diff --git a/src/controllers/ProfileEditController.ts b/src/controllers/ProfileEditController.ts index a1e081f3..35f26786 100644 --- a/src/controllers/ProfileEditController.ts +++ b/src/controllers/ProfileEditController.ts @@ -24,6 +24,7 @@ import CallAPI from "../interfaces/call-api"; import permission from "../interfaces/permission"; import { OrgRevision } from "../entities/OrgRevision"; import { OrgRoot } from "../entities/OrgRoot"; +import { PosMaster } from "../entities/PosMaster"; @Route("api/v1/org/profile/edit") @Tags("ProfileEdit") @Security("bearerAuth") @@ -32,6 +33,7 @@ export class ProfileEditController extends Controller { private profileEditRepo = AppDataSource.getRepository(ProfileEdit); private orgRevisionRepository = AppDataSource.getRepository(OrgRevision); private orgRootRepo = AppDataSource.getRepository(OrgRoot); + private posMasterRepo = AppDataSource.getRepository(PosMaster); @Get("user") public async detailProfileEditUser( @@ -272,6 +274,22 @@ export class ProfileEditController extends Controller { if (!getProfileEdit) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); } + let orgRoot: OrgRoot | null = null; + if(getProfileEdit.profile) { + const empPosMaster = await this.posMasterRepo.findOne({ + where: { + current_holderId: getProfileEdit.profile.id, + orgRevision: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false } + }, + relations: { orgRevision: true } + }); + if(empPosMaster) { + orgRoot = await this.orgRootRepo.findOne({ + select: { isDeputy: true }, + where: { id: empPosMaster.orgRootId ?? "" } + }); + } + } const _data = { id: getProfileEdit.id, topic: getProfileEdit.topic, @@ -289,6 +307,7 @@ export class ProfileEditController extends Controller { (getProfileEdit?.profile?.firstName ?? "") + " " + (getProfileEdit?.profile?.lastName ?? ""), + isDeputy: orgRoot?.isDeputy ?? false }; return new HttpSuccess(_data); } diff --git a/src/controllers/ProfileEditEmployeeController.ts b/src/controllers/ProfileEditEmployeeController.ts index 87bba20a..2cdd9fde 100644 --- a/src/controllers/ProfileEditEmployeeController.ts +++ b/src/controllers/ProfileEditEmployeeController.ts @@ -28,6 +28,7 @@ import permission from "../interfaces/permission"; import { OrgRevision } from "../entities/OrgRevision"; import { OrgRoot } from "../entities/OrgRoot"; import CallAPI from "../interfaces/call-api"; +import { EmployeePosMaster } from "../entities/EmployeePosMaster"; @Route("api/v1/org/profile-employee/edit") @Tags("ProfileEmployeeEdit") @Security("bearerAuth") @@ -36,6 +37,7 @@ export class ProfileEditEmployeeController extends Controller { private profileEditRepository = AppDataSource.getRepository(ProfileEdit); private orgRevisionRepository = AppDataSource.getRepository(OrgRevision); private orgRootRepo = AppDataSource.getRepository(OrgRoot); + private empPosMasterRepo = AppDataSource.getRepository(EmployeePosMaster); @Get("user") public async detailProfileEditUserEmp( @@ -271,6 +273,22 @@ export class ProfileEditEmployeeController extends Controller { if (!getProfileEdit) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); } + let orgRoot: OrgRoot | null = null; + if(getProfileEdit.profileEmployee) { + const empPosMaster = await this.empPosMasterRepo.findOne({ + where: { + current_holderId: getProfileEdit.profileEmployee.id, + orgRevision: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false } + }, + relations: { orgRevision: true } + }); + if(empPosMaster) { + orgRoot = await this.orgRootRepo.findOne({ + select: { isDeputy: true }, + where: { id: empPosMaster.orgRootId ?? "" } + }); + } + } const _data = { id: getProfileEdit.id, topic: getProfileEdit.topic, @@ -288,6 +306,7 @@ export class ProfileEditEmployeeController extends Controller { (getProfileEdit?.profileEmployee?.firstName ?? "") + " " + (getProfileEdit?.profileEmployee?.lastName ?? ""), + isDeputy: orgRoot?.isDeputy ?? false }; return new HttpSuccess(_data); }