38 lines
878 B
TypeScript
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;
|
|
} |