orgTreeOrder เพิ่มหน่วยงาน
This commit is contained in:
parent
145e64b655
commit
019ded1aa3
5 changed files with 35 additions and 0 deletions
|
|
@ -130,6 +130,12 @@ export class OrgChild1Controller {
|
||||||
if (chkCode != null) {
|
if (chkCode != null) {
|
||||||
throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, "รหัสหน่วยงานนี้มีอยู่ในระบบแล้ว");
|
throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, "รหัสหน่วยงานนี้มีอยู่ในระบบแล้ว");
|
||||||
}
|
}
|
||||||
|
const order:any = await this.child1Repository.findOne({
|
||||||
|
where: {
|
||||||
|
orgRootId: requestBody.orgRootId
|
||||||
|
},
|
||||||
|
order: { orgChild1Order: "DESC" }
|
||||||
|
})
|
||||||
try {
|
try {
|
||||||
const child1 = Object.assign(new OrgChild1(), requestBody) as OrgChild1;
|
const child1 = Object.assign(new OrgChild1(), requestBody) as OrgChild1;
|
||||||
child1.orgChild1Name = requestBody.orgChild1Name;
|
child1.orgChild1Name = requestBody.orgChild1Name;
|
||||||
|
|
@ -139,6 +145,7 @@ export class OrgChild1Controller {
|
||||||
child1.lastUpdateFullName = request.user.name;
|
child1.lastUpdateFullName = request.user.name;
|
||||||
child1.orgRevisionId = String(rootIdExits?.orgRevisionId);
|
child1.orgRevisionId = String(rootIdExits?.orgRevisionId);
|
||||||
child1.orgRootId = String(rootIdExits?.id);
|
child1.orgRootId = String(rootIdExits?.id);
|
||||||
|
child1.orgChild1Order = order.orgChild1Order == null ? 1 : order.orgChild1Order+1;
|
||||||
await this.child1Repository.save(child1);
|
await this.child1Repository.save(child1);
|
||||||
return new HttpSuccess();
|
return new HttpSuccess();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
||||||
|
|
@ -136,6 +136,12 @@ export class OrgChild2Controller extends Controller {
|
||||||
if (!validOrgChild2Ranks.includes(requestBody.orgChild2Rank.toUpperCase())) {
|
if (!validOrgChild2Ranks.includes(requestBody.orgChild2Rank.toUpperCase())) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgChild2Rank");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgChild2Rank");
|
||||||
}
|
}
|
||||||
|
const order:any = await this.child2Repository.findOne({
|
||||||
|
where: {
|
||||||
|
orgChild1Id: requestBody.orgChild1Id
|
||||||
|
},
|
||||||
|
order: { orgChild2Order: "DESC" }
|
||||||
|
})
|
||||||
try {
|
try {
|
||||||
const child2 = Object.assign(new OrgChild2(), requestBody) as OrgChild2;
|
const child2 = Object.assign(new OrgChild2(), requestBody) as OrgChild2;
|
||||||
child2.orgChild2Name = requestBody.orgChild2Name;
|
child2.orgChild2Name = requestBody.orgChild2Name;
|
||||||
|
|
@ -146,6 +152,7 @@ export class OrgChild2Controller extends Controller {
|
||||||
child2.orgRootId = String(child1?.orgRootId);
|
child2.orgRootId = String(child1?.orgRootId);
|
||||||
child2.orgRevisionId = String(child1?.orgRevisionId);
|
child2.orgRevisionId = String(child1?.orgRevisionId);
|
||||||
child2.orgChild1Id = String(child1?.id);
|
child2.orgChild1Id = String(child1?.id);
|
||||||
|
child2.orgChild2Order = order.orgChild2Order == null ? 1 : order.orgChild2Order+1;
|
||||||
await this.child2Repository.save(child2);
|
await this.child2Repository.save(child2);
|
||||||
return new HttpSuccess();
|
return new HttpSuccess();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
||||||
|
|
@ -118,6 +118,12 @@ export class OrgChild3Controller {
|
||||||
if (!validOrgChild3Ranks.includes(requestBody.orgChild3Rank.toUpperCase())) {
|
if (!validOrgChild3Ranks.includes(requestBody.orgChild3Rank.toUpperCase())) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgChild3Rank");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgChild3Rank");
|
||||||
}
|
}
|
||||||
|
const order:any = await this.child3Repository.findOne({
|
||||||
|
where: {
|
||||||
|
orgChild2Id: requestBody.orgChild2Id
|
||||||
|
},
|
||||||
|
order: { orgChild3Order: "DESC" }
|
||||||
|
})
|
||||||
try {
|
try {
|
||||||
const child3 = Object.assign(new OrgChild3(), requestBody) as OrgChild3;
|
const child3 = Object.assign(new OrgChild3(), requestBody) as OrgChild3;
|
||||||
child3.orgChild3Name = requestBody.orgChild3Name;
|
child3.orgChild3Name = requestBody.orgChild3Name;
|
||||||
|
|
@ -129,6 +135,7 @@ export class OrgChild3Controller {
|
||||||
child3.orgChild1Id = String(child2?.orgChild1Id);
|
child3.orgChild1Id = String(child2?.orgChild1Id);
|
||||||
child3.orgRevisionId = String(child2?.orgRevisionId);
|
child3.orgRevisionId = String(child2?.orgRevisionId);
|
||||||
child3.orgChild2Id = String(child2?.id);
|
child3.orgChild2Id = String(child2?.id);
|
||||||
|
child3.orgChild3Order = order.orgChild3Order == null ? 1 : order.orgChild3Order+1;
|
||||||
await this.child3Repository.save(child3);
|
await this.child3Repository.save(child3);
|
||||||
return new HttpSuccess();
|
return new HttpSuccess();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
||||||
|
|
@ -134,6 +134,12 @@ export class OrgChild4Controller extends Controller {
|
||||||
if (!validOrgChild4Ranks.includes(requestBody.orgChild4Rank.toUpperCase())) {
|
if (!validOrgChild4Ranks.includes(requestBody.orgChild4Rank.toUpperCase())) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgChild4Rank");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgChild4Rank");
|
||||||
}
|
}
|
||||||
|
const order:any = await this.child4Repository.findOne({
|
||||||
|
where: {
|
||||||
|
orgChild3Id: requestBody.orgChild3Id
|
||||||
|
},
|
||||||
|
order: { orgChild4Order: "DESC" }
|
||||||
|
})
|
||||||
try {
|
try {
|
||||||
const child4 = Object.assign(new OrgChild4(), requestBody) as OrgChild4;
|
const child4 = Object.assign(new OrgChild4(), requestBody) as OrgChild4;
|
||||||
child4.orgChild4Name = requestBody.orgChild4Name;
|
child4.orgChild4Name = requestBody.orgChild4Name;
|
||||||
|
|
@ -146,6 +152,7 @@ export class OrgChild4Controller extends Controller {
|
||||||
child4.orgChild2Id = String(child3?.orgChild2Id);
|
child4.orgChild2Id = String(child3?.orgChild2Id);
|
||||||
child4.orgRevisionId = String(child3?.orgRevisionId);
|
child4.orgRevisionId = String(child3?.orgRevisionId);
|
||||||
child4.orgChild3Id = String(child3?.id);
|
child4.orgChild3Id = String(child3?.id);
|
||||||
|
child4.orgChild4Order = order.orgChild4Order == null ? 1 : order.orgChild4Order+1;
|
||||||
await this.child4Repository.save(child4);
|
await this.child4Repository.save(child4);
|
||||||
|
|
||||||
return new HttpSuccess();
|
return new HttpSuccess();
|
||||||
|
|
|
||||||
|
|
@ -128,11 +128,18 @@ export class OrgRootController extends Controller {
|
||||||
"not found. orgRevisionIsDraft:true, orgRevisionIsCurrent:false",
|
"not found. orgRevisionIsDraft:true, orgRevisionIsCurrent:false",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
const order:any = await this.orgRootRepository.findOne({
|
||||||
|
where: {
|
||||||
|
orgRevisionId: requestBody.orgRevisionId
|
||||||
|
},
|
||||||
|
order: { orgRootOrder: "DESC" }
|
||||||
|
})
|
||||||
try {
|
try {
|
||||||
orgRoot.createdUserId = request.user.sub;
|
orgRoot.createdUserId = request.user.sub;
|
||||||
orgRoot.createdFullName = request.user.name;
|
orgRoot.createdFullName = request.user.name;
|
||||||
orgRoot.lastUpdateUserId = request.user.sub;
|
orgRoot.lastUpdateUserId = request.user.sub;
|
||||||
orgRoot.lastUpdateFullName = request.user.name;
|
orgRoot.lastUpdateFullName = request.user.name;
|
||||||
|
orgRoot.orgRootOrder = order.orgRootOrder == null ? 1 : order.orgRootOrder+1;
|
||||||
await this.orgRootRepository.save(orgRoot);
|
await this.orgRootRepository.save(orgRoot);
|
||||||
|
|
||||||
return new HttpSuccess();
|
return new HttpSuccess();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue