From 29f27faaadf285a1c204dc260e95d01498fc8b9f Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Tue, 13 May 2025 14:49:24 +0700 Subject: [PATCH] isGood in snapshot --- .../OrganizationUnauthorizeController.ts | 73 ++++++++++++++----- 1 file changed, 56 insertions(+), 17 deletions(-) diff --git a/src/controllers/OrganizationUnauthorizeController.ts b/src/controllers/OrganizationUnauthorizeController.ts index 234c2ec9..c682cc3d 100644 --- a/src/controllers/OrganizationUnauthorizeController.ts +++ b/src/controllers/OrganizationUnauthorizeController.ts @@ -4,7 +4,7 @@ import { AppDataSource } from "../database/data-source"; import HttpSuccess from "../interfaces/http-success"; import HttpError from "../interfaces/http-error"; import HttpStatusCode from "../interfaces/http-status"; -import { Brackets, In, IsNull, Not } from "typeorm"; +import { Brackets, In, IsNull, MoreThanOrEqual, Not } from "typeorm"; import { OrgRoot } from "../entities/OrgRoot"; import { PosMaster } from "../entities/PosMaster"; import { calculateRetireDate } from "../interfaces/utils"; @@ -172,7 +172,7 @@ export class OrganizationUnauthorizeController extends Controller { if (!findPosMaster) { throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. PosMaster"); } - + const formattedData = findPosMaster.map((item) => { let orgShortName = ""; @@ -317,13 +317,21 @@ export class OrganizationUnauthorizeController extends Controller { if (!findRevision) { throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. OrgRevision"); } + // const rootIds = [ + // "d7e98989-b5ce-47d6-93c3-ab63ed486348", + // "e0545eca-5d0a-4a1c-8bbd-e3e25c2521db", + // "26989ffa-d5ab-4bbd-ac97-130646cd1da6", + // "6f9b30e1-757a-40d5-b053-61eb1b91c0f0", + // "eaf65f33-25e9-4956-9dba-5d909f5eb595", + // "a3efed2c-3f4b-476d-95e6-9f7e0585ae25", + // ]; + const rootIds = [ - "d7e98989-b5ce-47d6-93c3-ab63ed486348", - "e0545eca-5d0a-4a1c-8bbd-e3e25c2521db", - "26989ffa-d5ab-4bbd-ac97-130646cd1da6", - "6f9b30e1-757a-40d5-b053-61eb1b91c0f0", - "eaf65f33-25e9-4956-9dba-5d909f5eb595", - "a3efed2c-3f4b-476d-95e6-9f7e0585ae25", + "b89a4467-7ee3-4706-8db7-f366555f826c", + "585648a9-e634-43fc-9360-5fd4189136ab", + "d6e3daa0-284a-428f-aa43-0750fa74e974", + "ed3ddcfb-f882-4499-817b-aff73e5be87c", + "f8ce98ca-a691-4c89-abde-875f559afb3a", ]; const [findPosMaster, total] = await AppDataSource.getRepository(viewPosMaster) @@ -398,6 +406,17 @@ export class OrganizationUnauthorizeController extends Controller { if (!findPosMaster) { throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. PosMaster"); } + + const profileAssessment = await this.profileAssessmentRepo.findOne( + { + where:{ + profileId: In(findPosMaster.map((item) => item.current_holderId)), + year: body.year.toString(), + pointSum: MoreThanOrEqual(90), + period: body.period.toLocaleUpperCase(), + } + } + ); const formattedData = findPosMaster.map((item) => { let orgShortName = ""; @@ -503,7 +522,8 @@ export class OrganizationUnauthorizeController extends Controller { calculateRetireDate(item.birthDate).getFullYear() != body.year ? false : true, - // isSpecial: isSpecial, + // isSpecial: isSpecial, + isGood: profileAssessment?.profileId.includes(item.current_holderId) ? true : false, }; }); return new HttpSuccess({ data: formattedData, total: total }); @@ -753,13 +773,20 @@ export class OrganizationUnauthorizeController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. OrgRevision"); } + // const rootIds = [ + // "d7e98989-b5ce-47d6-93c3-ab63ed486348", + // "e0545eca-5d0a-4a1c-8bbd-e3e25c2521db", + // "26989ffa-d5ab-4bbd-ac97-130646cd1da6", + // "6f9b30e1-757a-40d5-b053-61eb1b91c0f0", + // "eaf65f33-25e9-4956-9dba-5d909f5eb595", + // "a3efed2c-3f4b-476d-95e6-9f7e0585ae25", + // ]; const rootIds = [ - "d7e98989-b5ce-47d6-93c3-ab63ed486348", - "e0545eca-5d0a-4a1c-8bbd-e3e25c2521db", - "26989ffa-d5ab-4bbd-ac97-130646cd1da6", - "6f9b30e1-757a-40d5-b053-61eb1b91c0f0", - "eaf65f33-25e9-4956-9dba-5d909f5eb595", - "a3efed2c-3f4b-476d-95e6-9f7e0585ae25", + "b89a4467-7ee3-4706-8db7-f366555f826c", + "585648a9-e634-43fc-9360-5fd4189136ab", + "d6e3daa0-284a-428f-aa43-0750fa74e974", + "ed3ddcfb-f882-4499-817b-aff73e5be87c", + "f8ce98ca-a691-4c89-abde-875f559afb3a", ]; const [findPosMaster, total] = await AppDataSource.getRepository(viewEmployeePosMaster) @@ -813,7 +840,7 @@ export class OrganizationUnauthorizeController extends Controller { ) .orWhere( body.keyword != null && body.keyword != "" - ? "posType.posTypeName LIKE :keyword" + ? "posTypeName LIKE :keyword" : "1=1", { keyword: `%${body.keyword}%`, @@ -821,7 +848,7 @@ export class OrganizationUnauthorizeController extends Controller { ) .orWhere( body.keyword != null && body.keyword != "" - ? "posLevel.posLevelName LIKE :keyword" + ? "posLevelName LIKE :keyword" : "1=1", { keyword: `%${body.keyword}%`, @@ -837,6 +864,17 @@ export class OrganizationUnauthorizeController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. PosMaster"); } + const profileAssessment = await this.profileAssessmentRepo.findOne( + { + where:{ + profileEmployeeId: In(findPosMaster.map((item) => item.current_holderId)), + year: body.year.toString(), + pointSum: MoreThanOrEqual(90), + period: body.period.toLocaleUpperCase(), + } + } + ); + const formattedData = findPosMaster.map((item) => { let orgShortName = ""; @@ -936,6 +974,7 @@ export class OrganizationUnauthorizeController extends Controller { calculateRetireDate(item.birthDate).getFullYear() != body.year ? false : true, + isGood: profileAssessment?.profileId.includes(item.current_holderId) ? true : false, }; }); return new HttpSuccess({ data: formattedData, total: total });