แก้apiแสดงข้อมูลtree
This commit is contained in:
parent
49c468f53d
commit
9166faf102
6 changed files with 486 additions and 144 deletions
|
|
@ -39,42 +39,42 @@ export class OrgChild4Controller extends Controller {
|
|||
private child4Repository = AppDataSource.getRepository(OrgChild4);
|
||||
private orgRevisionRepository = AppDataSource.getRepository(OrgRevision);
|
||||
|
||||
/**
|
||||
/**
|
||||
* API รายละเอียดโครงสร้างระดับ 4
|
||||
*
|
||||
* @summary ORG_019 - รายละเอียดโครงสร้างระดับ4 (ADMIN) #26
|
||||
*
|
||||
* @param {string} id Id Child4
|
||||
*/
|
||||
@Get("{id}")
|
||||
async GetChild4(@Path() id: string) {
|
||||
const orgChild4 = await this.child4Repository.findOne({ where: { id } });
|
||||
if (!orgChild4) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล โครงสร้างระดับ 4");
|
||||
}
|
||||
const orgRoot = await this.orgRootRepository.findOne({ where: { id: orgChild4.orgRootId } });
|
||||
if (!orgRoot) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล โครงสร้างระดับ Root");
|
||||
}
|
||||
try {
|
||||
const getOrgChild4 = {
|
||||
"orgChild4Id" : orgChild4.id,
|
||||
"orgChild4Name" : orgChild4.orgChild4Name,
|
||||
"orgChild4ShortName" : orgChild4.orgChild4ShortName,
|
||||
"orgChild4Code" : orgChild4.orgChild4Code,
|
||||
"orgChild4Rank" : orgChild4.orgChild4Rank,
|
||||
"orgChild4Order" : orgChild4.orgChild4Order,
|
||||
"orgChild4PhoneEx" : orgChild4.orgChild4PhoneEx,
|
||||
"orgChild4PhoneIn" : orgChild4.orgChild4PhoneIn,
|
||||
"orgChild4Fax" : orgChild4.orgChild4Fax,
|
||||
"orgRevisionId" : orgChild4.orgRevisionId,
|
||||
"orgCode" : orgRoot.orgRootCode + orgChild4.orgChild4Code
|
||||
}
|
||||
return new HttpSuccess(getOrgChild4);
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
@Get("{id}")
|
||||
async GetChild4(@Path() id: string) {
|
||||
const orgChild4 = await this.child4Repository.findOne({ where: { id } });
|
||||
if (!orgChild4) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล โครงสร้างระดับ 4");
|
||||
}
|
||||
const orgRoot = await this.orgRootRepository.findOne({ where: { id: orgChild4.orgRootId } });
|
||||
if (!orgRoot) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล โครงสร้างระดับ Root");
|
||||
}
|
||||
try {
|
||||
const getOrgChild4 = {
|
||||
orgChild4Id: orgChild4.id,
|
||||
orgChild4Name: orgChild4.orgChild4Name,
|
||||
orgChild4ShortName: orgChild4.orgChild4ShortName,
|
||||
orgChild4Code: orgChild4.orgChild4Code,
|
||||
orgChild4Rank: orgChild4.orgChild4Rank,
|
||||
orgChild4Order: orgChild4.orgChild4Order,
|
||||
orgChild4PhoneEx: orgChild4.orgChild4PhoneEx,
|
||||
orgChild4PhoneIn: orgChild4.orgChild4PhoneIn,
|
||||
orgChild4Fax: orgChild4.orgChild4Fax,
|
||||
orgRevisionId: orgChild4.orgRevisionId,
|
||||
orgCode: orgRoot.orgRootCode + orgChild4.orgChild4Code,
|
||||
};
|
||||
return new HttpSuccess(getOrgChild4);
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* สร้างโครงสร้างระดับ4 Child4
|
||||
|
|
@ -101,27 +101,33 @@ export class OrgChild4Controller extends Controller {
|
|||
requestBody: CreateOrgChild4,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
const child3 = await this.child3Repository.findOne({
|
||||
where: { id: requestBody.orgChild3Id },
|
||||
});
|
||||
if (!child3) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
|
||||
}
|
||||
|
||||
const revisionIdExits = await this.orgRevisionRepository.findOne({
|
||||
where: { id: child3.orgRevisionId },
|
||||
});
|
||||
if (!revisionIdExits) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. RevisionId");
|
||||
}
|
||||
if(revisionIdExits.orgRevisionIsDraft != true && revisionIdExits.orgRevisionIsCurrent != false){
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgRevisionIsDraft:true, orgRevisionIsCurrent:false");
|
||||
}
|
||||
const child3 = await this.child3Repository.findOne({
|
||||
where: { id: requestBody.orgChild3Id },
|
||||
});
|
||||
if (!child3) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
|
||||
}
|
||||
|
||||
const validOrgChild4Ranks = ["OFFICE", "DIVISION", "SECTION"];
|
||||
if (!validOrgChild4Ranks.includes(requestBody.orgChild4Rank.toUpperCase())) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgChild4Rank");
|
||||
}
|
||||
const revisionIdExits = await this.orgRevisionRepository.findOne({
|
||||
where: { id: child3.orgRevisionId },
|
||||
});
|
||||
if (!revisionIdExits) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. RevisionId");
|
||||
}
|
||||
if (
|
||||
revisionIdExits.orgRevisionIsDraft != true &&
|
||||
revisionIdExits.orgRevisionIsCurrent != false
|
||||
) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"not found. orgRevisionIsDraft:true, orgRevisionIsCurrent:false",
|
||||
);
|
||||
}
|
||||
|
||||
const validOrgChild4Ranks = ["OFFICE", "DIVISION", "SECTION"];
|
||||
if (!validOrgChild4Ranks.includes(requestBody.orgChild4Rank.toUpperCase())) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgChild4Rank");
|
||||
}
|
||||
try {
|
||||
const child4 = Object.assign(new OrgChild4(), requestBody) as OrgChild4;
|
||||
child4.orgChild4Name = requestBody.orgChild4Name;
|
||||
|
|
@ -182,8 +188,14 @@ export class OrgChild4Controller extends Controller {
|
|||
if (!revisionIdExits) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. RevisionId");
|
||||
}
|
||||
if(revisionIdExits.orgRevisionIsDraft != true && revisionIdExits.orgRevisionIsCurrent != false){
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgRevisionIsDraft:true, orgRevisionIsCurrent:false");
|
||||
if (
|
||||
revisionIdExits.orgRevisionIsDraft != true &&
|
||||
revisionIdExits.orgRevisionIsCurrent != false
|
||||
) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"not found. orgRevisionIsDraft:true, orgRevisionIsCurrent:false",
|
||||
);
|
||||
}
|
||||
|
||||
const validOrgChild4Ranks = ["OFFICE", "DIVISION", "SECTION"];
|
||||
|
|
@ -235,8 +247,14 @@ export class OrgChild4Controller extends Controller {
|
|||
if (!revisionIdExits) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. RevisionId");
|
||||
}
|
||||
if(revisionIdExits.orgRevisionIsDraft != true && revisionIdExits.orgRevisionIsCurrent != false){
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgRevisionIsDraft:true, orgRevisionIsCurrent:false");
|
||||
if (
|
||||
revisionIdExits.orgRevisionIsDraft != true &&
|
||||
revisionIdExits.orgRevisionIsCurrent != false
|
||||
) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"not found. orgRevisionIsDraft:true, orgRevisionIsCurrent:false",
|
||||
);
|
||||
}
|
||||
try {
|
||||
await this.child4Repository.remove(child4);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue