แก้ไข api สร้างโครงสร้าง
This commit is contained in:
parent
a1226bfbfc
commit
49c468f53d
2 changed files with 281 additions and 127 deletions
|
|
@ -57,18 +57,18 @@ export class OrgChild1Controller {
|
|||
}
|
||||
try {
|
||||
const getOrgChild1 = {
|
||||
"orgChild1Id" : orgChild1.id,
|
||||
"orgChild1Name" : orgChild1.orgChild1Name,
|
||||
"orgChild1ShortName" : orgChild1.orgChild1ShortName,
|
||||
"orgChild1Code" : orgChild1.orgChild1Code,
|
||||
"orgChild1Rank" : orgChild1.orgChild1Rank,
|
||||
"orgChild1Order" : orgChild1.orgChild1Order,
|
||||
"orgChild1PhoneEx" : orgChild1.orgChild1PhoneEx,
|
||||
"orgChild1PhoneIn" : orgChild1.orgChild1PhoneIn,
|
||||
"orgChild1Fax" : orgChild1.orgChild1Fax,
|
||||
"orgRevisionId" : orgChild1.orgRevisionId,
|
||||
"orgCode" : orgRoot.orgRootCode + orgChild1.orgChild1Code
|
||||
}
|
||||
orgChild1Id: orgChild1.id,
|
||||
orgChild1Name: orgChild1.orgChild1Name,
|
||||
orgChild1ShortName: orgChild1.orgChild1ShortName,
|
||||
orgChild1Code: orgChild1.orgChild1Code,
|
||||
orgChild1Rank: orgChild1.orgChild1Rank,
|
||||
orgChild1Order: orgChild1.orgChild1Order,
|
||||
orgChild1PhoneEx: orgChild1.orgChild1PhoneEx,
|
||||
orgChild1PhoneIn: orgChild1.orgChild1PhoneIn,
|
||||
orgChild1Fax: orgChild1.orgChild1Fax,
|
||||
orgRevisionId: orgChild1.orgRevisionId,
|
||||
orgCode: orgRoot.orgRootCode + orgChild1.orgChild1Code,
|
||||
};
|
||||
return new HttpSuccess(getOrgChild1);
|
||||
} catch (error) {
|
||||
return error;
|
||||
|
|
@ -85,8 +85,7 @@ export class OrgChild1Controller {
|
|||
async save(
|
||||
@Body() requestBody: CreateOrgChild1,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
){
|
||||
|
||||
) {
|
||||
const rootIdExits = await this.orgRootRepository.findOne({
|
||||
where: { id: requestBody.orgRootId },
|
||||
});
|
||||
|
|
@ -94,13 +93,19 @@ export class OrgChild1Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgRootId");
|
||||
}
|
||||
const revisionIdExits = await this.orgRevisionRepository.findOne({
|
||||
where: { id: rootIdExits.orgRevisionId }
|
||||
where: { id: rootIdExits.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");
|
||||
if (
|
||||
revisionIdExits.orgRevisionIsDraft != true &&
|
||||
revisionIdExits.orgRevisionIsCurrent != false
|
||||
) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"not found. orgRevisionIsDraft:true, orgRevisionIsCurrent:false",
|
||||
);
|
||||
}
|
||||
|
||||
const validOrgChild1Ranks = ["OFFICE", "DIVISION", "SECTION"];
|
||||
|
|
@ -109,13 +114,14 @@ export class OrgChild1Controller {
|
|||
}
|
||||
|
||||
const chkCode = await this.child1Repository.findOne({
|
||||
where: { orgRootId: requestBody.orgRootId, orgChild1Code: requestBody.orgChild1Code },
|
||||
where: {
|
||||
orgRevisionId: rootIdExits.orgRevisionId,
|
||||
orgRootId: requestBody.orgRootId,
|
||||
orgChild1Code: requestBody.orgChild1Code,
|
||||
},
|
||||
});
|
||||
if (chkCode != null) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||
"รหัสหน่วยงานนี้มีอยู่ในระบบแล้ว",
|
||||
);
|
||||
throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, "รหัสหน่วยงานนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
try {
|
||||
const child1 = Object.assign(new OrgChild1(), requestBody) as OrgChild1;
|
||||
|
|
@ -158,8 +164,14 @@ export class OrgChild1Controller {
|
|||
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 validOrgChild1Ranks = ["OFFICE", "DIVISION", "SECTION"];
|
||||
|
|
@ -177,6 +189,7 @@ export class OrgChild1Controller {
|
|||
const chkCode = await this.child1Repository.findOne({
|
||||
where: {
|
||||
id: Not(id),
|
||||
orgRevisionId: rootIdExits.orgRevisionId,
|
||||
orgRootId: requestBody.orgRootId,
|
||||
orgChild1Code: requestBody.orgChild1Code,
|
||||
},
|
||||
|
|
@ -217,8 +230,14 @@ export class OrgChild1Controller {
|
|||
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 exitsChild2 = await this.child2Repository.findOne({ where: { orgChild1Id: id } });
|
||||
if (exitsChild2) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue