ปรับ api ตำแหน่งทั้งหมด

This commit is contained in:
Bright 2024-02-09 16:35:01 +07:00
parent 3bfbb93691
commit 0e71ba98ea

View file

@ -1137,7 +1137,7 @@ export class PositionController extends Controller {
* *
*/ */
@Post("summary") @Post("summary")
async PositionSummary(@Body() requestBody: { id: string; type: number }) { async PositionSummary(@Body() requestBody: { id: string; type: number; isNode: boolean }) {
try { try {
let summary: any; let summary: any;
let totalPosition: any; let totalPosition: any;
@ -1146,204 +1146,517 @@ export class PositionController extends Controller {
let totalPositionNextUse: any; let totalPositionNextUse: any;
let totalPositionNextVacant: any; let totalPositionNextVacant: any;
switch (requestBody.type) { if(requestBody.isNode === true){
case 0: { switch (requestBody.type) {
const NodeId = await this.posMasterRepository.findOne({ case 0: {
where: { orgRootId: requestBody.id }, const NodeId = await this.posMasterRepository.findOne({
}); where: { orgRootId: requestBody.id },
if (!NodeId) { });
throw new HttpError( if (!NodeId) {
HttpStatusCode.NOT_FOUND, throw new HttpError(
"ไม่พบข้อมูลตามไอดีนี้ : " + requestBody.id, HttpStatusCode.NOT_FOUND,
); "ไม่พบข้อมูลตามไอดีนี้ : " + requestBody.id,
);
}
totalPosition = await this.posMasterRepository.count({
where: { orgRootId: requestBody.id },
});
totalPositionCurrentUse = await this.posMasterRepository.count({
where: {
orgRootId: requestBody.id,
current_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionCurrentVacant = await this.posMasterRepository.count({
where: {
orgRootId: requestBody.id,
current_holderId: IsNull() && "",
},
});
totalPositionNextUse = await this.posMasterRepository.count({
where: {
orgRootId: requestBody.id,
next_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionNextVacant = await this.posMasterRepository.count({
where: {
orgRootId: requestBody.id,
next_holderId: IsNull() && "",
},
});
break;
} }
totalPosition = await this.posMasterRepository.count({ case 1: {
where: { orgRootId: requestBody.id }, const NodeId = await this.posMasterRepository.findOne({
}); where: { orgChild1Id: requestBody.id },
totalPositionCurrentUse = await this.posMasterRepository.count({ });
where: { if (!NodeId) {
orgRootId: requestBody.id, throw new HttpError(
current_holderId: Not(IsNull()) && Not(""), HttpStatusCode.NOT_FOUND,
}, "ไม่พบข้อมูลตามไอดีนี้ : " + requestBody.id,
}); );
totalPositionCurrentVacant = await this.posMasterRepository.count({ }
where: { totalPosition = await this.posMasterRepository.count({
orgRootId: requestBody.id, where: { orgChild1Id: requestBody.id },
current_holderId: IsNull() && "", });
}, totalPositionCurrentUse = await this.posMasterRepository.count({
}); where: {
totalPositionNextUse = await this.posMasterRepository.count({ orgChild1Id: requestBody.id,
where: { current_holderId: Not(IsNull()) && Not(""),
orgRootId: requestBody.id, },
next_holderId: Not(IsNull()) && Not(""), });
}, totalPositionCurrentVacant = await this.posMasterRepository.count({
}); where: {
totalPositionNextVacant = await this.posMasterRepository.count({ orgChild1Id: requestBody.id,
where: { current_holderId: IsNull() && "",
orgRootId: requestBody.id, },
next_holderId: IsNull() && "", });
}, totalPositionNextUse = await this.posMasterRepository.count({
}); where: {
break; orgChild1Id: requestBody.id,
} next_holderId: Not(IsNull()) && Not(""),
case 1: { },
const NodeId = await this.posMasterRepository.findOne({ });
where: { orgChild1Id: requestBody.id }, totalPositionNextVacant = await this.posMasterRepository.count({
}); where: {
if (!NodeId) { orgChild1Id: requestBody.id,
throw new HttpError( next_holderId: IsNull() && "",
HttpStatusCode.NOT_FOUND, },
"ไม่พบข้อมูลตามไอดีนี้ : " + requestBody.id, });
); break;
} }
totalPosition = await this.posMasterRepository.count({ case 2: {
where: { orgChild1Id: requestBody.id }, const NodeId = await this.posMasterRepository.findOne({
}); where: { orgChild2Id: requestBody.id },
totalPositionCurrentUse = await this.posMasterRepository.count({ });
where: { if (!NodeId) {
orgChild1Id: requestBody.id, throw new HttpError(
current_holderId: Not(IsNull()) && Not(""), HttpStatusCode.NOT_FOUND,
}, "ไม่พบข้อมูลตามไอดีนี้ : " + requestBody.id,
}); );
totalPositionCurrentVacant = await this.posMasterRepository.count({ }
where: { totalPosition = await this.posMasterRepository.count({
orgChild1Id: requestBody.id, where: { orgChild2Id: requestBody.id },
current_holderId: IsNull() && "", });
}, totalPositionCurrentUse = await this.posMasterRepository.count({
}); where: {
totalPositionNextUse = await this.posMasterRepository.count({ orgChild2Id: requestBody.id,
where: { current_holderId: Not(IsNull()) && Not(""),
orgChild1Id: requestBody.id, },
next_holderId: Not(IsNull()) && Not(""), });
}, totalPositionCurrentVacant = await this.posMasterRepository.count({
}); where: {
totalPositionNextVacant = await this.posMasterRepository.count({ orgChild2Id: requestBody.id,
where: { current_holderId: IsNull() && "",
orgChild1Id: requestBody.id, },
next_holderId: IsNull() && "", });
}, totalPositionNextUse = await this.posMasterRepository.count({
}); where: {
break; orgChild2Id: requestBody.id,
} next_holderId: Not(IsNull()) && Not(""),
case 2: { },
const NodeId = await this.posMasterRepository.findOne({ });
where: { orgChild2Id: requestBody.id }, totalPositionNextVacant = await this.posMasterRepository.count({
}); where: {
if (!NodeId) { orgChild2Id: requestBody.id,
throw new HttpError( next_holderId: IsNull() && "",
HttpStatusCode.NOT_FOUND, },
"ไม่พบข้อมูลตามไอดีนี้ : " + requestBody.id, });
); break;
} }
totalPosition = await this.posMasterRepository.count({ case 3: {
where: { orgChild2Id: requestBody.id }, const NodeId = await this.posMasterRepository.findOne({
}); where: { orgChild3Id: requestBody.id },
totalPositionCurrentUse = await this.posMasterRepository.count({ });
where: { if (!NodeId) {
orgChild2Id: requestBody.id, throw new HttpError(
current_holderId: Not(IsNull()) && Not(""), HttpStatusCode.NOT_FOUND,
}, "ไม่พบข้อมูลตามไอดีนี้ : " + requestBody.id,
}); );
totalPositionCurrentVacant = await this.posMasterRepository.count({ }
where: { totalPosition = await this.posMasterRepository.count({
orgChild2Id: requestBody.id, where: { orgChild3Id: requestBody.id },
current_holderId: IsNull() && "", });
}, totalPositionCurrentUse = await this.posMasterRepository.count({
}); where: {
totalPositionNextUse = await this.posMasterRepository.count({ orgChild3Id: requestBody.id,
where: { current_holderId: Not(IsNull()) && Not(""),
orgChild2Id: requestBody.id, },
next_holderId: Not(IsNull()) && Not(""), });
}, totalPositionCurrentVacant = await this.posMasterRepository.count({
}); where: {
totalPositionNextVacant = await this.posMasterRepository.count({ orgChild3Id: requestBody.id,
where: { current_holderId: IsNull() && "",
orgChild2Id: requestBody.id, },
next_holderId: IsNull() && "", });
}, totalPositionNextUse = await this.posMasterRepository.count({
}); where: {
break; orgChild3Id: requestBody.id,
} next_holderId: Not(IsNull()) && Not(""),
case 3: { },
const NodeId = await this.posMasterRepository.findOne({ });
where: { orgChild3Id: requestBody.id }, totalPositionNextVacant = await this.posMasterRepository.count({
}); where: {
if (!NodeId) { orgChild3Id: requestBody.id,
throw new HttpError( next_holderId: IsNull() && "",
HttpStatusCode.NOT_FOUND, },
"ไม่พบข้อมูลตามไอดีนี้ : " + requestBody.id, });
); break;
} }
totalPosition = await this.posMasterRepository.count({ case 4: {
where: { orgChild3Id: requestBody.id }, const NodeId = await this.posMasterRepository.findOne({
}); where: { orgChild4Id: requestBody.id },
totalPositionCurrentUse = await this.posMasterRepository.count({ });
where: { if (!NodeId) {
orgChild3Id: requestBody.id, throw new HttpError(
current_holderId: Not(IsNull()) && Not(""), HttpStatusCode.NOT_FOUND,
}, "ไม่พบข้อมูลตามไอดีนี้ : " + requestBody.id,
}); );
totalPositionCurrentVacant = await this.posMasterRepository.count({ }
where: { totalPosition = await this.posMasterRepository.count({
orgChild3Id: requestBody.id, where: { orgChild4Id: requestBody.id },
current_holderId: IsNull() && "", });
}, totalPositionCurrentUse = await this.posMasterRepository.count({
}); where: {
totalPositionNextUse = await this.posMasterRepository.count({ orgChild4Id: requestBody.id,
where: { current_holderId: Not(IsNull()) && Not(""),
orgChild3Id: requestBody.id, },
next_holderId: Not(IsNull()) && Not(""), });
}, totalPositionCurrentVacant = await this.posMasterRepository.count({
}); where: {
totalPositionNextVacant = await this.posMasterRepository.count({ orgChild4Id: requestBody.id,
where: { current_holderId: IsNull() && "",
orgChild3Id: requestBody.id, },
next_holderId: IsNull() && "", });
}, totalPositionNextUse = await this.posMasterRepository.count({
}); where: {
break; orgChild4Id: requestBody.id,
} next_holderId: Not(IsNull()) && Not(""),
case 4: { },
const NodeId = await this.posMasterRepository.findOne({ });
where: { orgChild4Id: requestBody.id }, totalPositionNextVacant = await this.posMasterRepository.count({
}); where: {
if (!NodeId) { orgChild4Id: requestBody.id,
throw new HttpError( next_holderId: IsNull() && "",
HttpStatusCode.NOT_FOUND, },
"ไม่พบข้อมูลตามไอดีนี้ : " + requestBody.id, });
); break;
} }
totalPosition = await this.posMasterRepository.count({ default:
where: { orgChild4Id: requestBody.id }, break;
}); }
totalPositionCurrentUse = await this.posMasterRepository.count({ }
where: { else {
orgChild4Id: requestBody.id, switch (requestBody.type) {
current_holderId: Not(IsNull()) && Not(""), case 0: {
}, const NodeId = await this.posMasterRepository.findOne({
}); where: { orgRootId: requestBody.id },
totalPositionCurrentVacant = await this.posMasterRepository.count({ });
where: { if (!NodeId) {
orgChild4Id: requestBody.id, throw new HttpError(
current_holderId: IsNull() && "", HttpStatusCode.NOT_FOUND,
}, "ไม่พบข้อมูลตามไอดีนี้ : " + requestBody.id,
}); );
totalPositionNextUse = await this.posMasterRepository.count({ }
where: { totalPosition = await this.posMasterRepository.count({
orgChild4Id: requestBody.id, where: {
next_holderId: Not(IsNull()) && Not(""), orgRootId: requestBody.id,
}, orgChild1Id : IsNull() || "",
}); orgChild2Id : IsNull() || "",
totalPositionNextVacant = await this.posMasterRepository.count({ orgChild3Id : IsNull() || "",
where: { orgChild4Id : IsNull() || "",
orgChild4Id: requestBody.id, },
next_holderId: IsNull() && "", });
}, totalPositionCurrentUse = await this.posMasterRepository.count({
}); where: {
break; orgRootId: requestBody.id,
orgChild1Id : IsNull() || "",
orgChild2Id : IsNull() || "",
orgChild3Id : IsNull() || "",
orgChild4Id : IsNull() || "",
current_holderId: Not(IsNull()) || Not(""),
},
});
totalPositionCurrentVacant = await this.posMasterRepository.count({
where: {
orgRootId: requestBody.id,
orgChild1Id : IsNull() || "",
orgChild2Id : IsNull() || "",
orgChild3Id : IsNull() || "",
orgChild4Id : IsNull() || "",
current_holderId: IsNull() || "",
},
});
totalPositionNextUse = await this.posMasterRepository.count({
where: {
orgRootId: requestBody.id,
orgChild1Id : IsNull() || "",
orgChild2Id : IsNull() || "",
orgChild3Id : IsNull() || "",
orgChild4Id : IsNull() || "",
next_holderId: Not(IsNull()) || Not(""),
},
});
totalPositionNextVacant = await this.posMasterRepository.count({
where: {
orgRootId: requestBody.id,
orgChild1Id : IsNull() || "",
orgChild2Id : IsNull() || "",
orgChild3Id : IsNull() || "",
orgChild4Id : IsNull() || "",
next_holderId: IsNull() || "",
},
});
break;
}
case 1: {
const NodeId = await this.posMasterRepository.findOne({
where: { orgChild1Id: requestBody.id },
});
if (!NodeId) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลตามไอดีนี้ : " + requestBody.id,
);
}
totalPosition = await this.posMasterRepository.count({
where: {
orgRootId: Not(IsNull()) || Not(""),
orgChild1Id : requestBody.id,
orgChild2Id : IsNull() || "",
orgChild3Id : IsNull() || "",
orgChild4Id : IsNull() || "",
},
});
totalPositionCurrentUse = await this.posMasterRepository.count({
where: {
orgRootId: Not(IsNull()) || Not(""),
orgChild1Id : requestBody.id,
orgChild2Id : IsNull() || "",
orgChild3Id : IsNull() || "",
orgChild4Id : IsNull() || "",
current_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionCurrentVacant = await this.posMasterRepository.count({
where: {
orgRootId: Not(IsNull()) || Not(""),
orgChild1Id : requestBody.id,
orgChild2Id : IsNull() || "",
orgChild3Id : IsNull() || "",
orgChild4Id : IsNull() || "",
current_holderId: IsNull() && "",
},
});
totalPositionNextUse = await this.posMasterRepository.count({
where: {
orgRootId: Not(IsNull()) || Not(""),
orgChild1Id : requestBody.id,
orgChild2Id : IsNull() || "",
orgChild3Id : IsNull() || "",
orgChild4Id : IsNull() || "",
next_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionNextVacant = await this.posMasterRepository.count({
where: {
orgRootId: Not(IsNull()) || Not(""),
orgChild1Id : requestBody.id,
orgChild2Id : IsNull() || "",
orgChild3Id : IsNull() || "",
orgChild4Id : IsNull() || "",
next_holderId: IsNull() && "",
},
});
break;
}
case 2: {
const NodeId = await this.posMasterRepository.findOne({
where: { orgChild2Id: requestBody.id },
});
if (!NodeId) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลตามไอดีนี้ : " + requestBody.id,
);
}
totalPosition = await this.posMasterRepository.count({
where: {
orgRootId: Not(IsNull()) || Not(""),
orgChild1Id : Not(IsNull()) || Not(""),
orgChild2Id : requestBody.id,
orgChild3Id : IsNull() || "",
orgChild4Id : IsNull() || "",
},
});
totalPositionCurrentUse = await this.posMasterRepository.count({
where: {
orgRootId: Not(IsNull()) || Not(""),
orgChild1Id : Not(IsNull()) || Not(""),
orgChild2Id : requestBody.id,
orgChild3Id : IsNull() || "",
orgChild4Id : IsNull() || "",
current_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionCurrentVacant = await this.posMasterRepository.count({
where: {
orgRootId: Not(IsNull()) || Not(""),
orgChild1Id : Not(IsNull()) || Not(""),
orgChild2Id : requestBody.id,
orgChild3Id : IsNull() || "",
orgChild4Id : IsNull() || "",
current_holderId: IsNull() && "",
},
});
totalPositionNextUse = await this.posMasterRepository.count({
where: {
orgRootId: Not(IsNull()) || Not(""),
orgChild1Id : Not(IsNull()) || Not(""),
orgChild2Id : requestBody.id,
orgChild3Id : IsNull() || "",
orgChild4Id : IsNull() || "",
next_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionNextVacant = await this.posMasterRepository.count({
where: {
orgRootId: Not(IsNull()) || Not(""),
orgChild1Id : Not(IsNull()) || Not(""),
orgChild2Id : requestBody.id,
orgChild3Id : IsNull() || "",
orgChild4Id : IsNull() || "",
next_holderId: IsNull() && "",
},
});
break;
}
case 3: {
const NodeId = await this.posMasterRepository.findOne({
where: { orgChild3Id: requestBody.id },
});
if (!NodeId) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลตามไอดีนี้ : " + requestBody.id,
);
}
totalPosition = await this.posMasterRepository.count({
where: {
orgRootId: Not(IsNull()) || Not(""),
orgChild1Id : Not(IsNull()) || Not(""),
orgChild2Id : Not(IsNull()) || Not(""),
orgChild3Id : requestBody.id,
orgChild4Id : IsNull() || "",
},
});
totalPositionCurrentUse = await this.posMasterRepository.count({
where: {
orgRootId: Not(IsNull()) || Not(""),
orgChild1Id : Not(IsNull()) || Not(""),
orgChild2Id : Not(IsNull()) || Not(""),
orgChild3Id : requestBody.id,
orgChild4Id : IsNull() || "",
current_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionCurrentVacant = await this.posMasterRepository.count({
where: {
orgRootId: Not(IsNull()) || Not(""),
orgChild1Id : Not(IsNull()) || Not(""),
orgChild2Id : Not(IsNull()) || Not(""),
orgChild3Id : requestBody.id,
orgChild4Id : IsNull() || "",
current_holderId: IsNull() && "",
},
});
totalPositionNextUse = await this.posMasterRepository.count({
where: {
orgRootId: Not(IsNull()) || Not(""),
orgChild1Id : Not(IsNull()) || Not(""),
orgChild2Id : Not(IsNull()) || Not(""),
orgChild3Id : requestBody.id,
orgChild4Id : IsNull() || "",
next_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionNextVacant = await this.posMasterRepository.count({
where: {
orgRootId: Not(IsNull()) || Not(""),
orgChild1Id : Not(IsNull()) || Not(""),
orgChild2Id : Not(IsNull()) || Not(""),
orgChild3Id : requestBody.id,
orgChild4Id : IsNull() || "",
next_holderId: IsNull() && "",
},
});
break;
}
case 4: {
const NodeId = await this.posMasterRepository.findOne({
where: { orgChild4Id: requestBody.id },
});
if (!NodeId) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลตามไอดีนี้ : " + requestBody.id,
);
}
totalPosition = await this.posMasterRepository.count({
where: {
orgRootId: Not(IsNull()) || Not(""),
orgChild1Id : Not(IsNull()) || Not(""),
orgChild2Id : Not(IsNull()) || Not(""),
orgChild3Id : Not(IsNull()) || Not(""),
orgChild4Id : requestBody.id,
},
});
totalPositionCurrentUse = await this.posMasterRepository.count({
where: {
orgRootId: Not(IsNull()) || Not(""),
orgChild1Id : Not(IsNull()) || Not(""),
orgChild2Id : Not(IsNull()) || Not(""),
orgChild3Id : Not(IsNull()) || Not(""),
orgChild4Id : requestBody.id,
current_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionCurrentVacant = await this.posMasterRepository.count({
where: {
orgRootId: Not(IsNull()) || Not(""),
orgChild1Id : Not(IsNull()) || Not(""),
orgChild2Id : Not(IsNull()) || Not(""),
orgChild3Id : Not(IsNull()) || Not(""),
orgChild4Id : requestBody.id,
current_holderId: IsNull() && "",
},
});
totalPositionNextUse = await this.posMasterRepository.count({
where: {
orgRootId: Not(IsNull()) || Not(""),
orgChild1Id : Not(IsNull()) || Not(""),
orgChild2Id : Not(IsNull()) || Not(""),
orgChild3Id : Not(IsNull()) || Not(""),
orgChild4Id : requestBody.id,
next_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionNextVacant = await this.posMasterRepository.count({
where: {
orgRootId: Not(IsNull()) || Not(""),
orgChild1Id : Not(IsNull()) || Not(""),
orgChild2Id : Not(IsNull()) || Not(""),
orgChild3Id : Not(IsNull()) || Not(""),
orgChild4Id : requestBody.id,
next_holderId: IsNull() && "",
},
});
break;
}
default:
break;
} }
default:
break;
} }
summary = { summary = {