From 12a6186fc430b6b07af27b2a77ae5719d3f885e6 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Tue, 2 Sep 2025 15:48:40 +0700 Subject: [PATCH 1/3] feat: add api passthough notification to socket --- src/controllers/SocketController.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/controllers/SocketController.ts diff --git a/src/controllers/SocketController.ts b/src/controllers/SocketController.ts new file mode 100644 index 00000000..3b6f455b --- /dev/null +++ b/src/controllers/SocketController.ts @@ -0,0 +1,25 @@ +import { Body, Controller, Post, Route } from "tsoa"; +import { sendWebSocket } from "../services/webSocket"; + +@Route("/api/v1/through-socket") +export class SocketController extends Controller { + @Post("notify") + async notify( + @Body() + payload: { + message: string; + userId?: string | string[]; + roles?: string | string[]; + error?: boolean; + }, + ) { + sendWebSocket( + "socket-notification", + { success: !payload.error, message: payload.message }, + { + roles: payload.roles || [], + userId: payload.userId || [], + }, + ); + } +} From 577a413ffa7bce72e61930626002efbfaa4a8028 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Tue, 2 Sep 2025 16:18:48 +0700 Subject: [PATCH 2/3] fix: endpoint behind api gateway --- src/controllers/SocketController.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/SocketController.ts b/src/controllers/SocketController.ts index 3b6f455b..eb0b72c2 100644 --- a/src/controllers/SocketController.ts +++ b/src/controllers/SocketController.ts @@ -1,7 +1,7 @@ import { Body, Controller, Post, Route } from "tsoa"; import { sendWebSocket } from "../services/webSocket"; -@Route("/api/v1/through-socket") +@Route("/api/v1/org/through-socket") export class SocketController extends Controller { @Post("notify") async notify( From f1436d148518626fa9c3ac0f655b6ec7bcd47bca Mon Sep 17 00:00:00 2001 From: mamoss <> Date: Tue, 2 Sep 2025 22:52:11 +0700 Subject: [PATCH 3/3] save profile before add his --- src/controllers/CommandController.ts | 15 +++++----- src/controllers/EmployeePositionController.ts | 2 +- .../EmployeeTempPositionController.ts | 2 +- src/controllers/PositionController.ts | 30 +++++++++---------- 4 files changed, 25 insertions(+), 24 deletions(-) diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index d5a05800..ca2352c5 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -93,6 +93,7 @@ import { Gender } from "../entities/Gender"; import { ProfileAvatar } from "../entities/ProfileAvatar"; import { CreatePosMasterHistoryEmployee, + CreatePosMasterHistoryEmployeeTemp, CreatePosMasterHistoryOfficer, } from "../services/PositionService"; @Route("api/v1/org/command") @@ -2175,8 +2176,7 @@ export class CommandController extends Controller { command.isDraft = true; command.isSign = true; command.status = "PENDING"; - } - else { + } else { command.status = "NEW"; } command.issue = commandType.name; @@ -3171,6 +3171,7 @@ export class CommandController extends Controller { await CreatePosMasterHistoryOfficer(posMasterOld.id, req); } await this.posMasterRepository.save(posMaster); + await CreatePosMasterHistoryOfficer(posMaster.id, req); const positionNew = await this.positionRepository.findOne({ where: { @@ -3188,7 +3189,6 @@ export class CommandController extends Controller { await this.profileRepository.save(profile); await this.positionRepository.save(positionNew); } - await CreatePosMasterHistoryOfficer(posMaster.id, req); }), ); @@ -3363,6 +3363,7 @@ export class CommandController extends Controller { await CreatePosMasterHistoryEmployee(posMasterOld.id, req); } await this.employeePosMasterRepository.save(posMaster); + await CreatePosMasterHistoryEmployee(posMaster.id, req); const positionNew = await this.employeePositionRepository.findOne({ where: { id: item.positionId, @@ -3381,7 +3382,6 @@ export class CommandController extends Controller { await this.profileEmployeeRepository.save(profile); await this.employeePositionRepository.save(positionNew); } - await CreatePosMasterHistoryEmployee(posMaster.id, req); }), ); @@ -6055,7 +6055,8 @@ export class CommandController extends Controller { await CreatePosMasterHistoryOfficer(posMasterOld.id, req); } await this.posMasterRepository.save(posMaster); - + await CreatePosMasterHistoryOfficer(posMaster.id, req); + const positionNew = await this.positionRepository.findOne({ where: { id: item.bodyPosition.positionId, @@ -6072,7 +6073,6 @@ export class CommandController extends Controller { setLogDataDiff(req, { before, after: profile }); await this.positionRepository.save(positionNew, { data: req }); } - await CreatePosMasterHistoryOfficer(posMaster.id, req); } // Insignia if (_oldInsigniaIds.length > 0) { @@ -6440,6 +6440,7 @@ export class CommandController extends Controller { await CreatePosMasterHistoryEmployee(posMasterOld.id, req); } await this.employeePosMasterRepository.save(posMaster); + await CreatePosMasterHistoryEmployee(posMaster.id, req); const clsTempPosmaster = await this.employeeTempPosMasterRepository.find({ where: { @@ -6568,7 +6569,6 @@ export class CommandController extends Controller { }); await this.profileEmployeeRepository.save(profile); await this.employeePositionRepository.save(positionNew); - await CreatePosMasterHistoryEmployee(posMaster.id, req); //ลบออกคนออกจากโครงสร้างลูกจ้างชั่วคราว const posMasterTemp = await this.employeeTempPosMasterRepository.findOne({ where: { @@ -6580,6 +6580,7 @@ export class CommandController extends Controller { await this.employeeTempPosMasterRepository.update(posMasterTemp.id, { current_holderId: _null, }); + await CreatePosMasterHistoryEmployeeTemp(posMasterTemp.id, req); } } }), diff --git a/src/controllers/EmployeePositionController.ts b/src/controllers/EmployeePositionController.ts index cd6be34f..632261e0 100644 --- a/src/controllers/EmployeePositionController.ts +++ b/src/controllers/EmployeePositionController.ts @@ -2451,6 +2451,7 @@ export class EmployeePositionController extends Controller { await CreatePosMasterHistoryEmployee(posMasterOld.id, request); } await this.employeePosMasterRepository.save(posMaster); + await CreatePosMasterHistoryEmployee(posMaster.id, request); const positionNew = await this.employeePositionRepository.findOne({ where: { @@ -2471,7 +2472,6 @@ export class EmployeePositionController extends Controller { await this.profileRepository.save(profile); await this.employeePositionRepository.save(positionNew); } - await CreatePosMasterHistoryEmployee(posMaster.id, request); return new HttpSuccess(); } diff --git a/src/controllers/EmployeeTempPositionController.ts b/src/controllers/EmployeeTempPositionController.ts index 4242af81..5d304de0 100644 --- a/src/controllers/EmployeeTempPositionController.ts +++ b/src/controllers/EmployeeTempPositionController.ts @@ -2187,6 +2187,7 @@ export class EmployeeTempPositionController extends Controller { await CreatePosMasterHistoryEmployeeTemp(posMasterOld.id, request); } await this.employeeTempPosMasterRepository.save(posMaster); + await CreatePosMasterHistoryEmployeeTemp(posMaster.id, request); const positionNew = await this.employeePositionRepository.findOne({ where: { @@ -2207,7 +2208,6 @@ export class EmployeeTempPositionController extends Controller { await this.profileRepository.save(profile); await this.employeePositionRepository.save(positionNew); } - await CreatePosMasterHistoryEmployeeTemp(posMaster.id, request); return new HttpSuccess(); } diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index 9bafbbe7..875f838e 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -4087,17 +4087,17 @@ export class PositionController extends Controller { }); posLevel = await this.posLevelRepository.find({ where: { - posTypeId: In(posType.map((x: any) => x.id)), - posLevelName: In(["ทรงคุณวุฒิ", "สูง"]) - }, + posTypeId: In(posType.map((x: any) => x.id)), + posLevelName: In(["ทรงคุณวุฒิ", "สูง"]), + }, }); - conditionA = "positions.posTypeId IN (:...posTypeIds) AND positions.posLevelId IN (:...posLevelIds)"; + conditionA = + "positions.posTypeId IN (:...posTypeIds) AND positions.posLevelId IN (:...posLevelIds)"; params = { posTypeIds: posType.map((x: any) => x.id), posLevelIds: posLevel.map((x: any) => x.id), }; - } - else { + } else { posType = await this.posTypeRepository.findOne({ where: { id: String(body.posType) }, }); @@ -4195,13 +4195,13 @@ export class PositionController extends Controller { .andWhere( new Brackets((qb) => { qb.andWhere(typeCondition) - // .andWhere(conditionA == null ? "1=1" : conditionA, { - // posType: posType == null ? `%%` : `${posType.id}`, - // posLevel: posLevel == null ? `%%` : `${posLevel.id}`, - // posTypeRank: posType == null ? 0 : posType.posTypeRank, - // posLevelRank: posLevel == null ? 0 : posLevel.posLevelRank, - // }); - .andWhere(conditionA, params); + // .andWhere(conditionA == null ? "1=1" : conditionA, { + // posType: posType == null ? `%%` : `${posType.id}`, + // posLevel: posLevel == null ? `%%` : `${posLevel.id}`, + // posTypeRank: posType == null ? 0 : posType.posTypeRank, + // posLevelRank: posLevel == null ? 0 : posLevel.posLevelRank, + // }); + .andWhere(conditionA, params); }), ) .orderBy("orgRoot.orgRootOrder", "ASC") @@ -4924,7 +4924,8 @@ export class PositionController extends Controller { await CreatePosMasterHistoryOfficer(posMasterOld.id, request); } await this.posMasterRepository.save(posMaster); - + await CreatePosMasterHistoryOfficer(posMaster.id, request); + const positionNew = await this.positionRepository.findOne({ where: { id: body.positionId, @@ -4939,7 +4940,6 @@ export class PositionController extends Controller { await this.profileRepository.save(profile); await this.positionRepository.save(positionNew); } - await CreatePosMasterHistoryOfficer(posMaster.id, request); return new HttpSuccess(); }