feat: isAllRoot

This commit is contained in:
Adisak 2026-02-13 09:29:31 +07:00
parent 7694a83d5a
commit cfd5ced28a
2 changed files with 124 additions and 102 deletions

View file

@ -4943,101 +4943,6 @@ export class PositionController extends Controller {
return new HttpSuccess({ data: formattedData, total });
}
/**
* API .
*
* @summary .
*
*/
@Post("act/search")
async searchAct(
@Request() request: RequestWithUser,
@Body()
body: {
posmasterId: string;
isAll: boolean;
},
) {
await new permission().PermissionGet(request, "SYS_ACTING");
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 = {};
if (body.isAll == true) {
typeCondition = {
orgRootId: posMasterMain.orgRootId,
orgChild1Id: posMasterMain.orgChild1Id,
orgChild2Id: posMasterMain.orgChild2Id,
orgChild3Id: posMasterMain.orgChild3Id,
orgChild4Id: posMasterMain.orgChild4Id,
current_holderId: Not(IsNull()),
id: Not(In(posId)),
};
} else {
typeCondition = {
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,
isDirector: item.isDirector ?? 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);
}
/**
* API
*