From 766888d01ca6d7fc0a8ec73a6e41d05d920d3531 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Tue, 15 Oct 2024 16:54:18 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88=E0=B8=A1?= =?UTF-8?q?=E0=B9=80=E0=B8=87=E0=B8=B7=E0=B9=88=E0=B8=AD=E0=B8=99=E0=B9=84?= =?UTF-8?q?=E0=B8=82=E0=B8=81=E0=B8=B2=E0=B8=A3=E0=B8=AA=E0=B8=A3=E0=B9=89?= =?UTF-8?q?=E0=B8=B2=E0=B8=87=E0=B9=81=E0=B8=9A=E0=B8=9A=E0=B8=A3=E0=B9=88?= =?UTF-8?q?=E0=B8=B2=E0=B8=87=E0=B9=82=E0=B8=84=E0=B8=A3=E0=B8=87=E0=B8=AA?= =?UTF-8?q?=E0=B8=A3=E0=B9=89=E0=B8=B2=E0=B8=87=20#1024?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/OrganizationController.ts | 110 +++++++++++++++++++--- 1 file changed, 95 insertions(+), 15 deletions(-) diff --git a/src/controllers/OrganizationController.ts b/src/controllers/OrganizationController.ts index 0d7ffbbc..37339837 100644 --- a/src/controllers/OrganizationController.ts +++ b/src/controllers/OrganizationController.ts @@ -33,6 +33,7 @@ import permission from "../interfaces/permission"; import { PermissionOrg } from "../entities/PermissionOrg"; import FunctionMain from "../interfaces/functionMain"; import { setLogDataDiff } from "../interfaces/utils"; +import { AuthRole } from "../entities/AuthRole"; @Route("api/v1/org") @Tags("Organization") @@ -54,6 +55,7 @@ export class OrganizationController extends Controller { private positionRepository = AppDataSource.getRepository(Position); private salaryRepository = AppDataSource.getRepository(ProfileSalary); private profileRepo = AppDataSource.getRepository(Profile); + private authRoleRepo = AppDataSource.getRepository(AuthRole); /** * API รายการประวัติโครงสร้าง @@ -114,7 +116,7 @@ export class OrganizationController extends Controller { } /** - * API สร้างโครงสร้างระดับ4 + * API สร้างแบบร่างโครงสร้าง * * @summary ORG_022 - สร้างโครงสร้างใหม่ #23 * @@ -124,6 +126,7 @@ export class OrganizationController extends Controller { @Body() requestBody: CreateOrgRevision, @Request() request: RequestWithUser, ) { + console.log("fucntion draft"); //new main revision const before = null; const revision = Object.assign(new OrgRevision(), requestBody) as OrgRevision; @@ -141,7 +144,9 @@ export class OrganizationController extends Controller { if ( requestBody.typeDraft.toUpperCase() == "ORG" || requestBody.typeDraft.toUpperCase() == "ORG_POSITION" || - requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" + requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" || + requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" || + requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE" ) { //cone by revisionId if (requestBody.orgRevisionId == null) @@ -217,10 +222,13 @@ export class OrganizationController extends Controller { where: { orgRevisionId: requestBody.orgRevisionId }, relations: ["positions"], }); + let _orgPosMaster: PosMaster[]; if ( requestBody.typeDraft.toUpperCase() == "ORG_POSITION" || - requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" + requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" || + requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" || + requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE" ) { _orgPosMaster = orgPosMaster.map((x) => ({ ...x, @@ -246,7 +254,9 @@ export class OrganizationController extends Controller { await this.orgRootRepository.save(data); if ( requestBody.typeDraft.toUpperCase() == "ORG_POSITION" || - requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" + requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" || + requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" || + requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE" ) { //create posmaster await Promise.all( @@ -256,12 +266,23 @@ export class OrganizationController extends Controller { delete item.id; const posMaster = Object.assign(new PosMaster(), item); posMaster.positions = []; - if (requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON") { + if ( + requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" || + requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE" + ) { posMaster.next_holderId = item.current_holderId; } else { posMaster.next_holderId = null; posMaster.isSit = false; } + if ( + requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" || + requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE" + ) { + posMaster.authRoleId = item.authRoleId; + } else { + posMaster.authRoleId = null; + } posMaster.current_holderId = null; posMaster.orgRevisionId = revision.id; posMaster.orgRootId = data.id; @@ -278,7 +299,10 @@ export class OrganizationController extends Controller { delete pos.id; const position = Object.assign(new Position(), pos); position.posMasterId = posMaster.id; - if (requestBody.typeDraft.toUpperCase() == "ORG_POSITION") { + if ( + requestBody.typeDraft.toUpperCase() == "ORG_POSITION" || + requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" + ) { position.positionIsSelected = false; } position.createdUserId = request.user.sub; @@ -321,12 +345,23 @@ export class OrganizationController extends Controller { delete item.id; const posMaster = Object.assign(new PosMaster(), item); posMaster.positions = []; - if (requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON") { + if ( + requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" || + requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE" + ) { posMaster.next_holderId = item.current_holderId; } else { posMaster.next_holderId = null; posMaster.isSit = false; } + if ( + requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" || + requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE" + ) { + posMaster.authRoleId = item.authRoleId; + } else { + posMaster.authRoleId = null; + } posMaster.current_holderId = null; posMaster.orgRevisionId = revision.id; posMaster.orgRootId = data.id; @@ -344,7 +379,10 @@ export class OrganizationController extends Controller { delete pos.id; const position = Object.assign(new Position(), pos); position.posMasterId = posMaster.id; - if (requestBody.typeDraft.toUpperCase() == "ORG_POSITION") { + if ( + requestBody.typeDraft.toUpperCase() == "ORG_POSITION" || + requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" + ) { position.positionIsSelected = false; } position.createdUserId = request.user.sub; @@ -388,12 +426,23 @@ export class OrganizationController extends Controller { delete item.id; const posMaster = Object.assign(new PosMaster(), item); posMaster.positions = []; - if (requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON") { + if ( + requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" || + requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE" + ) { posMaster.next_holderId = item.current_holderId; } else { posMaster.next_holderId = null; posMaster.isSit = false; } + if ( + requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" || + requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE" + ) { + posMaster.authRoleId = item.authRoleId; + } else { + posMaster.authRoleId = null; + } posMaster.current_holderId = null; posMaster.orgRevisionId = revision.id; posMaster.orgRootId = data.id; @@ -412,7 +461,10 @@ export class OrganizationController extends Controller { delete pos.id; const position = Object.assign(new Position(), pos); position.posMasterId = posMaster.id; - if (requestBody.typeDraft.toUpperCase() == "ORG_POSITION") { + if ( + requestBody.typeDraft.toUpperCase() == "ORG_POSITION" || + requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" + ) { position.positionIsSelected = false; } position.createdUserId = request.user.sub; @@ -459,12 +511,23 @@ export class OrganizationController extends Controller { delete item.id; const posMaster = Object.assign(new PosMaster(), item); posMaster.positions = []; - if (requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON") { + if ( + requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" || + requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE" + ) { posMaster.next_holderId = item.current_holderId; } else { posMaster.next_holderId = null; posMaster.isSit = false; } + if ( + requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" || + requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE" + ) { + posMaster.authRoleId = item.authRoleId; + } else { + posMaster.authRoleId = null; + } posMaster.current_holderId = null; posMaster.orgRevisionId = revision.id; posMaster.orgRootId = data.id; @@ -484,7 +547,10 @@ export class OrganizationController extends Controller { delete pos.id; const position = Object.assign(new Position(), pos); position.posMasterId = posMaster.id; - if (requestBody.typeDraft.toUpperCase() == "ORG_POSITION") { + if ( + requestBody.typeDraft.toUpperCase() == "ORG_POSITION" || + requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" + ) { position.positionIsSelected = false; } position.createdUserId = request.user.sub; @@ -529,12 +595,23 @@ export class OrganizationController extends Controller { delete item.id; const posMaster = Object.assign(new PosMaster(), item); posMaster.positions = []; - if (requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON") { + if ( + requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" || + requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE" + ) { posMaster.next_holderId = item.current_holderId; } else { posMaster.next_holderId = null; posMaster.isSit = false; } + if ( + requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" || + requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE" + ) { + posMaster.authRoleId = item.authRoleId; + } else { + posMaster.authRoleId = null; + } posMaster.current_holderId = null; posMaster.orgRevisionId = revision.id; posMaster.orgRootId = data.id; @@ -555,7 +632,10 @@ export class OrganizationController extends Controller { delete pos.id; const position = Object.assign(new Position(), pos); position.posMasterId = posMaster.id; - if (requestBody.typeDraft.toUpperCase() == "ORG_POSITION") { + if ( + requestBody.typeDraft.toUpperCase() == "ORG_POSITION" || + requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" + ) { position.positionIsSelected = false; } position.createdUserId = request.user.sub; @@ -575,7 +655,7 @@ export class OrganizationController extends Controller { }); }); } - + const _orgRevisions = await this.orgRevisionRepository.find({ where: [{ orgRevisionIsDraft: true, id: Not(revision.id) }], });