api รักษาการแทน

This commit is contained in:
Kittapath 2024-06-19 23:03:54 +07:00
parent f7c553ec1d
commit 9de005c7ae
8 changed files with 752 additions and 69 deletions

View file

@ -1274,7 +1274,7 @@ export class PositionController extends Controller {
});
const authRoleName = await this.authRoleRepo.findOne({
where: { id: String(posMaster.authRoleId) }
where: { id: String(posMaster.authRoleId) },
});
let profile: any;
@ -1366,7 +1366,8 @@ export class PositionController extends Controller {
profilePostype: type == null || type.posTypeName == null ? null : type.posTypeName,
profilePoslevel: level == null || level.posLevelName == null ? null : level.posLevelName,
authRoleId: posMaster.authRoleId,
authRoleName: authRoleName == null || authRoleName.roleName == null ? null : authRoleName.roleName,
authRoleName:
authRoleName == null || authRoleName.roleName == null ? null : authRoleName.roleName,
positions: positions.map((position: any) => ({
id: position.id,
positionName: position.positionName,
@ -2743,6 +2744,14 @@ export class PositionController extends Controller {
posMasterNoSuffix: posMaster.posMasterNoSuffix,
orgShortname: shortName,
isSit: posMaster.isSit,
fullNameCurrentHolder:
posMaster.current_holder == null
? null
: `${posMaster.current_holder.prefix}${posMaster.current_holder.firstName} ${posMaster.current_holder.lastName}`,
fullNameNextHolder:
posMaster.next_holder == null
? null
: `${posMaster.next_holder.prefix}${posMaster.next_holder.firstName} ${posMaster.next_holder.lastName}`,
isPosition: posMaster.positions.filter((x) => x.positionName == body.position).length > 0,
positions: posMaster.positions.map((position) => ({
id: position.id,
@ -3181,4 +3190,81 @@ export class PositionController extends Controller {
);
return new HttpSuccess({ data: formattedData, total });
}
/**
* API .
*
* @summary .
*
*/
@Post("act/search")
async searchAct(
@Body()
body: {
posmasterId: string;
},
) {
const posMasterMain = await this.posMasterRepository.findOne({
where: { id: body.posmasterId },
relations: ["posMasterActs"],
});
if (posMasterMain == null) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้");
}
let posId: any = posMasterMain.posMasterActs.map((x) => x.posMasterChildId);
posId.push(body.posmasterId);
let typeCondition: any = {
orgRootId: posMasterMain.orgRootId == null ? IsNull() : posMasterMain.orgRootId,
orgChild1Id: posMasterMain.orgChild1Id == null ? IsNull() : posMasterMain.orgChild1Id,
orgChild2Id: posMasterMain.orgChild2Id == null ? IsNull() : posMasterMain.orgChild2Id,
orgChild3Id: posMasterMain.orgChild3Id == null ? IsNull() : posMasterMain.orgChild3Id,
orgChild4Id: posMasterMain.orgChild4Id == null ? IsNull() : posMasterMain.orgChild4Id,
current_holderId: Not(IsNull()),
id: Not(In(posId)),
};
const posMaster = await this.posMasterRepository.find({
where: typeCondition,
relations: [
"orgRoot",
"orgChild1",
"orgChild2",
"orgChild3",
"orgChild4",
"current_holder",
"current_holder.posLevel",
"current_holder.posType",
],
});
const data = await Promise.all(
posMaster
.sort((a, b) => a.posMasterOrder - b.posMasterOrder)
.map((item) => {
const shortName =
item.orgChild4 != null
? `${item.orgChild4.orgChild4ShortName}${item.posMasterNo}`
: item?.orgChild3 != null
? `${item.orgChild3.orgChild3ShortName}${item.posMasterNo}`
: item?.orgChild2 != null
? `${item.orgChild2.orgChild2ShortName}${item.posMasterNo}`
: item?.orgChild1 != null
? `${item.orgChild1.orgChild1ShortName}${item.posMasterNo}`
: item?.orgRoot != null
? `${item.orgRoot.orgRootShortName}${item.posMasterNo}`
: null;
return {
id: item.id,
citizenId: item.current_holder?.citizenId ?? null,
prefix: item.current_holder?.prefix ?? null,
firstName: item.current_holder?.firstName ?? null,
lastName: item.current_holder?.lastName ?? null,
posLevel: item.current_holder?.posLevel?.posLevelName ?? null,
posType: item.current_holder?.posType?.posTypeName ?? null,
position: item.current_holder?.position ?? null,
posNo: shortName,
};
}),
);
return new HttpSuccess(data);
}
}