From 866dd91d813a8fcec4fd9fddcffbb0a94bd56236 Mon Sep 17 00:00:00 2001 From: Bright Date: Wed, 3 Apr 2024 14:52:37 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=20isActive?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/SalaryController.ts | 65 ++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 19 deletions(-) diff --git a/src/controllers/SalaryController.ts b/src/controllers/SalaryController.ts index 1b1e928..bd2d8b7 100644 --- a/src/controllers/SalaryController.ts +++ b/src/controllers/SalaryController.ts @@ -73,13 +73,26 @@ export class SalaryController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ระดับของตำแหน่ง ไม่ถูกต้อง"); } - const chk_3fields = await this.salaryRepository.findOne({ - where: { - posTypeId: salarys.posTypeId, - posLevelId: salarys.posLevelId, - }, - }); - if (chk_3fields && salarys.isActive) { + let chk_fields: any + if(salarys.isSpecial){ + chk_fields = await this.salaryRepository.findOne({ + where: { + posTypeId: salarys.posTypeId, + posLevelId: salarys.posLevelId, + isSpecial: true + }, + }); + }else{ + chk_fields = await this.salaryRepository.findOne({ + where: { + posTypeId: salarys.posTypeId, + posLevelId: salarys.posLevelId, + isSpecial: false + }, + }); + } + + if (chk_fields && salarys.isActive) { salarys.isActive = false; } salarys.name = salarys.name; @@ -129,22 +142,36 @@ export class SalaryController extends Controller { ); } - const chk_3fields = await this.salaryRepository.find({ - where: { - posTypeId: requestBody.posTypeId, - posLevelId: requestBody.posLevelId, - isActive: true, - id: Not(id), - }, - }); - - if (chk_3fields.length > 0 && requestBody.isActive) { - chk_3fields.forEach(async (item) => { + let chk_fields: any + if(chk_Salary.isSpecial){ + chk_fields = await this.salaryRepository.find({ + where: { + posTypeId: requestBody.posTypeId, + posLevelId: requestBody.posLevelId, + isActive: true, + isSpecial: true, + id: Not(id), + }, + }); + }else{ + chk_fields = await this.salaryRepository.find({ + where: { + posTypeId: requestBody.posTypeId, + posLevelId: requestBody.posLevelId, + isActive: true, + isSpecial: false, + id: Not(id), + }, + }); + } + + if (chk_fields.length > 0 && requestBody.isActive) { + chk_fields.forEach(async (item:any) => { item.isActive = false; item.lastUpdateUserId = request.user.sub; item.lastUpdateFullName = request.user.name; item.lastUpdatedAt = new Date(); - await this.salaryRepository.save(chk_3fields); + await this.salaryRepository.save(chk_fields); }); }