ปรับโครงสร้าง root
This commit is contained in:
parent
9de005c7ae
commit
7f21756928
5 changed files with 143 additions and 60 deletions
|
|
@ -34,10 +34,10 @@ import { EmployeePosition } from "../entities/EmployeePosition";
|
|||
@Security("bearerAuth")
|
||||
export class OrgRootController extends Controller {
|
||||
private orgRootRepository = AppDataSource.getRepository(OrgRoot);
|
||||
private orgChild1Repository = AppDataSource.getRepository(OrgChild1);
|
||||
private orgChild2Repository = AppDataSource.getRepository(OrgChild2);
|
||||
private orgChild3Repository = AppDataSource.getRepository(OrgChild3);
|
||||
private orgChild4Repository = AppDataSource.getRepository(OrgChild4);
|
||||
private child1Repository = AppDataSource.getRepository(OrgChild1);
|
||||
private child2Repository = AppDataSource.getRepository(OrgChild2);
|
||||
private child3Repository = AppDataSource.getRepository(OrgChild3);
|
||||
private child4Repository = AppDataSource.getRepository(OrgChild4);
|
||||
private orgRevisionRepository = AppDataSource.getRepository(OrgRevision);
|
||||
private posMasterRepository = AppDataSource.getRepository(PosMaster);
|
||||
private positionRepository = AppDataSource.getRepository(Position);
|
||||
|
|
@ -228,7 +228,7 @@ export class OrgRootController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงสร้างระดับ Root นี้");
|
||||
}
|
||||
|
||||
// const chkCodeChild1 = await this.orgChild1Repository.findOne({
|
||||
// const chkCodeChild1 = await this.child1Repository.findOne({
|
||||
// where:{
|
||||
// orgRevisionId : requestBody.orgRevisionId,
|
||||
// orgRootId: id,
|
||||
|
|
@ -238,7 +238,7 @@ export class OrgRootController extends Controller {
|
|||
// if(chkCodeChild1 != null){
|
||||
// throw new HttpError(HttpStatusCode.NOT_FOUND, "รหัสหน่วยงานนี้ซ้ำกับรหัสส่วนราชการ");
|
||||
// }
|
||||
// const chkShortChild1 = await this.orgChild1Repository.findOne({
|
||||
// const chkShortChild1 = await this.child1Repository.findOne({
|
||||
// where:{
|
||||
// orgRevisionId : requestBody.orgRevisionId,
|
||||
// orgRootId: id,
|
||||
|
|
@ -255,6 +255,62 @@ export class OrgRootController extends Controller {
|
|||
this.orgRootRepository.merge(orgRoot, requestBody);
|
||||
await this.orgRootRepository.save(orgRoot);
|
||||
|
||||
if (orgRoot.orgRootRankSub == "DISTRICT") {
|
||||
const up_Child1 = await this.child1Repository.find({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: id,
|
||||
},
|
||||
});
|
||||
if (up_Child1.length > 0) {
|
||||
for (const _child1 of up_Child1) {
|
||||
_child1.orgChild1ShortName = String(requestBody.orgRootShortName);
|
||||
_child1.orgChild1Code = String(requestBody.orgRootCode);
|
||||
}
|
||||
await this.child1Repository.save(up_Child1);
|
||||
}
|
||||
const up_Child2 = await this.child2Repository.find({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: id,
|
||||
},
|
||||
});
|
||||
if (up_Child2.length > 0) {
|
||||
for (const _child2 of up_Child2) {
|
||||
_child2.orgChild2ShortName = String(requestBody.orgRootShortName);
|
||||
_child2.orgChild2Code = String(requestBody.orgRootCode);
|
||||
}
|
||||
await this.child2Repository.save(up_Child2);
|
||||
}
|
||||
|
||||
const up_Child3 = await this.child3Repository.find({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: id,
|
||||
},
|
||||
});
|
||||
if (up_Child3.length > 0) {
|
||||
for (const _child3 of up_Child3) {
|
||||
_child3.orgChild3ShortName = String(requestBody.orgRootShortName);
|
||||
_child3.orgChild3Code = String(requestBody.orgRootCode);
|
||||
}
|
||||
await this.child3Repository.save(up_Child3);
|
||||
}
|
||||
|
||||
const up_Child4 = await this.child4Repository.find({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: id,
|
||||
},
|
||||
});
|
||||
if (up_Child4.length > 0) {
|
||||
for (const _child4 of up_Child4) {
|
||||
_child4.orgChild4ShortName = String(requestBody.orgRootShortName);
|
||||
_child4.orgChild4Code = String(requestBody.orgRootCode);
|
||||
}
|
||||
await this.child4Repository.save(up_Child4);
|
||||
}
|
||||
}
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
@ -272,7 +328,7 @@ export class OrgRootController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงสร้างระดับ Root นี้");
|
||||
}
|
||||
|
||||
// const orgChild1 = await this.orgChild1Repository.findOne({ where: { orgRootId: id } });
|
||||
// const orgChild1 = await this.child1Repository.findOne({ where: { orgRootId: id } });
|
||||
// if (orgChild1 != null) {
|
||||
// throw new HttpError(
|
||||
// HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||
|
|
@ -312,10 +368,10 @@ export class OrgRootController extends Controller {
|
|||
await this.empPosMasterRepository.remove(empPosMasters);
|
||||
await this.positionRepository.remove(positions);
|
||||
await this.posMasterRepository.remove(posMasters);
|
||||
await this.orgChild4Repository.delete({ orgRootId: id });
|
||||
await this.orgChild3Repository.delete({ orgRootId: id });
|
||||
await this.orgChild2Repository.delete({ orgRootId: id });
|
||||
await this.orgChild1Repository.delete({ orgRootId: id });
|
||||
await this.child4Repository.delete({ orgRootId: id });
|
||||
await this.child3Repository.delete({ orgRootId: id });
|
||||
await this.child2Repository.delete({ orgRootId: id });
|
||||
await this.child1Repository.delete({ orgRootId: id });
|
||||
await this.orgRootRepository.delete({ id });
|
||||
|
||||
return new HttpSuccess();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue