trello_fake/lib/usersService.ts

43 lines
1.2 KiB
TypeScript
Raw Normal View History

import { dolibarrFetch } from "./dolibarrClient";
import { DolibarrUser, UserProfile, mapDolibarrUser } from "@/types/user";
/**
* Obtiene los datos crudos de un usuario de Dolibarr
*/
export async function getDolibarrUser(id?: string): Promise<DolibarrUser> {
2026-01-27 15:29:20 +00:00
const userId = id || process.env.NEXT_PUBLIC_DOLIBARR_USER_ID || "1";
return dolibarrFetch(`users/${userId}`);
}
/**
* Obtiene el perfil de usuario mapeado para la UI
*/
export async function getUserProfile(id?: string): Promise<UserProfile> {
const raw = await getDolibarrUser(id);
return mapDolibarrUser(raw);
}
/**
* Obtiene datos básicos de usuario (para sidebar, compatibilidad hacia atrás)
*/
export async function getUser(id?: string): Promise<{
firstname: string;
lastname: string;
email: string;
}> {
const raw = await getDolibarrUser(id);
return {
firstname: raw.firstname || raw.login || 'Usuario',
lastname: raw.lastname || '',
email: raw.email || '',
};
}
/**
* Obtiene el perfil del usuario autenticado actualmente
* Usa el ID configurado en las variables de entorno
*/
export async function getCurrentUserProfile(): Promise<UserProfile> {
return getUserProfile();
}