checkpoint ORG_053

This commit is contained in:
AdisakKanthawilang 2024-01-31 17:51:49 +07:00
parent 923d75ebe3
commit 1b9f9a634e

View file

@ -703,10 +703,10 @@ export class PositionController extends Controller {
body: {
id: string;
type: number;
// isAll: boolean;
// page: number;
// pageSize: number;
// keyword?: string;
isAll: boolean;
page: number;
pageSize: number;
keyword?: string;
},
) {
try {
@ -736,10 +736,38 @@ export class PositionController extends Controller {
const posMaster = await this.posMasterRepository.find({
where: typeCondition,
// relations: ["position"]
});
return new HttpSuccess(posMaster);
if (!posMaster || posMaster.length === 0 ) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
const formattedData = await Promise.all(posMaster.map(async (posMaster) => {
const positions = await this.positionRepository.find({
where: { posMasterId: posMaster.id },
});
return {
id: posMaster.id,
posMasterNoPrefix: posMaster.posMasterNoPrefix,
posMasterNo: posMaster.posMasterNo,
posMasterNoSuffix: posMaster.posMasterNoSuffix,
positions: positions.map((position) => ({
id: position.id,
positionName: position.positionName,
positionField: position.positionField,
posTypeId: position.posTypeId,
posTypeName: position.posType == null ? null : position.posType.posTypeName,
posLevelId: position.posLevelId,
posLevelName: position.posLevel == null ? null : position.posLevel.posLevelName,
posExecutiveId: position.posExecutiveId,
posExecutiveName:
position.posExecutive == null ? null : position.posExecutive.posExecutiveName,
positionExecutiveField: position.positionExecutiveField,
positionArea: position.positionArea,
positionIsSelected: position.positionIsSelected,
})),
};
}));
return new HttpSuccess(formattedData);
} catch (error) {
return error;
}