From 2f378fa4a18dfa3e9c1a11161c3bfb4bb8014803 Mon Sep 17 00:00:00 2001 From: kittapath Date: Mon, 28 Oct 2024 17:39:13 +0700 Subject: [PATCH 1/4] no message --- src/controllers/ProfileController.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index c1f2d13a..d00dd9fd 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -3615,7 +3615,7 @@ export class ProfileController extends Controller { }, relations: ["orgChild1"], }); - if (posMasters == null || posMasters.orgChild1 == null) { + if (posMasters == null) { return new HttpSuccess({ isOfficer: null, rootId: null, @@ -3626,7 +3626,7 @@ export class ProfileController extends Controller { }); } return new HttpSuccess({ - isOfficer: posMasters?.orgChild1?.isOfficer || null, + isOfficer: posMasters?.orgChild1?.isOfficer || false, rootId: posMasters?.orgRootId || null, child1Id: posMasters?.orgChild1Id || null, child2Id: posMasters?.orgChild2Id || null, From 1b3f42fd855d43e841874c555ae2ce7aba64fb67 Mon Sep 17 00:00:00 2001 From: Bright Date: Mon, 28 Oct 2024 18:01:36 +0700 Subject: [PATCH 2/4] =?UTF-8?q?fix=20=E0=B8=9B=E0=B8=A5=E0=B8=94=E0=B8=88?= =?UTF-8?q?=E0=B8=B2=E0=B8=81=E0=B8=81=E0=B8=B4=E0=B9=88=E0=B8=87=20?= =?UTF-8?q?=E0=B8=A2=E0=B8=81=E0=B9=80=E0=B8=A7=E0=B9=89=E0=B8=99=E0=B8=84?= =?UTF-8?q?=E0=B8=B3=E0=B8=AA=E0=B8=B1=E0=B9=88=E0=B8=8725=2026?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/CommandController.ts | 6 ++++-- src/interfaces/utils.ts | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 9e654ffe..033e9133 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -39,6 +39,7 @@ import { commandTypePath, removeProfileInOrganize, setLogDataDiff, + checkExceptCommandType, checkCommandType, } from "../interfaces/utils"; import { Position } from "../entities/Position"; @@ -2113,7 +2114,7 @@ export class CommandController extends Controller { // ประวัติตำแหน่ง const data = new ProfileSalary(); const meta = { - profileId: item.profileId, + profileId: profile.id, date: item.date, refCommandNo: item.refCommandNo, templateDoc: item.salaryRef, @@ -2185,7 +2186,8 @@ export class CommandController extends Controller { profile.lastUpdateUserId = req.user.sub; profile.lastUpdateFullName = req.user.name; profile.lastUpdatedAt = new Date(); - if (item.isLeave == true) { + const exceptClear = await checkExceptCommandType(String(item.commandId)); + if (item.isLeave == true && !exceptClear) { await removeProfileInOrganize(profile.id, "OFFICER"); } const clearProfile = await checkCommandType(String(item.commandId)); diff --git a/src/interfaces/utils.ts b/src/interfaces/utils.ts index 826df67f..1c31504c 100644 --- a/src/interfaces/utils.ts +++ b/src/interfaces/utils.ts @@ -175,6 +175,20 @@ export async function removeProfileInOrganize(profileId: string, type: string) { } } +export async function checkExceptCommandType(commandId: string) { + const commandRepository = AppDataSource.getRepository(Command); + const _type = await commandRepository.findOne({ + where: { + id: commandId + }, + relations: ["commandType"], + }); + if (!["C-PM-25", "C-PM-26"].includes(String(_type?.commandType.code))) { + return false; + } + return true; +} + export async function checkCommandType(commandId: string) { const commandRepository = AppDataSource.getRepository(Command); const _type = await commandRepository.findOne({ From 08706f57ed4c400aa49c7bc3c500cc2c3d690eae Mon Sep 17 00:00:00 2001 From: Bright Date: Mon, 28 Oct 2024 20:59:31 +0700 Subject: [PATCH 3/4] =?UTF-8?q?create=20user=20keycloak=20=E0=B9=80?= =?UTF-8?q?=E0=B8=A1=E0=B8=B7=E0=B9=88=E0=B8=AD=E0=B8=81=E0=B8=A5=E0=B8=B1?= =?UTF-8?q?=E0=B8=9A=E0=B9=80=E0=B8=82=E0=B9=89=E0=B8=B2=E0=B8=A3=E0=B8=B1?= =?UTF-8?q?=E0=B8=9A=E0=B8=A3=E0=B8=B2=E0=B8=8A=E0=B8=81=E0=B8=B2=E0=B8=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/CommandController.ts | 25 +++++++++++++++++++++++++ src/interfaces/utils.ts | 14 ++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 033e9133..e836ad41 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -39,6 +39,7 @@ import { commandTypePath, removeProfileInOrganize, setLogDataDiff, + checkReturnCommandType, checkExceptCommandType, checkCommandType, } from "../interfaces/utils"; @@ -1838,6 +1839,30 @@ export class CommandController extends Controller { profile.posTypeId = _null; profile.posLevelId = _null; } + const returnWork = await checkReturnCommandType(String(item.commandId)); + if(returnWork && item.isGovernment) { + const userKeycloakId = await createUser(profile.citizenId, profile.citizenId, { + firstName: profile.firstName, + lastName: profile.lastName, + }); + if (typeof userKeycloakId !== "string") { + throw new Error(userKeycloakId.errorMessage); + } + const list = await getRoles(); + if (!Array.isArray(list)) + throw new Error("Failed. Cannot get role(s) data from the server."); + const result = await addUserRoles( + userKeycloakId, + list + .filter((v) => v.name === "USER") + .map((x) => ({ + id: x.id, + name: x.name, + })), + ); + if (!result) throw new Error("Failed. Cannot set user's role."); + profile.keycloak = userKeycloakId; + } await this.profileRepository.save(profile); }), ); diff --git a/src/interfaces/utils.ts b/src/interfaces/utils.ts index 1c31504c..91070e1d 100644 --- a/src/interfaces/utils.ts +++ b/src/interfaces/utils.ts @@ -175,6 +175,20 @@ export async function removeProfileInOrganize(profileId: string, type: string) { } } +export async function checkReturnCommandType(commandId: string) { + const commandRepository = AppDataSource.getRepository(Command); + const _type = await commandRepository.findOne({ + where: { + id: commandId + }, + relations: ["commandType"], + }); + if (!["C-PM-08", "C-PM-09"].includes(String(_type?.commandType.code))) { + return false; + } + return true; +} + export async function checkExceptCommandType(commandId: string) { const commandRepository = AppDataSource.getRepository(Command); const _type = await commandRepository.findOne({ From 049a0299de7e933836f763cc775fa61681602e76 Mon Sep 17 00:00:00 2001 From: kittapath Date: Tue, 29 Oct 2024 09:38:06 +0700 Subject: [PATCH 4/4] no message --- src/controllers/WorkflowController.ts | 33 +++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/controllers/WorkflowController.ts b/src/controllers/WorkflowController.ts index 8b334a83..2d60eed2 100644 --- a/src/controllers/WorkflowController.ts +++ b/src/controllers/WorkflowController.ts @@ -156,6 +156,39 @@ export class WorkflowController extends Controller { }), ); + const _workflow = await this.workflowRepo.findOne({ + where: { id: workflow.id }, + relations: ["stateOperatorUsers"], + }); + if (!_workflow) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่สามารถดำเนินการกระบวนการนี้ได้"); + + const _state = await this.stateRepo.findOne({ + where: { + id: _workflow.stateId, + }, + relations: ["stateOperators"], + }); + if (!_state) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลขั้นตอนการอนุมัติ"); + let profileNow = _workflow.stateOperatorUsers + .filter((x) => _state.stateOperators.map((s) => s.operator).includes(x.operator)) + .map((x) => ({ + receiverUserId: x.profile, + notiLink: "", + })); + await new CallAPI() + .PostData(req, "/placement/noti/profiles", { + subject: `รายการถูกส่ง`, + body: `รายการถูกส่ง`, + receiverUserIds: profileNow, + payload: "", //แนบไฟล์ + isSendMail: true, + isSendInbox: true, + isSendNotification: true, + }) + .catch((error) => { + console.error("Error calling API:", error); + }); + return new HttpSuccess(); }