From a4f967629729de6dbe290e7f8803357431e7d63f Mon Sep 17 00:00:00 2001 From: Kittapath Date: Fri, 8 Mar 2024 12:25:35 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=AA=E0=B8=A3=E0=B9=89=E0=B8=B2=E0=B8=87?= =?UTF-8?q?=E0=B8=A3=E0=B8=AD=E0=B8=9A=E0=B8=9E=E0=B8=B4=E0=B9=80=E0=B8=A8?= =?UTF-8?q?=E0=B8=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/SalaryPeriodController.ts | 69 +++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/src/controllers/SalaryPeriodController.ts b/src/controllers/SalaryPeriodController.ts index f01c562..6ff22a2 100644 --- a/src/controllers/SalaryPeriodController.ts +++ b/src/controllers/SalaryPeriodController.ts @@ -1179,6 +1179,41 @@ export class SalaryPeriodController extends Controller { salaryPeriod.lastUpdateUserId = request.user.sub; salaryPeriod.lastUpdateFullName = request.user.name; await this.salaryPeriodRepository.save(salaryPeriod); + + if (salaryPeriod.period == "SPECIAL") { + const snapshot = "SNAP1"; + const salaryOrg = await this.salaryOrgRepository.find({ + where: { salaryPeriodId: salaryPeriod.id, snapshot: snapshot }, + }); + const salaryProfile = await this.salaryProfileRepository.find({ + where: { salaryOrgId: In(salaryOrg.map((x) => x.id)) }, + }); + await this.salaryOrgRepository.remove(salaryOrg); + await this.salaryProfileRepository.remove(salaryProfile); + + let orgs = await new CallAPI().GetData(request, "org/unauthorize/active/root/id"); + let revisionId = await new CallAPI().GetData(request, "org/unauthorize/revision/latest"); + + salaryPeriod.revisionId = revisionId; + await this.salaryPeriodRepository.save(salaryPeriod); + + await Promise.all( + orgs.map(async (rootId: string) => { + let salaryOrgNew = Object.assign(new SalaryOrg()); + salaryOrgNew.salaryPeriodId = salaryPeriod.id; + salaryOrgNew.status = "PENDING"; + salaryOrgNew.rootId = rootId; + salaryOrgNew.revisionId = salaryPeriod.revisionId; + salaryOrgNew.snapshot = snapshot; + salaryOrgNew.createdUserId = request.user.sub; + salaryOrgNew.createdFullName = request.user.name; + salaryOrgNew.lastUpdateUserId = request.user.sub; + salaryOrgNew.lastUpdateFullName = request.user.name; + salaryOrgNew.group = "GROUP1"; + await this.salaryOrgRepository.save(salaryOrgNew); + }), + ); + } return new HttpSuccess(salaryPeriod.id); } @@ -1227,6 +1262,40 @@ export class SalaryPeriodController extends Controller { chk_SalaryPeriod.lastUpdatedAt = new Date(); this.salaryPeriodRepository.merge(chk_SalaryPeriod, requestBody); await this.salaryPeriodRepository.save(chk_SalaryPeriod); + if (chk_SalaryPeriod.period == "SPECIAL") { + const snapshot = "SNAP1"; + const salaryOrg = await this.salaryOrgRepository.find({ + where: { salaryPeriodId: chk_SalaryPeriod.id, snapshot: snapshot }, + }); + const salaryProfile = await this.salaryProfileRepository.find({ + where: { salaryOrgId: In(salaryOrg.map((x) => x.id)) }, + }); + await this.salaryOrgRepository.remove(salaryOrg); + await this.salaryProfileRepository.remove(salaryProfile); + + let orgs = await new CallAPI().GetData(request, "org/unauthorize/active/root/id"); + let revisionId = await new CallAPI().GetData(request, "org/unauthorize/revision/latest"); + + chk_SalaryPeriod.revisionId = revisionId; + await this.salaryPeriodRepository.save(chk_SalaryPeriod); + + await Promise.all( + orgs.map(async (rootId: string) => { + let salaryOrgNew = Object.assign(new SalaryOrg()); + salaryOrgNew.salaryPeriodId = chk_SalaryPeriod.id; + salaryOrgNew.status = "PENDING"; + salaryOrgNew.rootId = rootId; + salaryOrgNew.revisionId = chk_SalaryPeriod.revisionId; + salaryOrgNew.snapshot = snapshot; + salaryOrgNew.createdUserId = request.user.sub; + salaryOrgNew.createdFullName = request.user.name; + salaryOrgNew.lastUpdateUserId = request.user.sub; + salaryOrgNew.lastUpdateFullName = request.user.name; + salaryOrgNew.group = "GROUP1"; + await this.salaryOrgRepository.save(salaryOrgNew); + }), + ); + } return new HttpSuccess(id); }