From 9c338a0cdebf50bbe5784902b3de308589849e3f Mon Sep 17 00:00:00 2001 From: kittapath Date: Mon, 2 Sep 2024 15:35:12 +0700 Subject: [PATCH] no message --- src/controllers/ProfileController.ts | 3 + src/controllers/ProfileEmployeeController.ts | 60 ++++++------------- .../ProfileEmployeeTempController.ts | 54 +++++------------ 3 files changed, 36 insertions(+), 81 deletions(-) diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 08142f0d..e8a1feb7 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -2563,6 +2563,9 @@ export class ProfileController extends Controller { posType: true, }, where: { profileId: id }, + order: { + createdAt: "ASC", + }, }); if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index 9069ccc9..4e8d0ca0 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -665,17 +665,6 @@ export class ProfileEmployeeController extends Controller { const record = await this.profileRepo.findOneBy({ id }); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์นี้"); - await this.profileHistoryRepo.save( - Object.assign(new ProfileEmployeeHistory(), { - ...record, - lastUpdateUserId: request.user.sub, - lastUpdateFullName: request.user.name, - lastUpdatedAt: new Date(), - profileEmployeeId: id, - id: undefined, - }), - ); - if (body.employeeClass == null || body.employeeClass == undefined || body.employeeClass == "") { body.employeeClass = "PERM"; } @@ -691,6 +680,16 @@ export class ProfileEmployeeController extends Controller { record.dateRetireLaw = calculateRetireLaw(record.birthDate); record.citizenId = Extension.CheckCitizen(record.citizenId); record.employeeClass = record.employeeClass.toLocaleUpperCase(); + await this.profileHistoryRepo.save( + Object.assign(new ProfileEmployeeHistory(), { + ...record, + lastUpdateUserId: request.user.sub, + lastUpdateFullName: request.user.name, + lastUpdatedAt: new Date(), + profileEmployeeId: id, + id: undefined, + }), + ); await this.profileRepo.save(record); return new HttpSuccess(); } @@ -1395,11 +1394,11 @@ export class ProfileEmployeeController extends Controller { relations: { posLevel: true, posType: true, - // gender: true, - // relationship: true, - // bloodGroup: true, }, where: { profileEmployeeId: id }, + order: { + createdAt: "ASC", + }, }); if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); @@ -3037,36 +3036,13 @@ export class ProfileEmployeeController extends Controller { @Get("information/history/{profileEmployeeId}") async getInformationHistory(@Path() profileEmployeeId: string, @Request() req: RequestWithUser) { await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profileEmployeeId); - const profileInformation = await this.profileRepo.find({ - relations: { - information_histories: true, + const profileInformation = await this.informationHistoryRepository.find({ + where: { profileEmployeeId: profileEmployeeId }, + order: { + createdAt: "ASC", }, - where: { id: profileEmployeeId }, }); - if (!profileInformation) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); - - const mapData = profileInformation - .flatMap((profile) => profile.information_histories) - .map((history) => ({ - id: history.id, - positionEmployeeGroupId: history.positionEmployeeGroupId, - positionEmployeeLineId: history.positionEmployeeLineId, - positionEmployeePositionId: history.positionEmployeePositionId, - employeeOc: history.employeeOc, - employeeTypeIndividual: history.employeeTypeIndividual, - employeeWage: history.employeeWage, - employeeMoneyIncrease: history.employeeMoneyIncrease, - employeeMoneyAllowance: history.employeeMoneyAllowance, - employeeMoneyEmployee: history.employeeMoneyEmployee, - employeeMoneyEmployer: history.employeeMoneyEmployer, - createdAt: history.createdAt, - createdUserId: history.createdUserId, - createdFullName: history.createdFullName, - lastUpdatedAt: history.lastUpdatedAt, - lastUpdateUserId: history.lastUpdateUserId, - lastUpdateFullName: history.lastUpdateFullName, - })); - return new HttpSuccess(mapData); + return new HttpSuccess(profileInformation); } /** diff --git a/src/controllers/ProfileEmployeeTempController.ts b/src/controllers/ProfileEmployeeTempController.ts index 6dcfc92f..8d298273 100644 --- a/src/controllers/ProfileEmployeeTempController.ts +++ b/src/controllers/ProfileEmployeeTempController.ts @@ -662,14 +662,6 @@ export class ProfileEmployeeTempController extends Controller { const record = await this.profileRepo.findOneBy({ id }); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์นี้"); - await this.profileHistoryRepo.save( - Object.assign(new ProfileEmployeeHistory(), { - ...record, - profileEmployeeId: id, - id: undefined, - }), - ); - if (body.employeeClass == null || body.employeeClass == undefined || body.employeeClass == "") { body.employeeClass = "PERM"; } @@ -685,6 +677,13 @@ export class ProfileEmployeeTempController extends Controller { record.dateRetireLaw = calculateRetireLaw(record.birthDate); record.citizenId = Extension.CheckCitizen(record.citizenId); record.employeeClass = record.employeeClass.toLocaleUpperCase(); + await this.profileHistoryRepo.save( + Object.assign(new ProfileEmployeeHistory(), { + ...record, + profileEmployeeId: id, + id: undefined, + }), + ); await this.profileRepo.save(record); return new HttpSuccess(); } @@ -1333,11 +1332,11 @@ export class ProfileEmployeeTempController extends Controller { relations: { posLevel: true, posType: true, - // gender: true, - // relationship: true, - // bloodGroup: true, }, where: { profileEmployeeId: id }, + order: { + createdAt: "ASC", + }, }); if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); @@ -2973,36 +2972,13 @@ export class ProfileEmployeeTempController extends Controller { @Get("information/history/{profileEmployeeId}") async getInformationHistory(@Path() profileEmployeeId: string, @Request() req: RequestWithUser) { await new permission().PermissionGet(req, "SYS_REGISTRY_TEMP"); - const profileInformation = await this.profileRepo.find({ - relations: { - information_histories: true, + const profileInformation = await this.informationHistoryRepository.find({ + where: { profileEmployeeId: profileEmployeeId }, + order: { + createdAt: "ASC", }, - where: { id: profileEmployeeId }, }); - if (!profileInformation) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); - - const mapData = profileInformation - .flatMap((profile) => profile.information_histories) - .map((history) => ({ - id: history.id, - positionEmployeeGroupId: history.positionEmployeeGroupId, - positionEmployeeLineId: history.positionEmployeeLineId, - positionEmployeePositionId: history.positionEmployeePositionId, - employeeOc: history.employeeOc, - employeeTypeIndividual: history.employeeTypeIndividual, - employeeWage: history.employeeWage, - employeeMoneyIncrease: history.employeeMoneyIncrease, - employeeMoneyAllowance: history.employeeMoneyAllowance, - employeeMoneyEmployee: history.employeeMoneyEmployee, - employeeMoneyEmployer: history.employeeMoneyEmployer, - createdAt: history.createdAt, - createdUserId: history.createdUserId, - createdFullName: history.createdFullName, - lastUpdatedAt: history.lastUpdatedAt, - lastUpdateUserId: history.lastUpdateUserId, - lastUpdateFullName: history.lastUpdateFullName, - })); - return new HttpSuccess(mapData); + return new HttpSuccess(profileInformation); } /**