This commit is contained in:
AdisakKanthawilang 2024-03-18 17:53:31 +07:00
parent 42fd0084aa
commit 46e7495655
5 changed files with 65 additions and 5 deletions

View file

@ -26,6 +26,8 @@ import { OrgChild3 } from "../entities/OrgChild3";
import { OrgChild4 } from "../entities/OrgChild4";
import { PosMaster } from "../entities/PosMaster";
import { Position } from "../entities/Position";
import { EmployeePosMaster } from "../entities/EmployeePosMaster";
import { EmployeePosition } from "../entities/EmployeePosition";
@Route("api/v1/org/root")
@Tags("OrgRoot")
@ -39,6 +41,8 @@ export class OrgRootController extends Controller {
private orgRevisionRepository = AppDataSource.getRepository(OrgRevision);
private posMasterRepository = AppDataSource.getRepository(PosMaster);
private positionRepository = AppDataSource.getRepository(Position);
private empPosMasterRepository = AppDataSource.getRepository(EmployeePosMaster);
private empPositionRepository = AppDataSource.getRepository(EmployeePosition);
/**
* API Root
@ -250,7 +254,15 @@ export class OrgRootController extends Controller {
const positions = await this.positionRepository.find({
where: [{ posMasterId: In(posMasters.map((x) => x.id)) }],
});
const empPosMasters = await this.empPosMasterRepository.find({
where: { orgRootId: id },
});
const empPositions = await this.empPositionRepository.find({
where: [{ posMasterId: In(empPosMasters.map((x) => x.id)) }],
});
await this.empPositionRepository.remove(empPositions);
await this.empPosMasterRepository.remove(empPosMasters);
await this.positionRepository.remove(positions);
await this.posMasterRepository.remove(posMasters);
await this.orgChild4Repository.delete({ orgRootId: id });