From ecadf565ac6d148a9edd61411d22df3ddbf232ee Mon Sep 17 00:00:00 2001 From: kittapath Date: Tue, 22 Oct 2024 16:09:46 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=A3=E0=B8=B2=E0=B8=A2=E0=B8=8A=E0=B8=B7?= =?UTF-8?q?=E0=B9=88=E0=B8=AD=E0=B8=9C=E0=B8=B9=E0=B9=89=E0=B9=84=E0=B8=94?= =?UTF-8?q?=E0=B9=89=E0=B8=A3=E0=B8=B1=E0=B8=9A=E0=B8=AA=E0=B8=B3=E0=B9=80?= =?UTF-8?q?=E0=B8=99=E0=B8=B2=E0=B8=84=E0=B8=B3=E0=B8=AA=E0=B8=B1=E0=B9=88?= =?UTF-8?q?=E0=B8=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/CommandController.ts | 57 ++++++++++++++++++++++++--- src/controllers/WorkflowController.ts | 32 +++++++++++++++ 2 files changed, 84 insertions(+), 5 deletions(-) diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 26edc464..31375858 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -18,7 +18,7 @@ import HttpSuccess from "../interfaces/http-success"; import HttpStatusCode from "../interfaces/http-status"; import HttpError from "../interfaces/http-error"; import { Command } from "../entities/Command"; -import { Brackets, LessThan, MoreThan, Double, In, Between } from "typeorm"; +import { Brackets, LessThan, MoreThan, Double, In, Between, IsNull, Not } from "typeorm"; import { CommandType } from "../entities/CommandType"; import { CommandSend } from "../entities/CommandSend"; import { Profile, CreateProfileAllFields } from "../entities/Profile"; @@ -1429,6 +1429,53 @@ export class CommandController extends Controller { ); }) .catch(() => {}); + + if (requestBody.persons != undefined && requestBody.persons.length > 0) { + const posMaster = await this.posMasterRepository.find({ + where: { + current_holderId: In(requestBody.persons.map((x) => x.profileId)), + orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, + }, + select: ["orgRootId"], + }); + + const _posMaster = await this.posMasterRepository.find({ + where: { + orgRootId: In(posMaster.map((x) => x.orgRootId)), + orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, + isDirector: true, + current_holderId: Not(IsNull()), + }, + relations: ["current_holder", "orgRoot"], + }); + await Promise.all( + _posMaster.map(async (item) => { + const _commandSend = await this.commandSendRepository.findOne({ + where: { + commandId: command.id, + profileId: item.current_holder.id, + }, + }); + if (_commandSend) return; + let commandSend = new CommandSend(); + commandSend.citizenId = item.current_holder.citizenId; + commandSend.prefix = item.current_holder.prefix; + commandSend.firstName = item.current_holder.firstName; + commandSend.lastName = item.current_holder.lastName; + commandSend.position = item.current_holder.position; + commandSend.org = item.orgRoot.orgRootName; + commandSend.profileId = item.current_holder.id; + commandSend.commandId = command.id; + commandSend.createdUserId = request.user.sub; + commandSend.createdFullName = request.user.name; + commandSend.createdAt = new Date(); + commandSend.lastUpdateUserId = request.user.sub; + commandSend.lastUpdateFullName = request.user.name; + commandSend.lastUpdatedAt = new Date(); + await this.commandSendRepository.save(commandSend); + }), + ); + } return new HttpSuccess(command.id); } @@ -1487,7 +1534,7 @@ export class CommandController extends Controller { Object.assign(history, { ...data, id: undefined }); await this.salaryRepo.save(data, { data: req }); setLogDataDiff(req, { before, after: data }); - history.commandId = item.commandId??_null; + history.commandId = item.commandId ?? _null; await this.salaryHistoryRepo.save(history, { data: req }); const posMaster = await this.posMasterRepository.findOne({ @@ -2040,7 +2087,7 @@ export class CommandController extends Controller { createdAt: new Date(), lastUpdatedAt: new Date(), dateGovernment: new Date(), - isGovernment: item.isGovernment + isGovernment: item.isGovernment, }; Object.assign(data, meta); @@ -2253,7 +2300,7 @@ export class CommandController extends Controller { createdAt: new Date(), lastUpdatedAt: new Date(), dateGovernment: new Date(), - isGovernment: item.isGovernment + isGovernment: item.isGovernment, }); await Promise.all([ this.profileRepository.save(_profile), @@ -2507,7 +2554,7 @@ export class CommandController extends Controller { profileEmployeeId: profile.id, date: new Date(), amount: item.amount, - commandId: item.commandId, + commandId: item.commandId, positionSalaryAmount: item.positionSalaryAmount, mouthSalaryAmount: item.mouthSalaryAmount, posNo: profile.posMasterNoTemp, diff --git a/src/controllers/WorkflowController.ts b/src/controllers/WorkflowController.ts index b877087e..8b334a83 100644 --- a/src/controllers/WorkflowController.ts +++ b/src/controllers/WorkflowController.ts @@ -580,9 +580,41 @@ export class WorkflowController extends Controller { where: { id: body.stateUserCommentId, }, + relations: ["state", "state.workflow", "state.stateOperators"], }); if (!stateUserComment) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลขั้นตอนการอนุมัติ"); + stateUserComment.state.stateOperators; + + const workflow = await this.workflowRepo.findOne({ + where: { + refId: stateUserComment.state.workflow.refId, + sysName: stateUserComment.state.workflow.sysName, + }, + relations: ["stateOperatorUsers"], + }); + if (!workflow) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่สามารถดำเนินการกระบวนการนี้ได้"); + let profileNow = workflow.stateOperatorUsers + .filter((x) => + stateUserComment.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); + }); let _null: any = null; stateUserComment.isAccept = body.isAccept == null ? _null : body.isAccept; stateUserComment.isApprove = body.isApprove == null ? _null : body.isApprove;