Merge branch 'adiDev' into develop

This commit is contained in:
AdisakKanthawilang 2024-02-06 14:04:23 +07:00
commit f7eab59cef

View file

@ -17,9 +17,15 @@ import { CreateOrgRoot, OrgRoot } from "../entities/OrgRoot";
import { AppDataSource } from "../database/data-source";
import HttpSuccess from "../interfaces/http-success";
import { CreateOrgChild1, OrgChild1 } from "../entities/OrgChild1";
import { In, IsNull, Not } from "typeorm";
import HttpError from "../interfaces/http-error";
import HttpStatusCode from "../interfaces/http-status";
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")
@Tags("OrgRoot")
@ -27,7 +33,12 @@ import { OrgRevision } from "../entities/OrgRevision";
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 orgRevisionRepository = AppDataSource.getRepository(OrgRevision);
private posMasterRepository = AppDataSource.getRepository(PosMaster);
private positionRepository = AppDataSource.getRepository(Position);
/**
* API Root
@ -220,13 +231,13 @@ export class OrgRootController extends Controller {
);
}
const orgChild1 = await this.orgChild1Repository.findOne({ where: { orgRootId: id } });
if (orgChild1 != null) {
throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"ไม่สามารถลบข้อมูลได้เมื่อมีข้อมูลโครงสร้างระดับ1",
);
}
// const orgChild1 = await this.orgChild1Repository.findOne({ where: { orgRootId: id } });
// if (orgChild1 != null) {
// throw new HttpError(
// HttpStatusCode.INTERNAL_SERVER_ERROR,
// "ไม่สามารถลบข้อมูลได้เมื่อมีข้อมูลโครงสร้างระดับ1",
// );
// }
const revisionIdExits = await this.orgRevisionRepository.findOne({
where: { id: orgRoot.orgRevisionId },
@ -244,7 +255,20 @@ export class OrgRootController extends Controller {
);
}
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();
} catch (error) {