เพิ่มselect detail tree

This commit is contained in:
Kittapath 2024-01-31 18:24:38 +07:00
parent 35ba5b91f3
commit cd21c42710
7 changed files with 175 additions and 147 deletions

View file

@ -48,17 +48,18 @@ export class OrgChild2Controller extends Controller {
*/
@Get("{id}")
async GetChild2(@Path() id: string) {
const orgChild2 = await this.child2Repository.findOne({ where: { id } });
const orgChild2 = await this.child2Repository.findOne({
where: { id },
relations: ["orgRoot", "orgChild1"],
});
if (!orgChild2) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล โครงสร้างระดับ 2");
}
const orgRoot = await this.orgRootRepository.findOne({ where: { id: orgChild2.orgRootId } });
if (!orgRoot) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล โครงสร้างระดับ Root");
}
try {
const getOrgChild2 = {
orgChild2Id: orgChild2.id,
orgRootName: orgChild2.orgRoot.orgRootName,
orgName: `${orgChild2.orgChild2Name}/${orgChild2.orgChild1.orgChild1Name}/${orgChild2.orgRoot.orgRootName}`,
orgChild2Name: orgChild2.orgChild2Name,
orgChild2ShortName: orgChild2.orgChild2ShortName,
orgChild2Code: orgChild2.orgChild2Code,
@ -68,7 +69,7 @@ export class OrgChild2Controller extends Controller {
orgChild2PhoneIn: orgChild2.orgChild2PhoneIn,
orgChild2Fax: orgChild2.orgChild2Fax,
orgRevisionId: orgChild2.orgRevisionId,
orgCode: orgRoot.orgRootCode + orgChild2.orgChild2Code,
orgCode: orgChild2.orgRoot.orgRootCode + orgChild2.orgChild2Code,
};
return new HttpSuccess(getOrgChild2);
} catch (error) {