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();
}

View file

@ -128,6 +128,11 @@ export class ProfileChangeNameEmployeeController 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.profileEmployeeRepo.save(profile);
return new HttpSuccess(data.id);
}
@ -154,7 +159,26 @@ export class ProfileChangeNameEmployeeController extends Controller {
this.changeNameHistoryRepository.save(history),
]);
return new HttpSuccess();
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.profileEmployeeRepo.findOneBy({ id: record.profileEmployeeId });
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.profileEmployeeRepo.save(profile);
}
return new HttpSuccess([chkLastRecord.id,record.id]);
}
@Delete("{changeNameId}")

View file

@ -195,6 +195,10 @@ export class ProfileController extends Controller {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้");
}
if (body.citizenId && (await this.profileRepo.findOneBy({ citizenId: body.citizenId }))) {
throw new HttpError(HttpStatus.NOT_FOUND, "ข้อมูลรหัสบัตรประจำตัวประชาชนนี้มีอยู่ในระบบแล้ว");
}
const profile = Object.assign(new Profile(), body);
profile.isProbation = false;
profile.isLeave = false;

View file

@ -33,7 +33,7 @@ import { EmployeePosType } from "../entities/EmployeePosType";
import { RequestWithUser } from "../middlewares/user";
@Route("api/v1/org/profile-employee")
@Tags("Profile")
@Tags("ProfileEmployee")
@Security("bearerAuth")
@Response(
HttpStatus.INTERNAL_SERVER_ERROR,