เพิ่มselect detail tree
This commit is contained in:
parent
35ba5b91f3
commit
cd21c42710
7 changed files with 175 additions and 147 deletions
|
|
@ -418,25 +418,35 @@ export class PositionController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
const orgRoot = await this.orgRootRepository.findOne({
|
||||
where: { id: requestBody.orgRootId },
|
||||
});
|
||||
if (!orgRoot) {
|
||||
const orgChild1 = await this.child1Repository.findOne({
|
||||
where: { id: requestBody.orgChild1Id },
|
||||
let orgRoot: any = null;
|
||||
if (requestBody.orgRootId != null)
|
||||
orgRoot = await this.orgRootRepository.findOne({
|
||||
where: { id: requestBody.orgRootId },
|
||||
});
|
||||
if (!orgChild1) {
|
||||
const orgChild2 = await this.child2Repository.findOne({
|
||||
where: { id: requestBody.orgChild2Id },
|
||||
if (!orgRoot) {
|
||||
let orgChild1: any = null;
|
||||
if (requestBody.orgChild1Id != null)
|
||||
orgChild1 = await this.child1Repository.findOne({
|
||||
where: { id: requestBody.orgChild1Id },
|
||||
});
|
||||
if (!orgChild2) {
|
||||
const orgChild3 = await this.child3Repository.findOne({
|
||||
where: { id: requestBody.orgChild3Id },
|
||||
if (!orgChild1) {
|
||||
let orgChild2: any = null;
|
||||
if (requestBody.orgChild2Id != null)
|
||||
orgChild2 = await this.child2Repository.findOne({
|
||||
where: { id: requestBody.orgChild2Id },
|
||||
});
|
||||
if (!orgChild3) {
|
||||
const orgChild4 = await this.child4Repository.findOne({
|
||||
where: { id: requestBody.orgChild4Id },
|
||||
if (!orgChild2) {
|
||||
let orgChild3: any = null;
|
||||
if (requestBody.orgChild3Id != null)
|
||||
orgChild3 = await this.child3Repository.findOne({
|
||||
where: { id: requestBody.orgChild3Id },
|
||||
});
|
||||
if (!orgChild3) {
|
||||
let orgChild4: any = null;
|
||||
if (requestBody.orgChild4Id != null)
|
||||
orgChild4 = await this.child4Repository.findOne({
|
||||
where: { id: requestBody.orgChild4Id },
|
||||
});
|
||||
if (!orgChild4) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงสร้าง");
|
||||
} else {
|
||||
|
|
@ -541,25 +551,35 @@ export class PositionController extends Controller {
|
|||
posMaster.orgChild3Id = "";
|
||||
posMaster.orgChild4Id = "";
|
||||
|
||||
const orgRoot = await this.orgRootRepository.findOne({
|
||||
where: { id: requestBody.orgRootId },
|
||||
});
|
||||
if (!orgRoot) {
|
||||
const orgChild1 = await this.child1Repository.findOne({
|
||||
where: { id: requestBody.orgChild1Id },
|
||||
let orgRoot: any = null;
|
||||
if (requestBody.orgRootId != null)
|
||||
orgRoot = await this.orgRootRepository.findOne({
|
||||
where: { id: requestBody.orgRootId },
|
||||
});
|
||||
if (!orgChild1) {
|
||||
const orgChild2 = await this.child2Repository.findOne({
|
||||
where: { id: requestBody.orgChild2Id },
|
||||
if (!orgRoot) {
|
||||
let orgChild1: any = null;
|
||||
if (requestBody.orgChild1Id != null)
|
||||
orgChild1 = await this.child1Repository.findOne({
|
||||
where: { id: requestBody.orgChild1Id },
|
||||
});
|
||||
if (!orgChild2) {
|
||||
const orgChild3 = await this.child3Repository.findOne({
|
||||
where: { id: requestBody.orgChild3Id },
|
||||
if (!orgChild1) {
|
||||
let orgChild2: any = null;
|
||||
if (requestBody.orgChild2Id != null)
|
||||
orgChild2 = await this.child2Repository.findOne({
|
||||
where: { id: requestBody.orgChild2Id },
|
||||
});
|
||||
if (!orgChild3) {
|
||||
const orgChild4 = await this.child4Repository.findOne({
|
||||
where: { id: requestBody.orgChild4Id },
|
||||
if (!orgChild2) {
|
||||
let orgChild3: any = null;
|
||||
if (requestBody.orgChild3Id != null)
|
||||
orgChild3 = await this.child3Repository.findOne({
|
||||
where: { id: requestBody.orgChild3Id },
|
||||
});
|
||||
if (!orgChild3) {
|
||||
let orgChild4: any = null;
|
||||
if (requestBody.orgChild4Id != null)
|
||||
orgChild4 = await this.child4Repository.findOne({
|
||||
where: { id: requestBody.orgChild4Id },
|
||||
});
|
||||
if (!orgChild4) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงสร้าง");
|
||||
} else {
|
||||
|
|
@ -737,36 +757,38 @@ export class PositionController extends Controller {
|
|||
const posMaster = await this.posMasterRepository.find({
|
||||
where: typeCondition,
|
||||
});
|
||||
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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue