diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index cd3c7dfb..e1d76c73 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -33,6 +33,7 @@ import { PosLevel } from "../entities/PosLevel"; import { PosType } from "../entities/PosType"; import { calculateAge, calculateRetireDate, calculateRetireYear } from "../interfaces/utils"; import { RequestWithUser } from "../middlewares/user"; +import { Position } from "../entities/Position"; @Route("api/v1/org/profile") @Tags("Profile") @@ -50,6 +51,7 @@ export class ProfileController extends Controller { private posLevelRepo = AppDataSource.getRepository(PosLevel); private posTypeRepo = AppDataSource.getRepository(PosType); private orgRevisionRepository = AppDataSource.getRepository(OrgRevision); + private positionRepository = AppDataSource.getRepository(Position); /** * @@ -752,6 +754,14 @@ export class ProfileController extends Controller { profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id) == null ? null : profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id); + + const position = await this.positionRepository.findOne({ + relations: ["posExecutive"], + where: { + posMasterId: posMaster?.id + } + }); + const _profile: any = { profileId: profile.id, prefix: profile.prefix, @@ -767,6 +777,15 @@ export class ProfileController extends Controller { posTypeName: profile.posType == null ? null : profile.posType.posTypeName, posTypeRank: profile.posType == null ? null : profile.posType.posTypeRank, posTypeId: profile.posType == null ? null : profile.posType.id, + posExecutiveName: position == null || position.posExecutive == null + ? null + : position.posExecutive.posExecutiveName, + posExecutivePriority: position == null || position.posExecutive == null + ? null + : position.posExecutive.posExecutivePriority, + posExecutiveId: position == null || position.posExecutive == null + ? null + : position.posExecutive.id, rootId: profile.current_holders == null || profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgRoot == @@ -1911,6 +1930,19 @@ export class ProfileController extends Controller { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ"); } + const posMaster = await this.posMasterRepo.findOne({ + where: { + current_holderId: profile.id, + orgRevisionId: revisionId + } + }); + const position = await this.positionRepository.findOne({ + relations: ["posExecutive"], + where: { + posMasterId: posMaster?.id + } + }); + const _profile = { profileId: profile.id, prefix: profile.prefix, @@ -1925,6 +1957,15 @@ export class ProfileController extends Controller { posTypeName: profile.posType == null ? null : profile.posType.posTypeName, posTypeRank: profile.posType == null ? null : profile.posType.posTypeRank, posTypeId: profile.posType == null ? null : profile.posType.id, + posExecutiveName: position == null || position.posExecutive == null + ? null + : position.posExecutive.posExecutiveName, + posExecutivePriority: position == null || position.posExecutive == null + ? null + : position.posExecutive.posExecutivePriority, + posExecutiveId: position == null || position.posExecutive == null + ? null + : position.posExecutive.id, rootId: profile.current_holders == null || profile.current_holders.find((x) => x.orgRevisionId == revisionId) == null ||