From 7f217569282579745dde31010a1b171f24494db8 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Thu, 20 Jun 2024 11:58:51 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=9B=E0=B8=A3=E0=B8=B1=E0=B8=9A=E0=B9=82?= =?UTF-8?q?=E0=B8=84=E0=B8=A3=E0=B8=87=E0=B8=AA=E0=B8=A3=E0=B9=89=E0=B8=B2?= =?UTF-8?q?=E0=B8=87=20root?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/OrgChild1Controller.ts | 91 ++++++++++++----------- src/controllers/OrgRootController.ts | 78 ++++++++++++++++--- src/controllers/OrganizationController.ts | 13 +++- src/controllers/ProfileController.ts | 17 +++++ src/entities/OrgRoot.ts | 4 +- 5 files changed, 143 insertions(+), 60 deletions(-) diff --git a/src/controllers/OrgChild1Controller.ts b/src/controllers/OrgChild1Controller.ts index 982ec5e7..5d8f3241 100644 --- a/src/controllers/OrgChild1Controller.ts +++ b/src/controllers/OrgChild1Controller.ts @@ -122,28 +122,30 @@ export class OrgChild1Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgChild1Rank"); } - const chkCode = await this.child1Repository.findOne({ - where: { - orgRevisionId: rootIdExits.orgRevisionId, - orgRootId: requestBody.orgRootId, - orgChild1Code: requestBody.orgChild1Code, - }, - }); - if (chkCode != null) { - throw new HttpError( - HttpStatusCode.INTERNAL_SERVER_ERROR, - "รหัสส่วนราชการนี้มีอยู่ในระบบแล้ว", - ); - } - const chkShort = await this.child1Repository.findOne({ - where: { - orgRevisionId: rootIdExits.orgRevisionId, - orgRootId: requestBody.orgRootId, - orgChild1ShortName: requestBody.orgChild1ShortName, - }, - }); - if (chkShort != null) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "อักษรย่อนี้มีอยู่ในระบบแล้ว"); + if (rootIdExits.orgRootRankSub != "DISTRICT") { + const chkCode = await this.child1Repository.findOne({ + where: { + orgRevisionId: rootIdExits.orgRevisionId, + orgRootId: requestBody.orgRootId, + orgChild1Code: requestBody.orgChild1Code, + }, + }); + if (chkCode != null) { + throw new HttpError( + HttpStatusCode.INTERNAL_SERVER_ERROR, + "รหัสส่วนราชการนี้มีอยู่ในระบบแล้ว", + ); + } + const chkShort = await this.child1Repository.findOne({ + where: { + orgRevisionId: rootIdExits.orgRevisionId, + orgRootId: requestBody.orgRootId, + orgChild1ShortName: requestBody.orgChild1ShortName, + }, + }); + if (chkShort != null) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "อักษรย่อนี้มีอยู่ในระบบแล้ว"); + } } // if (requestBody.orgChild1Code == rootIdExits.orgRootCode) { @@ -220,27 +222,30 @@ export class OrgChild1Controller { if (!child1) { throw new HttpError(HttpStatusCode.NOT_FOUND, "not found."); } - const chkCode = await this.child1Repository.findOne({ - where: { - id: Not(id), - orgRevisionId: rootIdExits.orgRevisionId, - orgRootId: requestBody.orgRootId, - orgChild1Code: requestBody.orgChild1Code, - }, - }); - if (chkCode != null) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "รหัสส่วนราชการนี้มีอยู่ในระบบแล้ว"); - } - const chkShort = await this.child1Repository.findOne({ - where: { - id: Not(id), - orgRevisionId: rootIdExits.orgRevisionId, - orgRootId: requestBody.orgRootId, - orgChild1ShortName: requestBody.orgChild1ShortName, - }, - }); - if (chkShort != null) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "อักษรย่อนี้มีอยู่ในระบบแล้ว"); + + if (rootIdExits.orgRootRankSub != "DISTRICT") { + const chkCode = await this.child1Repository.findOne({ + where: { + id: Not(id), + orgRevisionId: rootIdExits.orgRevisionId, + orgRootId: requestBody.orgRootId, + orgChild1Code: requestBody.orgChild1Code, + }, + }); + if (chkCode != null) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "รหัสส่วนราชการนี้มีอยู่ในระบบแล้ว"); + } + const chkShort = await this.child1Repository.findOne({ + where: { + id: Not(id), + orgRevisionId: rootIdExits.orgRevisionId, + orgRootId: requestBody.orgRootId, + orgChild1ShortName: requestBody.orgChild1ShortName, + }, + }); + if (chkShort != null) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "อักษรย่อนี้มีอยู่ในระบบแล้ว"); + } } // if(requestBody.orgChild1Code == rootIdExits.orgRootCode){ diff --git a/src/controllers/OrgRootController.ts b/src/controllers/OrgRootController.ts index 6a682ab6..23ad88ec 100644 --- a/src/controllers/OrgRootController.ts +++ b/src/controllers/OrgRootController.ts @@ -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(); diff --git a/src/controllers/OrganizationController.ts b/src/controllers/OrganizationController.ts index 38fd52b0..c05fcad0 100644 --- a/src/controllers/OrganizationController.ts +++ b/src/controllers/OrganizationController.ts @@ -3175,9 +3175,10 @@ export class OrganizationController extends Controller { posMaster: await Promise.all( orgRoot.posMasters .filter( - (x) => x.orgChild1Id != null && x.current_holderId != null && x.posMasterOrder <= 3, + (x) => x.orgChild1Id == null && x.current_holderId != null && x.posMasterOrder <= 3, ) .map(async (x) => ({ + posmasterId: x.id, orgTreeId: orgRoot.id, orgLevel: 0, fullNameCurrentHolder: @@ -3210,11 +3211,12 @@ export class OrganizationController extends Controller { orgChild1.posMasters .filter( (x) => - x.orgChild2Id != null && + x.orgChild2Id == null && x.current_holderId != null && x.posMasterOrder <= 3, ) .map(async (x) => ({ + posmasterId: x.id, orgTreeId: orgChild1.id, orgLevel: 1, fullNameCurrentHolder: @@ -3248,11 +3250,12 @@ export class OrganizationController extends Controller { orgChild2.posMasters .filter( (x) => - x.orgChild3Id != null && + x.orgChild3Id == null && x.current_holderId != null && x.posMasterOrder <= 3, ) .map(async (x) => ({ + posmasterId: x.id, orgTreeId: orgChild2.id, orgLevel: 2, fullNameCurrentHolder: @@ -3286,11 +3289,12 @@ export class OrganizationController extends Controller { orgChild3.posMasters .filter( (x) => - x.orgChild4Id != null && + x.orgChild4Id == null && x.current_holderId != null && x.posMasterOrder <= 3, ) .map(async (x) => ({ + posmasterId: x.id, orgTreeId: orgChild3.id, orgLevel: 3, fullNameCurrentHolder: @@ -3326,6 +3330,7 @@ export class OrganizationController extends Controller { (x) => x.current_holderId != null && x.posMasterOrder <= 3, ) .map(async (x) => ({ + posmasterId: x.id, orgTreeId: orgChild4.id, orgLevel: 4, fullNameCurrentHolder: diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index db9003c0..6cde6f26 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -4466,4 +4466,21 @@ export class ProfileController extends Controller { return new HttpSuccess({ data: mapDataProfile, total }); } + /** + * + * @summary ปรับคนเป็นทดลองงาน (ADMIN) + * + */ + @Get("probation/{id}") + async getProbationProfile(@Path() id: string) { + const profile = await this.profileRepo.findOne({ + where: { id }, + }); + + if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + + profile.isProbation = true; + await this.profileRepo.save(profile); + return new HttpSuccess(profile); + } } diff --git a/src/entities/OrgRoot.ts b/src/entities/OrgRoot.ts index e258735c..9866cdae 100644 --- a/src/entities/OrgRoot.ts +++ b/src/entities/OrgRoot.ts @@ -143,8 +143,8 @@ export class CreateOrgRoot { @Column() orgRootRank: OrgRootRank; - // @Column() - // orgRootRankSub?: string; + @Column() + orgRootRankSub?: string; @Column() orgRootPhoneEx?: string;