แก้ฟิลด์ 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

@ -20,6 +20,7 @@ import HttpStatusCode from "../interfaces/http-status";
import HttpSuccess from "../interfaces/http-success";
import HttpError from "../interfaces/http-error";
import { OrgRevision } from "../entities/OrgRevision";
import { OrgRoot } from "../entities/OrgRoot";
import { CreateOrgChild2, OrgChild2, UpdateOrgChild2 } from "../entities/OrgChild2";
import { OrgChild1 } from "../entities/OrgChild1";
import { OrgChild3 } from "../entities/OrgChild3";
@ -32,6 +33,7 @@ import { OrgChild3 } from "../entities/OrgChild3";
)
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
export class OrgChild2Controller extends Controller {
private orgRootRepository = AppDataSource.getRepository(OrgRoot);
private child1Repository = AppDataSource.getRepository(OrgChild1);
private child2Repository = AppDataSource.getRepository(OrgChild2);
private child3Repository = AppDataSource.getRepository(OrgChild3);
@ -49,7 +51,11 @@ export class OrgChild2Controller extends Controller {
try {
const orgChild2 = await this.child2Repository.findOne({ where: { id } });
if (!orgChild2) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
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");
}
const getOrgChild2 = {
"orgChild2Id" : orgChild2.id,
@ -61,7 +67,7 @@ export class OrgChild2Controller extends Controller {
"orgChild2PhoneIn" : orgChild2.orgChild2PhoneIn,
"orgChild2Fax" : orgChild2.orgChild2Fax,
"orgRevisionId" : orgChild2.orgRevisionId,
"orgCode" : orgChild2.orgChild2Code+"00"
"orgCode" : orgRoot.orgRootCode + orgChild2.orgChild2Code
}
return new HttpSuccess(getOrgChild2);
} catch (error) {