From a157089097efdbbc82b5430537bdb83d299fb0c9 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Fri, 2 Feb 2024 15:49:08 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=9A=E0=B8=B1=E0=B8=8D=E0=B8=8A=E0=B8=B52?= =?UTF-8?q?=20=E0=B8=A2=E0=B8=B1=E0=B8=87=E0=B9=84=E0=B8=A1=E0=B9=88?= =?UTF-8?q?=E0=B9=80=E0=B8=AA=E0=B8=A3=E0=B9=87=E0=B8=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/OrganizationController.ts | 42 +++++----- src/controllers/ReportController.ts | 95 +++++++++++++++++++++++ 2 files changed, 116 insertions(+), 21 deletions(-) create mode 100644 src/controllers/ReportController.ts diff --git a/src/controllers/OrganizationController.ts b/src/controllers/OrganizationController.ts index d5a44396..4c709294 100644 --- a/src/controllers/OrganizationController.ts +++ b/src/controllers/OrganizationController.ts @@ -725,16 +725,16 @@ export class OrganizationController extends Controller { where: { orgRootId: orgRoot.id }, }), totalPositionCurrentUse: await this.posMasterRepository.count({ - where: { orgRootId: orgRoot.id, profileIdCurrentHolder: Not(IsNull()) && Not("") }, + where: { orgRootId: orgRoot.id, profileIdCurrentHolder: Not(IsNull()) || Not("") }, }), totalPositionCurrentVacant: await this.posMasterRepository.count({ - where: { orgRootId: orgRoot.id, profileIdCurrentHolder: IsNull() && "" }, + where: { orgRootId: orgRoot.id, profileIdCurrentHolder: IsNull() || "" }, }), totalPositionNextUse: await this.posMasterRepository.count({ - where: { orgRootId: orgRoot.id, profileIdNextHolder: Not(IsNull()) && Not("") }, + where: { orgRootId: orgRoot.id, profileIdNextHolder: Not(IsNull()) || Not("") }, }), totalPositionNextVacant: await this.posMasterRepository.count({ - where: { orgRootId: orgRoot.id, profileIdNextHolder: IsNull() && "" }, + where: { orgRootId: orgRoot.id, profileIdNextHolder: IsNull() || "" }, }), children: await Promise.all( @@ -763,20 +763,20 @@ export class OrganizationController extends Controller { totalPositionCurrentUse: await this.posMasterRepository.count({ where: { orgChild1Id: orgChild1.id, - profileIdCurrentHolder: Not(IsNull()) && Not(""), + profileIdCurrentHolder: Not(IsNull()) || Not(""), }, }), totalPositionCurrentVacant: await this.posMasterRepository.count({ - where: { orgChild1Id: orgChild1.id, profileIdCurrentHolder: IsNull() && "" }, + where: { orgChild1Id: orgChild1.id, profileIdCurrentHolder: IsNull() || "" }, }), totalPositionNextUse: await this.posMasterRepository.count({ where: { orgChild1Id: orgChild1.id, - profileIdNextHolder: Not(IsNull()) && Not(""), + profileIdNextHolder: Not(IsNull()) || Not(""), }, }), totalPositionNextVacant: await this.posMasterRepository.count({ - where: { orgChild1Id: orgChild1.id, profileIdNextHolder: IsNull() && "" }, + where: { orgChild1Id: orgChild1.id, profileIdNextHolder: IsNull() || "" }, }), children: await Promise.all( orgChild2Data @@ -804,23 +804,23 @@ export class OrganizationController extends Controller { totalPositionCurrentUse: await this.posMasterRepository.count({ where: { orgChild2Id: orgChild2.id, - profileIdCurrentHolder: Not(IsNull()) && Not(""), + profileIdCurrentHolder: Not(IsNull()) || Not(""), }, }), totalPositionCurrentVacant: await this.posMasterRepository.count({ where: { orgChild2Id: orgChild2.id, - profileIdCurrentHolder: IsNull() && "", + profileIdCurrentHolder: IsNull() || "", }, }), totalPositionNextUse: await this.posMasterRepository.count({ where: { orgChild2Id: orgChild2.id, - profileIdNextHolder: Not(IsNull()) && Not(""), + profileIdNextHolder: Not(IsNull()) || Not(""), }, }), totalPositionNextVacant: await this.posMasterRepository.count({ - where: { orgChild2Id: orgChild2.id, profileIdNextHolder: IsNull() && "" }, + where: { orgChild2Id: orgChild2.id, profileIdNextHolder: IsNull() || "" }, }), children: await Promise.all( orgChild3Data @@ -848,25 +848,25 @@ export class OrganizationController extends Controller { totalPositionCurrentUse: await this.posMasterRepository.count({ where: { orgChild3Id: orgChild3.id, - profileIdCurrentHolder: Not(IsNull()) && Not(""), + profileIdCurrentHolder: Not(IsNull()) || Not(""), }, }), totalPositionCurrentVacant: await this.posMasterRepository.count({ where: { orgChild3Id: orgChild3.id, - profileIdCurrentHolder: IsNull() && "", + profileIdCurrentHolder: IsNull() || "", }, }), totalPositionNextUse: await this.posMasterRepository.count({ where: { orgChild3Id: orgChild3.id, - profileIdNextHolder: Not(IsNull()) && Not(""), + profileIdNextHolder: Not(IsNull()) || Not(""), }, }), totalPositionNextVacant: await this.posMasterRepository.count({ where: { orgChild3Id: orgChild3.id, - profileIdNextHolder: IsNull() && "", + profileIdNextHolder: IsNull() || "", }, }), children: await Promise.all( @@ -895,26 +895,26 @@ export class OrganizationController extends Controller { totalPositionCurrentUse: await this.posMasterRepository.count({ where: { orgChild4Id: orgChild4.id, - profileIdCurrentHolder: Not(IsNull()) && Not(""), + profileIdCurrentHolder: Not(IsNull()) || Not(""), }, }), totalPositionCurrentVacant: await this.posMasterRepository.count({ where: { orgChild4Id: orgChild4.id, - profileIdCurrentHolder: IsNull() && "", + profileIdCurrentHolder: IsNull() || "", }, }), totalPositionNextUse: await this.posMasterRepository.count({ where: { orgChild4Id: orgChild4.id, - profileIdNextHolder: Not(IsNull()) && Not(""), + profileIdNextHolder: Not(IsNull()) || Not(""), }, }), totalPositionNextVacant: await this.posMasterRepository.count({ where: { orgChild4Id: orgChild4.id, - profileIdNextHolder: IsNull() && "", + profileIdNextHolder: IsNull() || "", }, }), })), @@ -1254,7 +1254,7 @@ export class OrganizationController extends Controller { .createQueryBuilder("orgRevision") .where("orgRevision.orgRevisionIsDraft = true") .andWhere("orgRevision.orgRevisionIsCurrent = false") - .andWhere("DATE(orgRevision.orgPublishDate) = :today", { today }) + // .andWhere("DATE(orgRevision.orgPublishDate) = :today", { today }) .getOne(); if (!orgRevisionDraft) { return new HttpSuccess(); diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts new file mode 100644 index 00000000..cb7030e9 --- /dev/null +++ b/src/controllers/ReportController.ts @@ -0,0 +1,95 @@ +import { + Controller, + Get, + Post, + Put, + Delete, + Patch, + Route, + Security, + Tags, + Body, + Path, + Request, + Example, + SuccessResponse, + Response, + Query, +} from "tsoa"; +import { AppDataSource } from "../database/data-source"; +import HttpSuccess from "../interfaces/http-success"; +import HttpStatusCode from "../interfaces/http-status"; +import { PosExecutive } from "../entities/PosExecutive"; +import { PosType } from "../entities/PosType"; +import { PosLevel } from "../entities/PosLevel"; +import { CreatePosDict, PosDict } from "../entities/PosDict"; +import HttpError from "../interfaces/http-error"; +import { Equal, ILike, In, IsNull, Like, Not } from "typeorm"; +import { CreatePosMaster, PosMaster } from "../entities/PosMaster"; +import { OrgRevision } from "../entities/OrgRevision"; +import { OrgRoot } from "../entities/OrgRoot"; +import { OrgChild1 } from "../entities/OrgChild1"; +import { OrgChild2 } from "../entities/OrgChild2"; +import { OrgChild3 } from "../entities/OrgChild3"; +import { OrgChild4 } from "../entities/OrgChild4"; +import { Position } from "../entities/Position"; +import { Brackets } from "typeorm/browser"; +@Route("api/v1/org/report") +@Tags("Position") +@Security("bearerAuth") +@Response( + HttpStatusCode.INTERNAL_SERVER_ERROR, + "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง", +) +@SuccessResponse(HttpStatusCode.OK, "สำเร็จ") +export class ReportController extends Controller { + private posExecutiveRepository = AppDataSource.getRepository(PosExecutive); + private posTypeRepository = AppDataSource.getRepository(PosType); + private posLevelRepository = AppDataSource.getRepository(PosLevel); + private posDictRepository = AppDataSource.getRepository(PosDict); + private posMasterRepository = AppDataSource.getRepository(PosMaster); + private positionRepository = AppDataSource.getRepository(Position); + + private orgRevisionRepository = AppDataSource.getRepository(OrgRevision); + private orgRootRepository = AppDataSource.getRepository(OrgRoot); + private child1Repository = AppDataSource.getRepository(OrgChild1); + private child2Repository = AppDataSource.getRepository(OrgChild2); + private child3Repository = AppDataSource.getRepository(OrgChild3); + private child4Repository = AppDataSource.getRepository(OrgChild4); + + /** + * API ค้นหารายการตำแหน่ง + * + * @summary ORG_029 - ค้นหารายการตำแหน่ง (ADMIN) #32 + * + */ + @Get("position") + async findPosition() { + try { + // const getPosType = await this.posTypeRepository.findOne({ + // select: ["id", "posTypeName", "posTypeRank"], + // relations: ["posLevels"], + // where: { id: id }, + // }); + // if (!getPosType) { + // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id); + // } + + // const mapGetPosType = { + // id: getPosType.id, + // posTypeName: getPosType.posTypeName, + // posTypeRank: getPosType.posTypeRank, + // posLevels: getPosType.posLevels.map((posLevel) => ({ + // id: posLevel.id, + // posLevelName: posLevel.posLevelName, + // posLevelRank: posLevel.posLevelRank, + // posLevelAuthority: posLevel.posLevelAuthority, + // })), + // }; + + return new HttpSuccess(); + } catch (error) { + return error; + } + } +}