Merge branch 'adiDev' into develop
This commit is contained in:
commit
f7eab59cef
1 changed files with 32 additions and 8 deletions
|
|
@ -17,9 +17,15 @@ import { CreateOrgRoot, OrgRoot } from "../entities/OrgRoot";
|
||||||
import { AppDataSource } from "../database/data-source";
|
import { AppDataSource } from "../database/data-source";
|
||||||
import HttpSuccess from "../interfaces/http-success";
|
import HttpSuccess from "../interfaces/http-success";
|
||||||
import { CreateOrgChild1, OrgChild1 } from "../entities/OrgChild1";
|
import { CreateOrgChild1, OrgChild1 } from "../entities/OrgChild1";
|
||||||
|
import { In, IsNull, Not } from "typeorm";
|
||||||
import HttpError from "../interfaces/http-error";
|
import HttpError from "../interfaces/http-error";
|
||||||
import HttpStatusCode from "../interfaces/http-status";
|
import HttpStatusCode from "../interfaces/http-status";
|
||||||
import { OrgRevision } from "../entities/OrgRevision";
|
import { OrgRevision } from "../entities/OrgRevision";
|
||||||
|
import { OrgChild2 } from "../entities/OrgChild2";
|
||||||
|
import { OrgChild3 } from "../entities/OrgChild3";
|
||||||
|
import { OrgChild4 } from "../entities/OrgChild4";
|
||||||
|
import { PosMaster } from "../entities/PosMaster";
|
||||||
|
import { Position } from "../entities/Position";
|
||||||
|
|
||||||
@Route("api/v1/org/root")
|
@Route("api/v1/org/root")
|
||||||
@Tags("OrgRoot")
|
@Tags("OrgRoot")
|
||||||
|
|
@ -27,7 +33,12 @@ import { OrgRevision } from "../entities/OrgRevision";
|
||||||
export class OrgRootController extends Controller {
|
export class OrgRootController extends Controller {
|
||||||
private orgRootRepository = AppDataSource.getRepository(OrgRoot);
|
private orgRootRepository = AppDataSource.getRepository(OrgRoot);
|
||||||
private orgChild1Repository = AppDataSource.getRepository(OrgChild1);
|
private orgChild1Repository = AppDataSource.getRepository(OrgChild1);
|
||||||
|
private orgChild2Repository = AppDataSource.getRepository(OrgChild2);
|
||||||
|
private orgChild3Repository = AppDataSource.getRepository(OrgChild3);
|
||||||
|
private orgChild4Repository = AppDataSource.getRepository(OrgChild4);
|
||||||
private orgRevisionRepository = AppDataSource.getRepository(OrgRevision);
|
private orgRevisionRepository = AppDataSource.getRepository(OrgRevision);
|
||||||
|
private posMasterRepository = AppDataSource.getRepository(PosMaster);
|
||||||
|
private positionRepository = AppDataSource.getRepository(Position);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API รายละเอียดโครงสร้างระดับ Root
|
* API รายละเอียดโครงสร้างระดับ Root
|
||||||
|
|
@ -220,13 +231,13 @@ export class OrgRootController extends Controller {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const orgChild1 = await this.orgChild1Repository.findOne({ where: { orgRootId: id } });
|
// const orgChild1 = await this.orgChild1Repository.findOne({ where: { orgRootId: id } });
|
||||||
if (orgChild1 != null) {
|
// if (orgChild1 != null) {
|
||||||
throw new HttpError(
|
// throw new HttpError(
|
||||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
// HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||||
"ไม่สามารถลบข้อมูลได้เมื่อมีข้อมูลโครงสร้างระดับ1",
|
// "ไม่สามารถลบข้อมูลได้เมื่อมีข้อมูลโครงสร้างระดับ1",
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
|
|
||||||
const revisionIdExits = await this.orgRevisionRepository.findOne({
|
const revisionIdExits = await this.orgRevisionRepository.findOne({
|
||||||
where: { id: orgRoot.orgRevisionId },
|
where: { id: orgRoot.orgRevisionId },
|
||||||
|
|
@ -244,7 +255,20 @@ export class OrgRootController extends Controller {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await this.orgRootRepository.remove(orgRoot);
|
const posMasters = await this.posMasterRepository.find({
|
||||||
|
where: { orgRootId: id}
|
||||||
|
});
|
||||||
|
const positions = await this.positionRepository.find({
|
||||||
|
where: [{ posMasterId: In(posMasters.map((x) => x.id)) }],
|
||||||
|
});
|
||||||
|
|
||||||
|
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.orgRootRepository.delete({id});
|
||||||
|
|
||||||
return new HttpSuccess();
|
return new HttpSuccess();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue