Files
playzer/apps/backend/src/modules/user/services/user.service.ts
Jose Selesan 6ad4fc9ee9 feat: add complex user invitation and management features
- Implemented complex member and invitation schemas using Zod for validation.
- Created new API endpoints for inviting, accepting, revoking, and canceling complex user invitations.
- Developed handlers for managing complex users, including listing, inviting, revoking, and canceling invitations.
- Added frontend components for displaying and managing complex users and invitations.
- Introduced session storage management for pending invitations.
- Integrated Gravatar for user avatars based on email.
- Created database migration for complex invitations table.
2026-04-22 15:30:04 -03:00

51 lines
1.0 KiB
TypeScript

import type { User } from '@/lib/auth';
import { resolveAvatarUrl } from '@/lib/avatar';
import { db } from '@/lib/prisma';
import type { UserProfile } from '@repo/api-contract';
export async function getUserProfile(user: User, complexId?: string): Promise<UserProfile> {
const dbUser = await db.user.findUnique({
where: { id: user.id },
select: {
id: true,
name: true,
email: true,
image: true,
createdAt: true,
},
});
if (!dbUser) {
throw new Error('User not found.');
}
let role = 'member';
if (complexId) {
const complexUser = await db.complexUser.findUnique({
where: {
complexId_userId: {
complexId,
userId: user.id,
},
},
});
if (complexUser) {
role = complexUser.role.toLowerCase();
}
}
return {
id: dbUser.id,
fullName: dbUser.name,
email: dbUser.email,
role,
avatarUrl: resolveAvatarUrl({
email: dbUser.email,
image: dbUser.image,
}),
createdAt: dbUser.createdAt.toISOString(),
};
}