org_053 รายการอัตรากำลัง

This commit is contained in:
AdisakKanthawilang 2024-02-01 11:12:44 +07:00
parent 1b9f9a634e
commit ee15891310

View file

@ -24,7 +24,7 @@ import { PosType } from "../entities/PosType";
import { PosLevel } from "../entities/PosLevel";
import { CreatePosDict, PosDict } from "../entities/PosDict";
import HttpError from "../interfaces/http-error";
import { In, Like } from "typeorm";
import { In, IsNull, Like } from "typeorm";
import { CreatePosMaster, PosMaster } from "../entities/PosMaster";
import { OrgRevision } from "../entities/OrgRevision";
import { OrgRoot } from "../entities/OrgRoot";
@ -711,23 +711,44 @@ export class PositionController extends Controller {
) {
try {
let typeCondition: any = {};
let checkChildConditions: any = {};
if (body.type === 0) {
typeCondition = {
orgRootId: body.id,
};
if (!body.isAll) {
checkChildConditions = {
orgChild1Id: IsNull(),
};
}
} else if (body.type === 1) {
typeCondition = {
orgChild1Id: body.id,
};
if (!body.isAll) {
checkChildConditions = {
orgChild2Id: IsNull(),
};
}
} else if (body.type === 2) {
typeCondition = {
orgChild2Id: body.id,
};
if (!body.isAll) {
checkChildConditions = {
orgChild3Id: IsNull(),
};
}
} else if (body.type === 3) {
typeCondition = {
orgChild3Id: body.id,
};
if (!body.isAll) {
checkChildConditions = {
orgChild4Id: IsNull(),
};
}
} else if (body.type === 4) {
typeCondition = {
orgChild4Id: body.id,
@ -735,38 +756,43 @@ export class PositionController extends Controller {
}
const posMaster = await this.posMasterRepository.find({
where: typeCondition,
where: {
...typeCondition,
...checkChildConditions,
},
});
if (!posMaster || posMaster.length === 0 ) {
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,
})),
};
}));
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;