แก้ฟิลด์ orgCode

This commit is contained in:
Bright 2024-01-29 14:55:13 +07:00
parent 5a7e5cfa0e
commit e82b4f6a85
5 changed files with 31 additions and 9 deletions

View file

@ -1,5 +1,6 @@
import { AppDataSource } from "../database/data-source";
import { OrgRevision } from "../entities/OrgRevision";
import { OrgRoot } from "../entities/OrgRoot";
import { OrgChild2 } from "../entities/OrgChild2";
import { OrgChild3, CreateOrgChild3, UpdateOrgChild3 } from "../entities/OrgChild3";
import { OrgChild4 } from "../entities/OrgChild4";
@ -30,6 +31,7 @@ import HttpError from "../interfaces/http-error";
)
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
export class OrgChild3Controller {
private orgRootRepository = AppDataSource.getRepository(OrgRoot);
private child2Repository = AppDataSource.getRepository(OrgChild2);
private child3Repository = AppDataSource.getRepository(OrgChild3);
private child4Repository = AppDataSource.getRepository(OrgChild4);
@ -47,7 +49,11 @@ export class OrgChild3Controller {
try {
const orgChild3 = await this.child3Repository.findOne({ where: { id } });
if (!orgChild3) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล โครงสร้างระดับ 3");
}
const orgRoot = await this.orgRootRepository.findOne({ where: { id: orgChild3.orgRootId } });
if (!orgRoot) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล โครงสร้างระดับ Root");
}
const getOrgChild3 = {
"orgChild3Id" : orgChild3.id,
@ -59,7 +65,7 @@ export class OrgChild3Controller {
"orgChild3PhoneIn" : orgChild3.orgChild3PhoneIn,
"orgChild3Fax" : orgChild3.orgChild3Fax,
"orgRevisionId" : orgChild3.orgRevisionId,
"orgCode" : orgChild3.orgChild3Code+"00"
"orgCode" : orgRoot.orgRootCode + orgChild3.orgChild3Code
}
return new HttpSuccess(getOrgChild3);
} catch (error) {