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 });