From 2a2635ad8334df65955b1dfadccc0fdecd8b18e7 Mon Sep 17 00:00:00 2001 From: harid Date: Tue, 27 Jan 2026 18:09:31 +0700 Subject: [PATCH] =?UTF-8?q?Add=20workflow=20=E0=B8=82=E0=B8=AD=E0=B9=81?= =?UTF-8?q?=E0=B8=81=E0=B9=89=E0=B9=84=E0=B8=82=E0=B8=82=E0=B9=89=E0=B8=AD?= =?UTF-8?q?=E0=B8=A1=E0=B8=B9=E0=B8=A5=E0=B8=97=E0=B8=B0=E0=B9=80=E0=B8=9A?= =?UTF-8?q?=E0=B8=B5=E0=B8=A2=E0=B8=99=E0=B8=9B=E0=B8=A3=E0=B8=B0=E0=B8=A7?= =?UTF-8?q?=E0=B8=B1=E0=B8=95=E0=B8=B4=20(=E0=B8=A5=E0=B8=B9=E0=B8=81?= =?UTF-8?q?=E0=B8=88=E0=B9=89=E0=B8=B2=E0=B8=87=E0=B8=9B=E0=B8=A3=E0=B8=B0?= =?UTF-8?q?=E0=B8=88=E0=B8=B3)=20#2222=20Fix=20=E0=B9=80=E0=B8=9E=E0=B8=B4?= =?UTF-8?q?=E0=B9=88=E0=B8=A1=E0=B8=A3=E0=B8=B2=E0=B8=A2=E0=B8=81=E0=B8=B2?= =?UTF-8?q?=E0=B8=A3=E0=B9=81=E0=B8=95=E0=B9=88=E0=B9=84=E0=B8=A1=E0=B9=88?= =?UTF-8?q?=E0=B9=81=E0=B8=AA=E0=B8=94=E0=B8=87=E0=B9=83=E0=B8=99=20Tab=20?= =?UTF-8?q?=E0=B8=A3=E0=B8=B2=E0=B8=A2=E0=B8=81=E0=B8=B2=E0=B8=A3=E0=B8=95?= =?UTF-8?q?=E0=B8=B3=E0=B9=81=E0=B8=AB=E0=B8=99=E0=B9=88=E0=B8=87/?= =?UTF-8?q?=E0=B9=80=E0=B8=87=E0=B8=B4=E0=B8=99=E0=B9=80=E0=B8=94=E0=B8=B7?= =?UTF-8?q?=E0=B8=AD=E0=B8=99=E0=B8=AB=E0=B8=A5=E0=B8=B1=E0=B8=87=E0=B8=88?= =?UTF-8?q?=E0=B8=B2=E0=B8=81=E0=B9=81=E0=B8=81=E0=B9=89=E0=B9=84=E0=B8=82?= =?UTF-8?q?=E0=B9=81=E0=B8=A5=E0=B9=89=E0=B8=A7=20#2243?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProfileEditEmployeeController.ts | 41 ++++++++++++++++++- .../ProfileSalaryTempController.ts | 1 + 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/controllers/ProfileEditEmployeeController.ts b/src/controllers/ProfileEditEmployeeController.ts index 8abc6d8b..86c364d5 100644 --- a/src/controllers/ProfileEditEmployeeController.ts +++ b/src/controllers/ProfileEditEmployeeController.ts @@ -26,7 +26,8 @@ import { RequestWithUser } from "../middlewares/user"; import { Brackets } from "typeorm"; import permission from "../interfaces/permission"; import { OrgRevision } from "../entities/OrgRevision"; - +import { OrgRoot } from "../entities/OrgRoot"; +import CallAPI from "../interfaces/call-api"; @Route("api/v1/org/profile-employee/edit") @Tags("ProfileEmployeeEdit") @Security("bearerAuth") @@ -34,6 +35,7 @@ export class ProfileEditEmployeeController extends Controller { private profileEmployeeRepo = AppDataSource.getRepository(ProfileEmployee); private profileEditRepository = AppDataSource.getRepository(ProfileEdit); private orgRevisionRepository = AppDataSource.getRepository(OrgRevision); + private orgRootRepo = AppDataSource.getRepository(OrgRoot); @Get("user") public async detailProfileEditUserEmp( @@ -294,10 +296,32 @@ export class ProfileEditEmployeeController extends Controller { @Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeEdit, ) { - const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: req.user.sub }); + // const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: req.user.sub }); + const profile = await this.profileEmployeeRepo.findOne({ + relations: { + current_holders: true + }, + where: { + keycloak: req.user.sub, + current_holders: { + orgRevision: { + orgRevisionIsCurrent: true, + orgRevisionIsDraft: false + } + } + } + }); if (!profile) { throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); } + const orgRoot = await this.orgRootRepo.findOne({ + select: { + isDeputy: true + }, + where: { + id: profile.current_holders.find(x => x.orgRootId)!.orgRootId ?? "" + } + }); const data = new ProfileEdit(); const meta = { @@ -312,6 +336,19 @@ export class ProfileEditEmployeeController extends Controller { data.status = "PENDING"; await this.profileEditRepository.save(data); + await new CallAPI() + .PostData(req, "/org/workflow/add-workflow", { + refId: data.id, + sysName: "REGISTRY_PROFILE_EMP", + posLevelName: "EMP", + posTypeName: "EMP", + fullName: `${profile.prefix}${profile.firstName} ${profile.lastName}`, + isDeputy: orgRoot?.isDeputy ?? false + }) + .catch((error) => { + console.error("Error calling API:", error); + }); + return new HttpSuccess(data.id); } diff --git a/src/controllers/ProfileSalaryTempController.ts b/src/controllers/ProfileSalaryTempController.ts index 8b49622a..cbdcf50a 100644 --- a/src/controllers/ProfileSalaryTempController.ts +++ b/src/controllers/ProfileSalaryTempController.ts @@ -1212,6 +1212,7 @@ export class ProfileSalaryTempController extends Controller { createdAt: new Date(), lastUpdatedAt: new Date(), isEdit: true, + isDelete: false, }; Object.assign(data, { ...body, ...meta }); await this.salaryRepo.save(data, { data: req });