diff --git a/libs/service/src/api/users/index.ts b/libs/service/src/api/users/index.ts index 97f0276..34dcb34 100644 --- a/libs/service/src/api/users/index.ts +++ b/libs/service/src/api/users/index.ts @@ -4,6 +4,7 @@ import type { TUsersDetailItem, TUserCreateRequest, TUserUpdateRequest, + TUsersMeResponse, } from '../../types/users'; import type { TApiPaginated, TPaginationParams } from '../../types/common'; @@ -11,13 +12,16 @@ import type { TApiPaginated, TPaginationParams } from '../../types/common'; export type UserDetailResponseDto = TUsersDetailItem; export type UserUpdateRequestDto = TUserUpdateRequest; +export type TUserMeInclude = 'hackathon' | 'qr' | 'mentor' | 'sessions'; + export const getUserList = async (params?: TPaginationParams): Promise> => { const response = await api.get>('/v1/iam/users', { params }); return response.data; }; -export const getUserMe = async (): Promise => { - const response = await api.get>('/v1/iam/users/me'); +export const getUserMe = async (include?: TUserMeInclude[]): Promise => { + const params = include?.length ? { include: include.join(',') } : undefined; + const response = await api.get>('/v1/iam/users/me', { params }); return response.data.data; }; diff --git a/libs/service/src/hooks/auth/index.ts b/libs/service/src/hooks/auth/index.ts index bada887..eb67548 100644 --- a/libs/service/src/hooks/auth/index.ts +++ b/libs/service/src/hooks/auth/index.ts @@ -8,7 +8,7 @@ import { postForgotPassword, postNewPassword, } from '../../api/auth'; -import { getUserMe } from '../../api/users'; +import { getUserMe, type TUserMeInclude } from '../../api/users'; export * from './use-auth-store'; @@ -27,15 +27,13 @@ export const useLogin = () => { id: u.id, email: u.email, fullname: u.fullname, - phone_number: u.phone_number || '', - avatar: u.avatar || '', - birthdate: u.birthdate || '', - gender: u.gender || '', + phone_number: u.phone_number, + avatar: u.avatar, is_active: u.is_active, location: u.location, bio: u.bio, skills: u.skills, - role: u.role ?? { id: '', name: 'user', permissions: [], created_at: '', updated_at: '' }, + role: u.role ?? { id: '', name: 'user', permissions: [] }, }, }); }, @@ -57,15 +55,13 @@ export const useBackofficeLogin = () => { id: u.id, email: u.email, fullname: u.fullname, - phone_number: u.phone_number || '', - avatar: u.avatar || '', - birthdate: u.birthdate || '', - gender: u.gender || '', + phone_number: u.phone_number, + avatar: u.avatar, is_active: u.is_active, location: u.location, bio: u.bio, skills: u.skills, - role: u.role ?? { id: '', name: 'admin', permissions: [], created_at: '', updated_at: '' }, + role: u.role ?? { id: '', name: 'admin', permissions: [] }, }, }); }, @@ -115,12 +111,12 @@ export const useSignOut = () => { }); }; -export const useSessionQuery = () => { +export const useSessionQuery = (include?: TUserMeInclude[]) => { const { session } = useAuthStore(); return useQuery({ - queryKey: ['auth-session'], + queryKey: ['auth-session', include], queryFn: async () => { - const user = await getUserMe(); + const user = await getUserMe(include); return { user }; }, enabled: !!session?.token, diff --git a/libs/service/src/storage/local-storage.ts b/libs/service/src/storage/local-storage.ts index 254eb33..f57b16b 100644 --- a/libs/service/src/storage/local-storage.ts +++ b/libs/service/src/storage/local-storage.ts @@ -1,26 +1,22 @@ -import type { TPermissionItem } from '../types/permissions'; - -type TRoleItem = { - id: string; - name: string; - created_at: string; - updated_at: string; - permissions: TPermissionItem[]; -}; +import type { TRoleDetailItem } from '../types/roles'; +import type { THackathonProfile, TQrProfile, TMentorProfile } from '../types/users'; type TUserItem = { id: string; - avatar: string; - birthdate: string; + avatar?: string; + birthdate?: string; email: string; fullname: string; - gender: string; + gender?: string; is_active: boolean; - phone_number: string; - role: TRoleItem; + phone_number?: string; + role: TRoleDetailItem; bio?: string; location?: string; skills?: string[]; + hackathon?: THackathonProfile; + qr?: TQrProfile; + mentor?: TMentorProfile; }; export const SessionUser = { diff --git a/libs/service/src/types/users/index.ts b/libs/service/src/types/users/index.ts index 3f0f1b3..68516ad 100644 --- a/libs/service/src/types/users/index.ts +++ b/libs/service/src/types/users/index.ts @@ -76,6 +76,47 @@ export type TUsersDetailItem = { updated_at: string; }; +// --- Unified /me response types --- + +export type THackathonProfile = { + is_admin: boolean; + phone_number?: string; + location?: string; + bio?: string; + skills?: string[] | null; +}; + +export type TQrProfile = { + role: string; + provider: string; +}; + +export type TMentorProfile = { + mentor_id: string; + status?: string; + current_company?: string; + current_role?: string; + years_of_experience?: number; +}; + +export type TSessionProfile = { + id: string; + topic: string; + description?: string; + scheduled_at: string; + duration_minutes: number; + session_type: string; + status: string; + role: string; +}; + +export type TUsersMeResponse = TUsersDetailItem & { + hackathon?: THackathonProfile; + qr?: TQrProfile; + mentor?: TMentorProfile; + sessions?: TSessionProfile[]; +}; + export type TUserCreateRequest = { email: string; password: string;