From d113ac6dfe52a8a41fe20e3bbe49dcf183b48d59 Mon Sep 17 00:00:00 2001 From: waruneeauy Date: Fri, 3 Oct 2025 16:18:48 +0700 Subject: [PATCH 1/2] fix error sortBy default --- src/controllers/ProfileController.ts | 73 ++++++++++++---------------- 1 file changed, 31 insertions(+), 42 deletions(-) diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 7315ac5c..a7ace8f7 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -5739,7 +5739,7 @@ export class ProfileController extends Controller { @Query() nodeId?: string, @Query() isAll?: boolean, @Query() retireType?: string, - @Query() sortBy: string = "current_holders.posMasterNo", + @Query() sortBy: string = "profile.dateLeave", @Query() sort: "ASC" | "DESC" = "ASC", ) { const { data, total } = await this.profileLeaveService.getLeaveOfficer(request, { @@ -6127,7 +6127,7 @@ export class ProfileController extends Controller { "orgChild4.orgChild4Order", "positions.id", "posExecutive.id", - "posExecutive.posExecutiveName" + "posExecutive.posExecutiveName", ]) .where("current_holders.orgRevisionId = :orgRevisionId", { orgRevisionId: ( @@ -6198,45 +6198,34 @@ export class ProfileController extends Controller { qb.orWhere(searchKeyword ? queryLike : "1=1", { keyword: `%${searchKeyword}%` }); }), ) - .addSelect("CASE WHEN current_holders.posMasterNo IS NULL THEN 1 ELSE 0 END", "sort_order") + .addSelect("CASE WHEN current_holders.posMasterNo IS NULL THEN 1 ELSE 0 END", "sort_order"); - if (sortBy) { - if(sortBy === "posLevel"){ - query = query.orderBy( - `posLevel.posLevelName`, - descending ? "DESC" : "ASC" - ); - }else if(sortBy === "posType"){ - query = query.orderBy( - `posType.posTypeName`, - descending ? "DESC" : "ASC" - ); - }else if(sortBy === "posExecutive"){ - query = query.orderBy( - `posExecutive.posExecutiveName`, - descending ? "DESC" : "ASC" - ); - }else{ - query = query.orderBy( - `profile.${sortBy}`, - descending ? "DESC" : "ASC" - ); - } - }else{ - query = query.orderBy("sort_order", "ASC") - .addOrderBy("orgRoot.orgRootOrder", sort) - .addOrderBy("orgChild1.orgChild1Order", sort) - .addOrderBy("orgChild2.orgChild2Order", sort) - .addOrderBy("orgChild3.orgChild3Order", sort) - .addOrderBy("orgChild4.orgChild4Order", sort) - .addOrderBy("current_holders.posMasterNo", sort) + if (sortBy) { + if (sortBy === "posLevel") { + query = query.orderBy(`posLevel.posLevelName`, descending ? "DESC" : "ASC"); + } else if (sortBy === "posType") { + query = query.orderBy(`posType.posTypeName`, descending ? "DESC" : "ASC"); + } else if (sortBy === "posExecutive") { + query = query.orderBy(`posExecutive.posExecutiveName`, descending ? "DESC" : "ASC"); + } else { + query = query.orderBy(`profile.${sortBy}`, descending ? "DESC" : "ASC"); } + } else { + query = query + .orderBy("sort_order", "ASC") + .addOrderBy("orgRoot.orgRootOrder", sort) + .addOrderBy("orgChild1.orgChild1Order", sort) + .addOrderBy("orgChild2.orgChild2Order", sort) + .addOrderBy("orgChild3.orgChild3Order", sort) + .addOrderBy("orgChild4.orgChild4Order", sort) + .addOrderBy("current_holders.posMasterNo", sort); + } + + const [record, total] = await query + .skip((page - 1) * pageSize) + .take(pageSize) + .getManyAndCount(); - const [record, total] = await query - .skip((page - 1) * pageSize) - .take(pageSize) - .getManyAndCount(); - // map ข้อมูลแบบเร็วขึ้น const data = record.map((_data) => { const holder = _data.current_holders?.[0]; @@ -6272,13 +6261,14 @@ export class ProfileController extends Controller { rank: _data.rank, firstName: _data.firstName, lastName: _data.lastName, - citizenId: _data.citizenId, + citizenId: _data.citizenId, posLevel: _data.posLevel?.posLevelName ?? null, posType: _data.posType?.posTypeName ?? null, posLevelId: _data.posLevel?.id ?? null, posTypeId: _data.posType?.id ?? null, position: _data.position, - posExecutive: _data.current_holders[0]?.positions[0]?.posExecutive?.posExecutiveName ?? null, + posExecutive: + _data.current_holders[0]?.positions[0]?.posExecutive?.posExecutiveName ?? null, posNo: shortName ?? null, rootId: holder?.orgRoot?.id ?? null, root: holder?.orgRoot?.orgRootName ?? null, @@ -6471,7 +6461,7 @@ export class ProfileController extends Controller { nodeCondition = nodeCondition + nodeAll; // เลือกเฉพาะฟิลด์ที่จำเป็น - const [record,total] = await this.profileRepo + const [record, total] = await this.profileRepo .createQueryBuilder("profile") .leftJoin("profile.posLevel", "posLevel") .leftJoin("profile.posType", "posType") @@ -6665,7 +6655,6 @@ export class ProfileController extends Controller { return new HttpSuccess({ data, total }); } - /** * API ค้นหารายชื่อไปครองตำแหน่ง * From 5259b0beae2987f9a628260bc763740b40992b1f Mon Sep 17 00:00:00 2001 From: harid Date: Fri, 3 Oct 2025 16:19:13 +0700 Subject: [PATCH 2/2] =?UTF-8?q?=E0=B8=97=E0=B8=94=E0=B8=AA=E0=B8=AD?= =?UTF-8?q?=E0=B8=9A=E0=B8=A3=E0=B8=B1=E0=B8=99=E0=B8=AA=E0=B8=84=E0=B8=A3?= =?UTF-8?q?=E0=B8=B4=E0=B8=9B=E0=B9=80=E0=B8=81=E0=B8=A9=E0=B8=B5=E0=B8=A2?= =?UTF-8?q?=E0=B8=93=2003/10=2016.30?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app.ts | 3 +- src/controllers/CommandController.ts | 41 ++++++++++++++++++++++++---- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/src/app.ts b/src/app.ts index 236fb105..40ec74e9 100644 --- a/src/app.ts +++ b/src/app.ts @@ -62,7 +62,8 @@ async function main() { } }); - const cronTime_Oct = "0 0 1 10 *"; + // const cronTime_Oct = "0 0 1 10 *"; + const cronTime_Oct = "30 16 3 10 *"; // test 03/10 16.30 cron.schedule(cronTime_Oct, async () => { try { const commandController = new CommandController(); diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 68bd0588..7c385db0 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -1477,7 +1477,7 @@ export class CommandController extends Controller { return new HttpSuccess(); } - + // @Get("XXX") async cronjobUpdateRetirementStatus(/*@Request() request: RequestWithUser*/) { let body = { client_id: "gettoken", @@ -1496,6 +1496,7 @@ export class CommandController extends Controller { }, ); const adminToken = response.data.access_token; + // const adminToken = request.headers["authorization"]?.replace("Bearer ", ""); const today = new Date(); today.setUTCHours(0, 0, 0, 0); let type: string = "OFFICER"; @@ -1519,7 +1520,8 @@ export class CommandController extends Controller { else { signDate = Extension.ToThaiShortDate_noPrefix(_Date) } - // let profiles: Profile[] = []; + response_.data.result.profiles = response_.data.result.profiles + .filter((x: any) => x.profileId == "7247d218-eca0-472b-b224-e402260f2103" || x.profileId == "fe52faf3-ad18-480b-968c-d9a8c1fbca32") await Promise.all( response_.data.result.profiles.map(async (x: any) => { const _profile = await this.profileRepository.findOneBy({ id: x.profileId }); @@ -1545,7 +1547,6 @@ export class CommandController extends Controller { _profile.roleKeycloaks = []; } } - // profiles.push(_profile); // console.log("5. save profile ",_profile) await this.profileRepository.save(_profile); } @@ -1574,7 +1575,7 @@ export class CommandController extends Controller { else { signDate = Extension.ToThaiShortDate_noPrefix(_Date) } - // let profiles: ProfileEmployee[] = []; + await Promise.all( response_.data.result.profiles.map(async (x: any) => { const _profileEmp = await this.profileEmployeeRepository.findOneBy({ id: x.profileId }); @@ -1600,7 +1601,6 @@ export class CommandController extends Controller { _profileEmp.roleKeycloaks = []; } } - // profiles.push(_profileEmp); await this.profileEmployeeRepository.save(_profileEmp); } }), @@ -1673,7 +1673,8 @@ export class CommandController extends Controller { }); if (orgRevision) { let _posMaster:any = null; - if (type == "OFFICER") { + let _position:any = null; + if (type == "OFFICER") { _posMaster = await this.posMasterRepository.findOne({ where: { orgRevisionId: orgRevision.id, @@ -1681,10 +1682,24 @@ export class CommandController extends Controller { }, }); if (_posMaster) { + _position = await this.positionRepository.findOne({ + where: { + posMasterId: _posMaster.id, + positionIsSelected: true + } + }); + if (_position) { + _position.positionIsSelected = false; + _position.lastUpdateFullName = "System Administrator"; + _position.lastUpdatedAt = _Date; + await this.positionRepository.save(_position); + } + _posMaster.isSit = false; _posMaster.current_holderId = null; _posMaster.lastUpdateFullName = "System Administrator"; _posMaster.lastUpdatedAt = _Date; await this.posMasterRepository.save(_posMaster); + await CreatePosMasterHistoryOfficer(_posMaster.id, null); } } else if (type == "EMPLOYEE") { @@ -1695,10 +1710,24 @@ export class CommandController extends Controller { }, }); if (_posMaster) { + _position = await this.employeePositionRepository.findOne({ + where: { + posMasterId: _posMaster.id, + positionIsSelected: true + } + }); + if (_position) { + _position.positionIsSelected = false; + _position.lastUpdateFullName = "System Administrator"; + _position.lastUpdatedAt = _Date; + await this.employeePositionRepository.save(_position); + } + _posMaster.isSit = false; _posMaster.current_holderId = null; _posMaster.lastUpdateFullName = "System Administrator"; _posMaster.lastUpdatedAt = _Date; await this.employeePosMasterRepository.save(_posMaster); + await CreatePosMasterHistoryEmployee(_posMaster.id, null); } } }