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:
abdalhamid99
2025-11-09 12:43:54 +03:00
committed by GitHub

View File

@ -114,7 +114,28 @@ export class JuniorService {
}
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, 'lastName', body.lastName);