changName update and validate citizenId

This commit is contained in:
AdisakKanthawilang 2024-05-14 17:24:33 +07:00
parent f1a8652587
commit 9506128842
4 changed files with 54 additions and 2 deletions

View file

@ -126,6 +126,11 @@ export class ProfileChangeNameController extends Controller {
await this.changeNameRepository.save(data);
profile.firstName = body.firstName ?? profile.firstName;
profile.lastName = body.lastName ?? profile.lastName;
profile.prefix = body.prefix ?? profile.prefix;
await this.profileRepository.save(profile);
return new HttpSuccess(data.id);
}
@ -152,6 +157,25 @@ export class ProfileChangeNameController extends Controller {
this.changeNameHistoryRepository.save(history),
]);
const chkLastRecord = await this.changeNameRepository.findOne({
where:{
profileEmployeeId: record.profileEmployeeId
},
order:{
createdAt: "DESC"
}
})
if (!chkLastRecord) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const profile = await this.profileRepository.findOneBy({ id: record.profileId });
if (profile && chkLastRecord.id === record.id) {
profile.firstName = body.firstName ?? profile.firstName;
profile.lastName = body.lastName ?? profile.lastName;
profile.prefix = body.prefix ?? profile.prefix;
await this.profileRepository.save(profile);
}
return new HttpSuccess();
}