mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-11-26 08:34:55 +00:00
Merge pull request #61 from HamzaSha1/fix/junior-profile-picture-refresh-on-update
Enhance profile picture handling in JuniorService to ensure foreign
This commit is contained in:
@ -114,7 +114,28 @@ export class JuniorService {
|
|||||||
}
|
}
|
||||||
junior.customer.user.email = body.email;
|
junior.customer.user.email = body.email;
|
||||||
}
|
}
|
||||||
setIf(user, 'profilePictureId', body.profilePictureId);
|
// Update profile picture: ensure FK and relation are consistent to avoid TypeORM overriding the FK
|
||||||
|
if (typeof body.profilePictureId !== 'undefined') {
|
||||||
|
if (body.profilePictureId) {
|
||||||
|
const document = await this.documentService.findDocumentById(body.profilePictureId);
|
||||||
|
if (!document) {
|
||||||
|
this.logger.error(`Document with id ${body.profilePictureId} not found`);
|
||||||
|
throw new BadRequestException('DOCUMENT.NOT_FOUND');
|
||||||
|
}
|
||||||
|
if (document.createdById !== juniorId) {
|
||||||
|
this.logger.error(
|
||||||
|
`Document with id ${body.profilePictureId} does not belong to user ${juniorId}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
user.profilePictureId = body.profilePictureId;
|
||||||
|
// assign relation to keep it consistent with FK during save
|
||||||
|
user.profilePicture = document as any;
|
||||||
|
} else {
|
||||||
|
// if empty string provided (unlikely), clear relation and FK
|
||||||
|
user.profilePicture = null as any;
|
||||||
|
user.profilePictureId = null as any;
|
||||||
|
}
|
||||||
|
}
|
||||||
setIf(user, 'firstName', body.firstName);
|
setIf(user, 'firstName', body.firstName);
|
||||||
setIf(user, 'lastName', body.lastName);
|
setIf(user, 'lastName', body.lastName);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user