no message

This commit is contained in:
Kittapath 2024-06-25 10:21:30 +07:00
parent b11be3364f
commit 568d326797
6 changed files with 643 additions and 31 deletions

View file

@ -60,6 +60,7 @@ import {
import { ProfileEmployeeEmploymentHistory } from "../entities/ProfileEmployeeEmploymentHistory";
import CallAPI from "../interfaces/call-api";
import e from "cors";
import { EmployeePosition } from "../entities/EmployeePosition";
@Route("api/v1/org/profile-employee")
@Tags("ProfileEmployee")
@ -76,6 +77,7 @@ export class ProfileEmployeeController extends Controller {
private profileHistoryRepo = AppDataSource.getRepository(ProfileEmployeeHistory);
private posLevelRepo = AppDataSource.getRepository(EmployeePosLevel);
private posTypeRepo = AppDataSource.getRepository(EmployeePosType);
private positionRepository = AppDataSource.getRepository(EmployeePosition);
private provinceRepository = AppDataSource.getRepository(Province);
private districtRepository = AppDataSource.getRepository(District);
private subDistrict = AppDataSource.getRepository(SubDistrict);
@ -3210,4 +3212,129 @@ export class ProfileEmployeeController extends Controller {
return new HttpSuccess({ data: mapDataProfile, total });
}
/**
* API profileid
*
* @summary ORG_065 - profileid (ADMIN) #70
*
*/
@Get("profileid/position/{id}")
async getProfileByProfileid(
@Request() request: { user: Record<string, any> },
@Path() id: string,
) {
const profile = await this.profileRepo.findOne({
where: { id: id },
relations: ["posLevel", "posType", "current_holders", "current_holders.orgRoot"],
});
if (!profile) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ");
}
const orgRevisionPublish = await this.orgRevisionRepo
.createQueryBuilder("orgRevision")
.where("orgRevision.orgRevisionIsDraft = false")
.andWhere("orgRevision.orgRevisionIsCurrent = true")
.getOne();
if (!orgRevisionPublish) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบแบบร่างโครงสร้าง");
}
const posMaster =
profile.current_holders == null ||
profile.current_holders.length == 0 ||
profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id) == null
? null
: profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id);
const root =
profile.current_holders == null ||
profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgRoot == null
? null
: profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgRoot;
const child1 =
profile.current_holders == null ||
profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgChild1 ==
null
? null
: profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgChild1;
const child2 =
profile.current_holders == null ||
profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgChild2 ==
null
? null
: profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgChild2;
const child3 =
profile.current_holders == null ||
profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgChild3 ==
null
? null
: profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgChild3;
const child4 =
profile.current_holders == null ||
profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgChild4 ==
null
? null
: profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgChild4;
const position = await this.positionRepository.findOne({
relations: ["posExecutive"],
where: {
posMasterId: posMaster?.id,
},
});
const _profile: any = {
profileId: profile.id,
prefix: profile.prefix,
rank: profile.rank,
isProbation: profile.isProbation,
firstName: profile.firstName,
lastName: profile.lastName,
citizenId: profile.citizenId,
birthDate: profile.birthDate,
position: profile.position,
leaveDate: profile.dateLeave,
posMasterNo: posMaster == null ? null : posMaster.posMasterNo,
posLevelName: profile.posLevel == null ? null : profile.posLevel.posLevelName,
posLevelRank: profile.posLevel == null ? null : profile.posLevel.posLevelRank,
posLevelId: profile.posLevel == null ? null : profile.posLevel.id,
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: "",
rootId: root == null ? null : root.id,
root: root == null ? null : root.orgRootName,
rootShortName: root == null ? null : root.orgRootShortName,
child1Id: child1 == null ? null : child1.id,
child1: child1 == null ? null : child1.orgChild1Name,
child1ShortName: child1 == null ? null : child1.orgChild1ShortName,
child2Id: child2 == null ? null : child2.id,
child2: child2 == null ? null : child2.orgChild2Name,
child2ShortName: child2 == null ? null : child2.orgChild2ShortName,
child3Id: child3 == null ? null : child3.id,
child3: child3 == null ? null : child3.orgChild3Name,
child3ShortName: child3 == null ? null : child3.orgChild3ShortName,
child4Id: child4 == null ? null : child4.id,
child4: child4 == null ? null : child4.orgChild4Name,
child4ShortName: child4 == null ? null : child4.orgChild4ShortName,
node: null,
nodeId: null,
};
if (_profile.child4Id != null) {
_profile.node = 4;
_profile.nodeId = _profile.child4Id;
} else if (_profile.child3Id != null) {
_profile.node = 3;
_profile.nodeId = _profile.child3Id;
} else if (_profile.child2Id != null) {
_profile.node = 2;
_profile.nodeId = _profile.child2Id;
} else if (_profile.child1Id != null) {
_profile.node = 1;
_profile.nodeId = _profile.child1Id;
} else if (_profile.rootId != null) {
_profile.node = 0;
_profile.nodeId = _profile.rootId;
}
return new HttpSuccess(_profile);
}
}