From 971c611c5d87c8ab2102a819cae2d3a2e3c1dcb8 Mon Sep 17 00:00:00 2001 From: Bright Date: Fri, 2 Feb 2024 16:15:51 +0700 Subject: [PATCH] =?UTF-8?q?api=20=E0=B8=95=E0=B8=B3=E0=B9=81=E0=B8=AB?= =?UTF-8?q?=E0=B8=99=E0=B9=88=E0=B8=87=E0=B8=97=E0=B8=B1=E0=B9=89=E0=B8=87?= =?UTF-8?q?=E0=B8=AB=E0=B8=A1=E0=B8=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/PositionController.ts | 210 +++++++++++++++++++++++++- 1 file changed, 209 insertions(+), 1 deletion(-) diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index b2f4dfc4..0a542aaa 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -939,7 +939,7 @@ export class PositionController extends Controller { item.orgRoot == null ? "-" : item.orgChild1 == null - ? item.orgRoot + ? item.orgRoot.orgRootShortName : item.orgChild2 == null ? item.orgChild1.orgChild1ShortName : item.orgChild3 == null @@ -1044,4 +1044,212 @@ export class PositionController extends Controller { return error; } } + + /** + * API ตำแหน่งทั้งหมด + * + * @summary ORG_055 - ตำแหน่งทั้งหมด (ADMIN) #60 + * + */ + @Post("summary") + async PositionSummary( + @Body() requestBody: { id: string; type: number }, + ) { + try { + + let summary: any; + let totalPosition: any; + let totalPositionCurrentUse: any; + let totalPositionCurrentVacant: any; + let totalPositionNextUse: any; + let totalPositionNextVacant: any; + + switch(requestBody.type){ + case 0: { + const NodeId = await this.posMasterRepository.findOne({where: {orgRootId: requestBody.id}}); + if(!NodeId){ + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตามไอดีนี้ : " + requestBody.id); + } + totalPosition = await this.posMasterRepository.count({ + where: { orgRootId: requestBody.id }, + }); + totalPositionCurrentUse = await this.posMasterRepository.count({ + where: { + orgRootId: requestBody.id, + profileIdCurrentHolder: Not(IsNull()) && Not(""), + }, + }); + totalPositionCurrentVacant = await this.posMasterRepository.count({ + where: { + orgRootId: requestBody.id, + profileIdCurrentHolder: IsNull() && "", + }, + }); + totalPositionNextUse = await this.posMasterRepository.count({ + where: { + orgRootId: requestBody.id, + profileIdNextHolder: Not(IsNull()) && Not(""), + }, + }); + totalPositionNextVacant = await this.posMasterRepository.count({ + where: { + orgRootId: requestBody.id, + profileIdNextHolder: IsNull() && "", + }, + }); + break; + } + case 1: { + const NodeId = await this.posMasterRepository.findOne({where: {orgChild1Id: requestBody.id}}); + if(!NodeId){ + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตามไอดีนี้ : " + requestBody.id); + } + totalPosition = await this.posMasterRepository.count({ + where: { orgChild1Id: requestBody.id }, + }); + totalPositionCurrentUse = await this.posMasterRepository.count({ + where: { + orgChild1Id: requestBody.id, + profileIdCurrentHolder: Not(IsNull()) && Not(""), + }, + }); + totalPositionCurrentVacant = await this.posMasterRepository.count({ + where: { + orgChild1Id: requestBody.id, + profileIdCurrentHolder: IsNull() && "", + }, + }); + totalPositionNextUse = await this.posMasterRepository.count({ + where: { + orgChild1Id: requestBody.id, + profileIdNextHolder: Not(IsNull()) && Not(""), + }, + }); + totalPositionNextVacant = await this.posMasterRepository.count({ + where: { + orgChild1Id: requestBody.id, + profileIdNextHolder: IsNull() && "", + }, + }); + break; + } + case 2: { + const NodeId = await this.posMasterRepository.findOne({where: {orgChild2Id: requestBody.id}}); + if(!NodeId){ + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตามไอดีนี้ : " + requestBody.id); + } + totalPosition = await this.posMasterRepository.count({ + where: { orgChild2Id: requestBody.id }, + }); + totalPositionCurrentUse = await this.posMasterRepository.count({ + where: { + orgChild2Id: requestBody.id, + profileIdCurrentHolder: Not(IsNull()) && Not(""), + }, + }); + totalPositionCurrentVacant = await this.posMasterRepository.count({ + where: { + orgChild2Id: requestBody.id, + profileIdCurrentHolder: IsNull() && "", + }, + }); + totalPositionNextUse = await this.posMasterRepository.count({ + where: { + orgChild2Id: requestBody.id, + profileIdNextHolder: Not(IsNull()) && Not(""), + }, + }); + totalPositionNextVacant = await this.posMasterRepository.count({ + where: { + orgChild2Id: requestBody.id, + profileIdNextHolder: IsNull() && "", + }, + }); + break; + } + case 3: { + const NodeId = await this.posMasterRepository.findOne({where: {orgChild3Id: requestBody.id}}); + if(!NodeId){ + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตามไอดีนี้ : " + requestBody.id); + } + totalPosition = await this.posMasterRepository.count({ + where: { orgChild3Id: requestBody.id }, + }); + totalPositionCurrentUse = await this.posMasterRepository.count({ + where: { + orgChild3Id: requestBody.id, + profileIdCurrentHolder: Not(IsNull()) && Not(""), + }, + }); + totalPositionCurrentVacant = await this.posMasterRepository.count({ + where: { + orgChild3Id: requestBody.id, + profileIdCurrentHolder: IsNull() && "", + }, + }); + totalPositionNextUse = await this.posMasterRepository.count({ + where: { + orgChild3Id: requestBody.id, + profileIdNextHolder: Not(IsNull()) && Not(""), + }, + }); + totalPositionNextVacant = await this.posMasterRepository.count({ + where: { + orgChild3Id: requestBody.id, + profileIdNextHolder: IsNull() && "", + }, + }); + break; + } + case 4: { + const NodeId = await this.posMasterRepository.findOne({where: {orgChild4Id: requestBody.id}}); + if(!NodeId){ + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตามไอดีนี้ : " + requestBody.id); + } + totalPosition = await this.posMasterRepository.count({ + where: { orgChild4Id: requestBody.id }, + }); + totalPositionCurrentUse = await this.posMasterRepository.count({ + where: { + orgChild4Id: requestBody.id, + profileIdCurrentHolder: Not(IsNull()) && Not(""), + }, + }); + totalPositionCurrentVacant = await this.posMasterRepository.count({ + where: { + orgChild4Id: requestBody.id, + profileIdCurrentHolder: IsNull() && "", + }, + }); + totalPositionNextUse = await this.posMasterRepository.count({ + where: { + orgChild4Id: requestBody.id, + profileIdNextHolder: Not(IsNull()) && Not(""), + }, + }); + totalPositionNextVacant = await this.posMasterRepository.count({ + where: { + orgChild4Id: requestBody.id, + profileIdNextHolder: IsNull() && "", + }, + }); + break; + } + default: + break; + } + + summary = { + totalPosition: totalPosition, + totalPositionCurrentUse: totalPositionCurrentUse, + totalPositionCurrentVacant: totalPositionCurrentVacant, + totalPositionNextUse: totalPositionNextUse, + totalPositionNextVacant: totalPositionNextVacant + } + return new HttpSuccess(summary); + + } catch (error) { + return error; + } + } }