From 40bc95bb87e613d2f8a1b71971d591f22d754cb6 Mon Sep 17 00:00:00 2001 From: mamoss <> Date: Mon, 3 Nov 2025 21:37:50 +0700 Subject: [PATCH] update org --- src/controllers/ImportDataController.ts | 44 ++++++++++++++----------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/src/controllers/ImportDataController.ts b/src/controllers/ImportDataController.ts index d6345ac0..e2339b8f 100644 --- a/src/controllers/ImportDataController.ts +++ b/src/controllers/ImportDataController.ts @@ -6316,45 +6316,49 @@ export class ImportDataController extends Controller { @Post("updateRetireClearOrg") async updateRetireClearOrg(@Request() request: { user: Record }) { const profiles = await this.profileRepo.find({ - where: { - isLeave: true, - }, + where: { isLeave: true }, + select: ["id"], }); - - for (const item of profiles) { - const posmaster = await this.posMasterRepo.findOne({ + const profileIds = profiles.map((p) => p.id); + if (profileIds.length > 0) { + const posmasters = await this.posMasterRepo.find({ where: { orgRevision: { orgRevisionIsCurrent: false, orgRevisionIsDraft: true, }, - next_holderId: item.id, + next_holderId: In(profileIds), }, }); - if (!posmaster) continue; - posmaster.next_holderId = null; - await this.posMasterRepo.save(posmaster); + for (const posmaster of posmasters) { + posmaster.next_holderId = null; + } + if (posmasters.length > 0) { + await this.posMasterRepo.save(posmasters); + } } const profileEmps = await this.profileEmpRepo.find({ - where: { - isLeave: true, - }, + where: { isLeave: true }, + select: ["id"], }); - - for (const item of profileEmps) { - const posmaster = await this.posMasterEmpRepo.findOne({ + const profileEmpIds = profileEmps.map((p) => p.id); + if (profileEmpIds.length > 0) { + const posmasterEmps = await this.posMasterEmpRepo.find({ where: { orgRevision: { orgRevisionIsCurrent: false, orgRevisionIsDraft: true, }, - next_holderId: item.id, + next_holderId: In(profileEmpIds), }, }); - if (!posmaster) continue; - posmaster.next_holderId = null; - await this.posMasterEmpRepo.save(posmaster); + for (const posmasterEmp of posmasterEmps) { + posmasterEmp.next_holderId = null; + } + if (posmasterEmps.length > 0) { + await this.posMasterEmpRepo.save(posmasterEmps); + } } return new HttpSuccess(); }