Initial commit
This commit is contained in:
28
apps/backend/src/modules/user/services/user.service.ts
Normal file
28
apps/backend/src/modules/user/services/user.service.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import type { AuthUser } from '@/types/auth-user'
|
||||
import type { UserProfile } from '@repo/api-contract'
|
||||
|
||||
export function getUserProfile(user: AuthUser): UserProfile {
|
||||
const fullName =
|
||||
(typeof user.user_metadata?.full_name === 'string' &&
|
||||
user.user_metadata.full_name) ||
|
||||
(typeof user.user_metadata?.name === 'string' && user.user_metadata.name) ||
|
||||
(user.email ?? 'Usuario')
|
||||
|
||||
const role =
|
||||
(typeof user.app_metadata?.role === 'string' && user.app_metadata.role) ||
|
||||
'member'
|
||||
|
||||
const avatarUrl =
|
||||
(typeof user.user_metadata?.avatar_url === 'string' &&
|
||||
user.user_metadata.avatar_url) ||
|
||||
null
|
||||
|
||||
return {
|
||||
id: user.id,
|
||||
fullName,
|
||||
email: user.email ?? null,
|
||||
role,
|
||||
avatarUrl,
|
||||
createdAt: user.created_at,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user