edit:model:user | change user prisma schema from profilePicture to avatar

This commit is contained in:
rafiarrafif
2025-06-21 22:13:01 +07:00
parent 22c24c0202
commit fbd5b68b10
3 changed files with 8 additions and 9 deletions

View File

@ -203,8 +203,8 @@ model User {
phoneNumber Int? phoneNumber Int?
roles UserRole[] @relation("UserRoles") roles UserRole[] @relation("UserRoles")
bioProfile String? @db.Text bioProfile String? @db.Text
profilePicture String? @db.Text avatar String? @db.Text
commentPicture String? @db.Text commentBackground String? @db.Text
preference UserPreference? @relation(fields: [preferenceId], references: [id]) preference UserPreference? @relation(fields: [preferenceId], references: [id])
preferenceId String? @unique preferenceId String? @unique
verifiedAt DateTime? verifiedAt DateTime?

View File

@ -10,6 +10,6 @@ export const createUserSchema = Joi.object({
phoneCC: Joi.string().min(2).max(2), phoneCC: Joi.string().min(2).max(2),
phoneNumber: Joi.string().min(7).max(15), phoneNumber: Joi.string().min(7).max(15),
bioProfile: Joi.string().max(300), bioProfile: Joi.string().max(300),
profilePicture: Joi.string().uri(), avatar: Joi.string().uri(),
commentPicture: Joi.string().uri(), commentBackground: Joi.string().uri(),
}); });

View File

@ -32,8 +32,7 @@ export const editUserService = async (
// Store the avatar to the file system if provided in the payload // Store the avatar to the file system if provided in the payload
let storeAvatar: string | undefined = undefined; let storeAvatar: string | undefined = undefined;
if (payload.profilePicture) if (payload.avatar) storeAvatar = await saveAvatar(payload.avatar as File);
storeAvatar = await saveAvatar(payload.profilePicture as File);
// Prepare the fields to update, only include fields that are provided in the payload // Prepare the fields to update, only include fields that are provided in the payload
const fieldsToUpdate: Partial<Prisma.UserUpdateInput> = { const fieldsToUpdate: Partial<Prisma.UserUpdateInput> = {
@ -53,9 +52,9 @@ export const editUserService = async (
...(payload.bioProfile !== undefined ...(payload.bioProfile !== undefined
? { bioProfile: payload.bioProfile } ? { bioProfile: payload.bioProfile }
: {}), : {}),
...(storeAvatar !== undefined ? { profilePicture: storeAvatar } : {}), ...(storeAvatar !== undefined ? { avatar: storeAvatar } : {}),
...(payload.commentPicture !== undefined ...(payload.commentBackground !== undefined
? { commentPicture: payload.commentPicture } ? { commentPicture: payload.commentBackground }
: {}), : {}),
...(payload.deletedAt !== undefined ...(payload.deletedAt !== undefined
? { deletedAt: payload.deletedAt } ? { deletedAt: payload.deletedAt }