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; + } + } }