From 46e7495655ff46f7120dea85d0945bb0aa06c30e Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Mon, 18 Mar 2024 17:53:31 +0700 Subject: [PATCH] fix del --- src/controllers/OrgChild1Controller.ts | 14 +++++++++++++- src/controllers/OrgChild2Controller.ts | 14 +++++++++++++- src/controllers/OrgChild3Controller.ts | 14 +++++++++++++- src/controllers/OrgChild4Controller.ts | 14 +++++++++++++- src/controllers/OrgRootController.ts | 14 +++++++++++++- 5 files changed, 65 insertions(+), 5 deletions(-) diff --git a/src/controllers/OrgChild1Controller.ts b/src/controllers/OrgChild1Controller.ts index 68667999..8c02118b 100644 --- a/src/controllers/OrgChild1Controller.ts +++ b/src/controllers/OrgChild1Controller.ts @@ -26,6 +26,8 @@ import { In, Not } from "typeorm"; 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/child1") @Tags("OrgChild1") @Security("bearerAuth") @@ -43,6 +45,8 @@ export class OrgChild1Controller { private posMasterRepository = AppDataSource.getRepository(PosMaster); private positionRepository = AppDataSource.getRepository(Position); private orgRevisionRepository = AppDataSource.getRepository(OrgRevision); + private empPosMasterRepository = AppDataSource.getRepository(EmployeePosMaster); + private empPositionRepository = AppDataSource.getRepository(EmployeePosition); /** * API รายละเอียดโครงสร้างระดับ 1 @@ -259,7 +263,15 @@ export class OrgChild1Controller { 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.child4Repository.delete({ orgChild1Id: id }); diff --git a/src/controllers/OrgChild2Controller.ts b/src/controllers/OrgChild2Controller.ts index ddaf0e99..5a734cde 100644 --- a/src/controllers/OrgChild2Controller.ts +++ b/src/controllers/OrgChild2Controller.ts @@ -28,6 +28,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/child2") @Tags("OrgChild2") @Security("bearerAuth") @@ -45,6 +47,8 @@ export class OrgChild2Controller extends Controller { private posMasterRepository = AppDataSource.getRepository(PosMaster); private positionRepository = AppDataSource.getRepository(Position); private orgRevisionRepository = AppDataSource.getRepository(OrgRevision); + private empPosMasterRepository = AppDataSource.getRepository(EmployeePosMaster); + private empPositionRepository = AppDataSource.getRepository(EmployeePosition); /** * API รายละเอียดโครงสร้างระดับ 2 @@ -270,7 +274,15 @@ export class OrgChild2Controller 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.child4Repository.delete({ orgChild2Id: id }); diff --git a/src/controllers/OrgChild3Controller.ts b/src/controllers/OrgChild3Controller.ts index e7e29903..1f29d8c7 100644 --- a/src/controllers/OrgChild3Controller.ts +++ b/src/controllers/OrgChild3Controller.ts @@ -25,6 +25,8 @@ import HttpError from "../interfaces/http-error"; import { In } from "typeorm"; import { PosMaster } from "../entities/PosMaster"; import { Position } from "../entities/Position"; +import { EmployeePosMaster } from "../entities/EmployeePosMaster"; +import { EmployeePosition } from "../entities/EmployeePosition"; @Route("api/v1/org/child3") @Tags("OrgChild3") @Security("bearerAuth") @@ -41,6 +43,8 @@ export class OrgChild3Controller { private posMasterRepository = AppDataSource.getRepository(PosMaster); private positionRepository = AppDataSource.getRepository(Position); private orgRevisionRepository = AppDataSource.getRepository(OrgRevision); + private empPosMasterRepository = AppDataSource.getRepository(EmployeePosMaster); + private empPositionRepository = AppDataSource.getRepository(EmployeePosition); /** * API รายละเอียดโครงสร้างระดับ 3 @@ -240,7 +244,15 @@ export class OrgChild3Controller { 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.child4Repository.delete({ orgChild3Id: id }); diff --git a/src/controllers/OrgChild4Controller.ts b/src/controllers/OrgChild4Controller.ts index bc3d1579..430f8dd0 100644 --- a/src/controllers/OrgChild4Controller.ts +++ b/src/controllers/OrgChild4Controller.ts @@ -27,6 +27,8 @@ import { OrgChild1 } from "../entities/OrgChild1"; import { OrgChild3 } from "../entities/OrgChild3"; import { PosMaster } from "../entities/PosMaster"; import { Position } from "../entities/Position"; +import { EmployeePosMaster } from "../entities/EmployeePosMaster"; +import { EmployeePosition } from "../entities/EmployeePosition"; @Route("api/v1/org/child4") @Tags("OrgChild4") @@ -43,6 +45,8 @@ export class OrgChild4Controller extends Controller { private posMasterRepository = AppDataSource.getRepository(PosMaster); private positionRepository = AppDataSource.getRepository(Position); private orgRevisionRepository = AppDataSource.getRepository(OrgRevision); + private empPosMasterRepository = AppDataSource.getRepository(EmployeePosMaster); + private empPositionRepository = AppDataSource.getRepository(EmployeePosition); /** * API รายละเอียดโครงสร้างระดับ 4 @@ -265,7 +269,15 @@ export class OrgChild4Controller 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.child4Repository.delete(id); diff --git a/src/controllers/OrgRootController.ts b/src/controllers/OrgRootController.ts index b82e2cac..228d838b 100644 --- a/src/controllers/OrgRootController.ts +++ b/src/controllers/OrgRootController.ts @@ -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 });