From 1d0b35983bff534992356e594c00005cf7ce0665 Mon Sep 17 00:00:00 2001 From: kittapath Date: Wed, 4 Sep 2024 09:56:58 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=84=E0=B9=89=E0=B8=99=E0=B8=AB=E0=B8=B2?= =?UTF-8?q?=E0=B8=A5=E0=B8=B8=E0=B8=81=E0=B8=88=E0=B9=89=E0=B8=B2=E0=B8=87?= =?UTF-8?q?=E0=B8=9B=E0=B8=A3=E0=B8=B0=E0=B8=88=E0=B8=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OrganizationUnauthorizeController.ts | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/src/controllers/OrganizationUnauthorizeController.ts b/src/controllers/OrganizationUnauthorizeController.ts index b2d531ce..786cce54 100644 --- a/src/controllers/OrganizationUnauthorizeController.ts +++ b/src/controllers/OrganizationUnauthorizeController.ts @@ -845,6 +845,97 @@ export class OrganizationUnauthorizeController extends Controller { posTypeId: findProfile.posTypeId, }); } + + /** + * API หา user profile employee + * + * @summary หา user profile employee + * + */ + @Get("employee-prem/citizen/{id}") + async GetProfileEmployeePremByCitizenId(@Path() id: string) { + const findRevision = await this.orgRevisionRepository.findOne({ + where: { orgRevisionIsCurrent: true }, + }); + if (!findRevision) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. OrgRevision"); + } + + const findProfile = await AppDataSource.getRepository(ProfileEmployee) + .createQueryBuilder("profile") + .leftJoinAndSelect("profile.current_holders", "current_holders") + .leftJoinAndSelect("current_holders.orgRoot", "orgRoot") + .leftJoinAndSelect("current_holders.orgChild1", "orgChild1") + .leftJoinAndSelect("current_holders.orgChild2", "orgChild2") + .leftJoinAndSelect("current_holders.orgChild3", "orgChild3") + .leftJoinAndSelect("current_holders.orgChild4", "orgChild4") + .leftJoinAndSelect("current_holders.positions", "positions") + // .leftJoinAndSelect("positions.posExecutive", "posExecutive") + .where({ citizenId: id, employeeclass: "PREM" }) + .getOne(); + if (!findProfile) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "not found Profile"); + } + + const root = + findProfile.current_holders == null || + findProfile.current_holders.length == 0 || + findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null + ? null + : findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot; + + const child1 = + findProfile.current_holders == null || + findProfile.current_holders.length == 0 || + findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null + ? null + : findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1; + + const child2 = + findProfile.current_holders == null || + findProfile.current_holders.length == 0 || + findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null + ? null + : findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2; + + const child3 = + findProfile.current_holders == null || + findProfile.current_holders.length == 0 || + findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null + ? null + : findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3; + + const child4 = + findProfile.current_holders == null || + findProfile.current_holders.length == 0 || + findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null + ? null + : findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4; + + let _child1 = child1 == null ? "" : `${child1.orgChild1Name}/`; + let _child2 = child2 == null ? "" : `${child2.orgChild2Name}/`; + let _child3 = child3 == null ? "" : `${child3.orgChild3Name}/`; + let _child4 = child4 == null ? "" : `${child4.orgChild4Name}/`; + let _root = root == null ? "" : `${root.orgRootName}`; + + return new HttpSuccess({ + rootId: root == null ? null : root.id, + root: root == null ? null : root.orgRootName, + orgRootShortName: root == null ? null : root.orgRootShortName, + orgRevisionId: findRevision.id, + profileId: findProfile.id, + org: `${_child4}${_child3}${_child2}${_child1}${_root}`, + type: "EMPLOYEE", + rank: findProfile.rank, + prefix: findProfile.prefix, + firstName: findProfile.firstName, + lastName: findProfile.lastName, + citizenId: findProfile.citizenId, + position: findProfile.position, + posLevelId: findProfile.posLevelId, + posTypeId: findProfile.posTypeId, + }); + } textPointSummaryKpi(val: number | undefined) { if (val == undefined || val == null) val = -1; if (val >= 0 && val <= 60) return "ต้องปรับปรุง";