diff --git a/src/controllers/ProfileChangeNameController.ts b/src/controllers/ProfileChangeNameController.ts index b7785d20..9d995cde 100644 --- a/src/controllers/ProfileChangeNameController.ts +++ b/src/controllers/ProfileChangeNameController.ts @@ -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(); } diff --git a/src/controllers/ProfileChangeNameEmployeeController.ts b/src/controllers/ProfileChangeNameEmployeeController.ts index 9ccefb2c..fcdcfbaf 100644 --- a/src/controllers/ProfileChangeNameEmployeeController.ts +++ b/src/controllers/ProfileChangeNameEmployeeController.ts @@ -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}") diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index e1d76c73..1e470911 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -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; diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index a553539b..98aa197f 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -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,