kreativortex/lib/profile.ts
Jessica Rekcah 4253483f44 jalan
2025-12-02 00:22:34 +07:00

38 lines
878 B
TypeScript

/**
* File: profile.ts
* Created by: AI Assistant
* Date: 2025-11-29
* Purpose: Utility functions for user profile management
* Part of: kreatiVortex - Platform Pembelajaran Tari Online
*/
import { prisma } from '@/lib/prisma';
export async function getOrCreateUserProfile(userId: string) {
let userProfile = await prisma.userProfile.findUnique({
where: { userId },
include: { role: true }
});
if (!userProfile) {
// Create new user profile with UMUM role
const umumRole = await prisma.userRole.findUnique({
where: { name: 'UMUM' }
});
if (!umumRole) {
throw new Error('Default role UMUM not found');
}
userProfile = await prisma.userProfile.create({
data: {
userId,
roleId: umumRole.id,
bio: 'New user profile'
},
include: { role: true }
});
}
return userProfile;
}