From 31fbfaed3b7ebbacc7b7c08b3034030a013695aa Mon Sep 17 00:00:00 2001 From: kittapath Date: Wed, 20 Nov 2024 16:06:48 +0700 Subject: [PATCH 1/7] no message --- src/controllers/WorkflowController.ts | 88 ++++++++++++++----- ...2085607231-update_workflow_add_employee.ts | 14 +++ ...087058773-update_workflow_add_employee1.ts | 14 +++ 3 files changed, 93 insertions(+), 23 deletions(-) create mode 100644 src/migration/1732085607231-update_workflow_add_employee.ts create mode 100644 src/migration/1732087058773-update_workflow_add_employee1.ts diff --git a/src/controllers/WorkflowController.ts b/src/controllers/WorkflowController.ts index f38b2317..2320c813 100644 --- a/src/controllers/WorkflowController.ts +++ b/src/controllers/WorkflowController.ts @@ -188,7 +188,7 @@ export class WorkflowController extends Controller { let profileNow = _workflow.stateOperatorUsers .filter((x) => _state.stateOperators.map((s) => s.operator).includes(x.operator)) .map((x) => ({ - receiverUserId: x.profileId, + receiverUserId: x.profileType == "OFFICER" ? x.profileId : x.profileEmployeeId, notiLink: "", })); await new CallAPI() @@ -313,7 +313,15 @@ export class WorkflowController extends Controller { system: string; }, ) { - const stateOperatorUser = await this.stateOperatorUserRepo.findOne({ + const workflow = await this.workflowRepo.findOne({ + where: { + refId: body.refId, + sysName: body.system, + }, + }); + if (!workflow) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่สามารถดำเนินการกระบวนการนี้ได้"); + + let stateOperatorUser = await this.stateOperatorUserRepo.findOne({ where: { workflow: { refId: body.refId, @@ -325,13 +333,20 @@ export class WorkflowController extends Controller { }, relations: ["workflow"], }); - const workflow = await this.workflowRepo.findOne({ - where: { - refId: body.refId, - sysName: body.system, - }, - }); - if (!workflow) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่สามารถดำเนินการกระบวนการนี้ได้"); + if (stateOperatorUser) { + stateOperatorUser = await this.stateOperatorUserRepo.findOne({ + where: { + workflow: { + refId: body.refId, + sysName: body.system, + }, + profileEmployee: { + keycloak: req.user.sub, + }, + }, + relations: ["workflow"], + }); + } const operator = await this.stateOperatorRepo.findOne({ where: { operator: stateOperatorUser?.operator || "", @@ -424,7 +439,16 @@ export class WorkflowController extends Controller { system: string; }, ) { - const stateOperatorUserNow = await this.stateOperatorUserRepo.findOne({ + const workflow = await this.workflowRepo.findOne({ + where: { + refId: body.refId, + sysName: body.system, + }, + relations: ["stateOperatorUsers"], + }); + if (!workflow) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่สามารถดำเนินการกระบวนการนี้ได้"); + + let stateOperatorUserNow = await this.stateOperatorUserRepo.findOne({ where: { workflow: { refId: body.refId, @@ -435,7 +459,20 @@ export class WorkflowController extends Controller { }, }, }); - const stateOperatorUser = await this.stateOperatorUserRepo.find({ + if (stateOperatorUserNow == null) { + stateOperatorUserNow = await this.stateOperatorUserRepo.findOne({ + where: { + workflow: { + refId: body.refId, + sysName: body.system, + }, + profileEmployee: { + keycloak: req.user.sub, + }, + }, + }); + } + let stateOperatorUser = await this.stateOperatorUserRepo.find({ where: { workflow: { refId: body.refId, @@ -447,17 +484,22 @@ export class WorkflowController extends Controller { operator: stateOperatorUserNow?.operator || "", }, }); + if (stateOperatorUser == null) { + stateOperatorUser = await this.stateOperatorUserRepo.find({ + where: { + workflow: { + refId: body.refId, + sysName: body.system, + }, + profileEmployee: { + keycloak: Not(req.user.sub), + }, + operator: stateOperatorUserNow?.operator || "", + }, + }); + } await this.stateOperatorUserRepo.remove(stateOperatorUser); - const workflow = await this.workflowRepo.findOne({ - where: { - refId: body.refId, - sysName: body.system, - }, - relations: ["stateOperatorUsers"], - }); - if (!workflow) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่สามารถดำเนินการกระบวนการนี้ได้"); - const state = await this.stateRepo.findOne({ where: { id: workflow.stateId, @@ -476,7 +518,7 @@ export class WorkflowController extends Controller { let profileNow = workflow.stateOperatorUsers .filter((x) => state.stateOperators.map((s) => s.operator).includes(x.operator)) .map((x) => ({ - receiverUserId: x.profileId, + receiverUserId: x.profileType == "OFFICER" ? x.profileId : x.profileEmployeeId, notiLink: "", })); await new CallAPI() @@ -496,7 +538,7 @@ export class WorkflowController extends Controller { let profileNext = workflow.stateOperatorUsers .filter((x) => _state.stateOperators.map((s) => s.operator).includes(x.operator)) .map((x) => ({ - receiverUserId: x.profileId, + receiverUserId: x.profileType == "OFFICER" ? x.profileId : x.profileEmployeeId, notiLink: "", })); await new CallAPI() @@ -656,7 +698,7 @@ export class WorkflowController extends Controller { stateUserComment.state.stateOperators.map((s) => s.operator).includes(x.operator), ) .map((x) => ({ - receiverUserId: x.profileId, + receiverUserId: x.profileType == "OFFICER" ? x.profileId : x.profileEmployeeId, notiLink: "", })); await new CallAPI() diff --git a/src/migration/1732085607231-update_workflow_add_employee.ts b/src/migration/1732085607231-update_workflow_add_employee.ts new file mode 100644 index 00000000..64a54cf7 --- /dev/null +++ b/src/migration/1732085607231-update_workflow_add_employee.ts @@ -0,0 +1,14 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateWorkflowAddEmployee1732085607231 implements MigrationInterface { + name = 'UpdateWorkflowAddEmployee1732085607231' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`workflow\` DROP COLUMN \`profileType\``); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`workflow\` ADD \`profileType\` varchar(255) NULL COMMENT 'ผู้ใช้งาน'`); + } + +} diff --git a/src/migration/1732087058773-update_workflow_add_employee1.ts b/src/migration/1732087058773-update_workflow_add_employee1.ts new file mode 100644 index 00000000..3514b309 --- /dev/null +++ b/src/migration/1732087058773-update_workflow_add_employee1.ts @@ -0,0 +1,14 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateWorkflowAddEmployee11732087058773 implements MigrationInterface { + name = 'UpdateWorkflowAddEmployee11732087058773' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`workflow\` ADD \`profileType\` varchar(255) NULL COMMENT 'ผู้ใช้งาน'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`workflow\` DROP COLUMN \`profileType\``); + } + +} From 9db1ca7492930481cf1bd060fc57daa78c3a3004 Mon Sep 17 00:00:00 2001 From: kittapath Date: Wed, 20 Nov 2024 16:40:00 +0700 Subject: [PATCH 2/7] no message --- src/controllers/UserController.ts | 78 ++++++++++++++++--------------- 1 file changed, 41 insertions(+), 37 deletions(-) diff --git a/src/controllers/UserController.ts b/src/controllers/UserController.ts index 1077fa51..1b9a7435 100644 --- a/src/controllers/UserController.ts +++ b/src/controllers/UserController.ts @@ -436,57 +436,61 @@ export class KeycloakController extends Controller { let condition: any = {}; if (req.user.role.includes("ADMIN")) { - const profile = await this.profileRepo.findOne({ - relations:[ - "current_holders", - "current_holders.orgRevision", - ], - where: { + const profile = await this.profileRepo.findOne({ + relations: ["current_holders", "current_holders.orgRevision"], + where: { keycloak: req.user.sub, - current_holders:{ - orgRevision:{ + current_holders: { + orgRevision: { orgRevisionIsCurrent: true, - orgRevisionIsDraft: false - } - } - } + orgRevisionIsDraft: false, + }, + }, + }, }); - if(profile?.current_holders[0].orgRootId && profile?.current_holders[0].orgChild1Id == null){ - condition = - `current_holders.orgRootId = '${profile?.current_holders[0].orgRootId}' + if ( + profile?.current_holders[0]?.orgRootId && + profile?.current_holders[0]?.orgChild1Id == null + ) { + condition = `current_holders.orgRootId = '${profile?.current_holders[0]?.orgRootId}' and current_holders.orgChild1Id IS NULL and current_holders.orgChild2Id IS NULL and current_holders.orgChild3Id IS NULL and current_holders.orgChild4Id IS NULL`; - }else if(profile?.current_holders[0].orgChild1Id && profile?.current_holders[0].orgChild2Id == null){ - condition = - `current_holders.orgRootId = '${profile?.current_holders[0].orgRootId}' - and current_holders.orgChild1Id '${profile?.current_holders[0].orgChild1Id}' + } else if ( + profile?.current_holders[0]?.orgChild1Id && + profile?.current_holders[0]?.orgChild2Id == null + ) { + condition = `current_holders.orgRootId = '${profile?.current_holders[0]?.orgRootId}' + and current_holders.orgChild1Id = '${profile?.current_holders[0]?.orgChild1Id}' and current_holders.orgChild2Id IS NULL and current_holders.orgChild3Id IS NULL and current_holders.orgChild4Id IS NULL`; - }else if(profile?.current_holders[0].orgChild2Id && profile?.current_holders[0].orgChild3Id == null){ - condition = - `current_holders.orgRootId = '${profile?.current_holders[0].orgRootId}' - and current_holders.orgChild1Id '${profile?.current_holders[0].orgChild1Id}' - and current_holders.orgChild2Id '${profile?.current_holders[0].orgChild2Id}' + } else if ( + profile?.current_holders[0]?.orgChild2Id && + profile?.current_holders[0]?.orgChild3Id == null + ) { + condition = `current_holders.orgRootId = '${profile?.current_holders[0]?.orgRootId}' + and current_holders.orgChild1Id = '${profile?.current_holders[0]?.orgChild1Id}' + and current_holders.orgChild2Id = '${profile?.current_holders[0]?.orgChild2Id}' and current_holders.orgChild3Id IS NULL and current_holders.orgChild4Id IS NULL`; - }else if(profile?.current_holders[0].orgChild3Id && profile?.current_holders[0].orgChild4Id == null){ - condition = - `current_holders.orgRootId = '${profile?.current_holders[0].orgRootId}' - and current_holders.orgChild1Id '${profile?.current_holders[0].orgChild1Id}' - and current_holders.orgChild2Id '${profile?.current_holders[0].orgChild2Id}' - and current_holders.orgChild3Id '${profile?.current_holders[0].orgChild3Id}' + } else if ( + profile?.current_holders[0]?.orgChild3Id && + profile?.current_holders[0]?.orgChild4Id == null + ) { + condition = `current_holders.orgRootId = '${profile?.current_holders[0]?.orgRootId}' + and current_holders.orgChild1Id = '${profile?.current_holders[0]?.orgChild1Id}' + and current_holders.orgChild2Id = '${profile?.current_holders[0]?.orgChild2Id}' + and current_holders.orgChild3Id = '${profile?.current_holders[0]?.orgChild3Id}' and current_holders.orgChild4Id IS NULL`; - }else if(profile?.current_holders[0].orgChild4Id){ - condition = - `current_holders.orgRootId = '${profile?.current_holders[0].orgRootId}' - and current_holders.orgChild1Id '${profile?.current_holders[0].orgChild1Id}' - and current_holders.orgChild2Id '${profile?.current_holders[0].orgChild2Id}' - and current_holders.orgChild3Id '${profile?.current_holders[0].orgChild3Id}' - and current_holders.orgChild4Id '${profile?.current_holders[0].orgChild4Id}'`; + } else if (profile?.current_holders[0]?.orgChild4Id) { + condition = `current_holders.orgRootId = '${profile?.current_holders[0]?.orgRootId}' + and current_holders.orgChild1Id = '${profile?.current_holders[0]?.orgChild1Id}' + and current_holders.orgChild2Id = '${profile?.current_holders[0]?.orgChild2Id}' + and current_holders.orgChild3Id = '${profile?.current_holders[0]?.orgChild3Id}' + and current_holders.orgChild4Id = '${profile?.current_holders[0]?.orgChild4Id}'`; } } let profiles: any = []; From a30821acc346b098c1283a0198a0522b6ee23760 Mon Sep 17 00:00:00 2001 From: Bright Date: Wed, 20 Nov 2024 18:17:17 +0700 Subject: [PATCH 3/7] REPORT 4 --- src/controllers/ReportController.ts | 235 +++++++++++++++++++++++----- 1 file changed, 196 insertions(+), 39 deletions(-) diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index e126509b..4f88c33f 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -13,6 +13,7 @@ import { OrgChild4 } from "../entities/OrgChild4"; import { PosType } from "../entities/PosType"; import { PosLevel } from "../entities/PosLevel"; import { PosMaster } from "../entities/PosMaster"; +import { EmployeePosMaster } from "../entities/EmployeePosMaster"; import Extension from "../interfaces/extension"; import { LeaveType } from "../entities/LeaveType"; import HttpStatus from "../interfaces/http-status"; @@ -33,6 +34,7 @@ export class ReportController extends Controller { private posTypepository = AppDataSource.getRepository(PosType); private posLevelRepository = AppDataSource.getRepository(PosLevel); private posMasterRepository = AppDataSource.getRepository(PosMaster); + private empPosMasterRepository = AppDataSource.getRepository(EmployeePosMaster); /** * API Report1 @@ -6246,7 +6248,6 @@ export class ReportController extends Controller { @Get("report4/{rootId}") async findReport4(@Path() rootId: string) { - const orgRootData = await this.orgRootRepository.findOne({ where: { id: rootId } }); @@ -6262,56 +6263,212 @@ export class ReportController extends Controller { .addOrderBy("posLevel.posLevelRank", "ASC") .getMany(); - const _posMaster = posMaster.map((x) => ({ - type: [...new Set(x.positions.flatMap((y) => y.posType.posTypeName))].join(","), - typeRank: [...new Set(x.positions.flatMap((y) => y.posType.posTypeRank))].join(""), - level: [...new Set(x.positions.flatMap((y) => y.posLevel.posLevelName))].join(","), - levelRank: [...new Set(x.positions.flatMap((y) => `${y.posType.posTypeRank}${y.posLevel.posLevelRank}`))].join(""), - })) - // .sort((x:any, y:any) => parseInt(x.typeRank) - parseInt(y.typeRank)) - // .sort((x:any, y:any) => parseInt(x.levelRank) - parseInt(y.levelRank)); + const _posMaster = posMaster + .map((x) => ({ + type: [...new Set(x.positions.flatMap((y) => y.posType.posTypeName))].join(","), + typeRank: [...new Set(x.positions.flatMap((y) => y.posType.posTypeRank))].join(""), + level: [...new Set(x.positions.flatMap((y) => y.posLevel.posLevelName))].join(","), + levelRank: [...new Set(x.positions.flatMap((y) => `${y.posType.posTypeRank}${y.posLevel.posLevelRank}`))].join(""), + })) - - // console.log("XXX: ",_posMaster) - const groupPosMaster = _posMaster.reduce((total: any, idx: any) => { - const sortedLevel = idx.level.split(",").sort().join(","); - const key = `${idx.type}-${sortedLevel}`; - - if (!total[key]) { - total[key] = { - type: idx.type, - typeRank: idx.typeRank, - level: sortedLevel, - LeaveType: idx.levelRank, - total: 0, - remark: "" - }; + const groupedData = _posMaster.reduce((acc:any, curr:any) => { + const key = `${curr.type}|${curr.typeRank}|${curr.level}|${curr.levelRank}`; + if (!acc[key]) { + acc[key] = { ...curr, total: 1 }; + } else { + acc[key].total += 1; } - total[key].total += 1; - return total; + return acc; }, {}); - - let result = Object.values(groupPosMaster) - .sort((x:any, y:any) => parseInt(x.typeRank) - parseInt(y.typeRank)) - .sort((x:any, y:any) => parseInt(x.levelRank) - parseInt(y.levelRank));; - // let _TypeTemp = ""; - // result = result.map((item: any) => { - // if (item.type === _TypeTemp) { - // return { ...item, type: "" }; - // } - // _TypeTemp = item.type; - // return item; - // }); + let result = Object.values(groupedData) + .map((x: any) => ({ + type: x.type, + typeRank: parseInt(x.typeRank), + level: x.level, + levelRank: parseInt(x.levelRank), + total: x.total, + remark: "", + })) + .sort((x, y) => { + if (x.typeRank !== y.typeRank) { + return x.typeRank - y.typeRank; + } + return x.levelRank - y.levelRank; + }); + let tmpType: string = ""; + let allTotal: number = 0; + let total: number = 0; + let _total: number = 0; + let _reslut = new Array(); + + result.forEach((x:any, idx:number) => { + allTotal += x.total; + total += x.total; + if(x.type === tmpType) { + _reslut.push({ + ...x, + type: "" + }) + }else { + if(x.type !== tmpType && tmpType != "") { + _total = total - x.total; + _reslut.push({ + type: "", + typeRank: "", + level: "รวม", + levelRank: "", + total: _total, + remark: "", + }) + total = x.total; + _total = 0; + } + _reslut.push({ + ...x + }) + } + tmpType = x.type; + }); + + _reslut.push({ + type: "", + typeRank: "", + level: "รวม", + levelRank: "", + total: total, + remark: "", + }) + _reslut.push({ + type: "", + typeRank: "", + level: "รวมทั้งสิ้น", + levelRank: "", + total: allTotal, + remark: "", + }); + return new HttpSuccess({ template: "report4", reportName: "report4", data: { dateCurrent: Extension.ToThaiShortDate(new Date()), rootName: orgRootData ? orgRootData.orgRootName : "-", - data: result + data: _reslut } }); + } + @Get("report4-employee/{rootId}") + async findReportEmp4(@Path() rootId: string) { + const orgRootData = await this.orgRootRepository.findOne({ + where: { id: rootId } + }); + if (!orgRootData) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + + const posMaster = await this.empPosMasterRepository + .createQueryBuilder("posMaster") + .leftJoinAndSelect("posMaster.positions", "position") + .leftJoinAndSelect("position.posType", "posType") + .leftJoinAndSelect("position.posLevel", "posLevel") + .where("posMaster.orgRootId = :rootId", { rootId }) + .orderBy("posType.posTypeRank", "ASC") + .addOrderBy("posLevel.posLevelRank", "ASC") + .getMany(); + + const _posMaster = posMaster + .map((x) => ({ + type: [...new Set(x.positions.flatMap((y) => y.posType.posTypeName))].join(","), + typeRank: [...new Set(x.positions.flatMap((y) => y.posType.posTypeRank))].join(""), + level: [...new Set(x.positions.flatMap((y) => y.posLevel.posLevelName))].join(","), + levelRank: [...new Set(x.positions.flatMap((y) => `${y.posType.posTypeRank}${y.posLevel.posLevelRank}`))].join(""), + })) + + const groupedData = _posMaster.reduce((acc:any, curr:any) => { + const key = `${curr.type}|${curr.typeRank}|${curr.level}|${curr.levelRank}`; + if (!acc[key]) { + acc[key] = { ...curr, total: 1 }; + } else { + acc[key].total += 1; + } + return acc; + }, {}); + + let result = Object.values(groupedData) + .map((x: any) => ({ + type: x.type, + typeRank: parseInt(x.typeRank), + level: x.level, + levelRank: parseInt(x.levelRank), + total: x.total, + remark: "", + })) + .sort((x, y) => { + if (x.typeRank !== y.typeRank) { + return x.typeRank - y.typeRank; + } + return x.levelRank - y.levelRank; + }); + let tmpType: string = ""; + let allTotal: number = 0; + let total: number = 0; + let _total: number = 0; + let _reslut = new Array(); + + result.forEach((x:any, idx:number) => { + allTotal += x.total; + total += x.total; + if(x.type === tmpType) { + _reslut.push({ + ...x, + type: "" + }) + }else { + if(x.type !== tmpType && tmpType != "") { + _total = total - x.total; + _reslut.push({ + type: "", + typeRank: "", + level: "รวม", + levelRank: "", + total: _total, + remark: "", + }) + total = x.total; + _total = 0; + } + _reslut.push({ + ...x + }) + } + tmpType = x.type; + }); + + _reslut.push({ + type: "", + typeRank: "", + level: "รวม", + levelRank: "", + total: total, + remark: "", + }) + _reslut.push({ + type: "", + typeRank: "", + level: "รวมทั้งสิ้น", + levelRank: "", + total: allTotal, + remark: "", + }); + + return new HttpSuccess({ + template: "report4", + reportName: "report4", + data: { + dateCurrent: Extension.ToThaiShortDate(new Date()), + rootName: orgRootData ? orgRootData.orgRootName : "-", + data: _reslut + } + }); } } From 396440e4bcb85315928789821fe9896e0d8591fe Mon Sep 17 00:00:00 2001 From: Bright Date: Wed, 20 Nov 2024 18:57:03 +0700 Subject: [PATCH 4/7] =?UTF-8?q?fix=20=E0=B9=81=E0=B8=99=E0=B8=9A=E0=B8=97?= =?UTF-8?q?=E0=B9=89=E0=B8=B2=E0=B8=A2=E0=B8=84=E0=B8=B3=E0=B8=AA=E0=B8=B1?= =?UTF-8?q?=E0=B9=88=E0=B8=87=E0=B8=A3=E0=B8=B1=E0=B8=81=E0=B8=A9=E0=B8=B2?= =?UTF-8?q?=E0=B8=81=E0=B8=B2=E0=B8=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/CommandController.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 7d530528..b3993ebb 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -3446,6 +3446,7 @@ export class CommandController extends Controller { RemarkHorizontal?: any | null; RemarkVertical?: any | null; CommandYear?: any | null; + CommandExcecuteDate?: Date | null; }[]; }, ) { @@ -3515,7 +3516,9 @@ export class CommandController extends Controller { "/" +*/ _organizationNew ?? "-", // date: Extension.ToThaiShortDate_noPrefix(new Date()), - dateStart: "-", + dateStart: item.CommandExcecuteDate + ? Extension.ToThaiShortDate(item.CommandExcecuteDate) + : "-", dateEnd: "-", order: posMasterAct.posMasterOrder == null From 15a9f6a3763305d69c1b51a004cd730c5e6e4b85 Mon Sep 17 00:00:00 2001 From: kittapath Date: Thu, 21 Nov 2024 10:54:09 +0700 Subject: [PATCH 5/7] no message --- src/controllers/PositionController.ts | 15 ++++++++------- src/controllers/UserController.ts | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index b87ee041..209e0633 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -1122,13 +1122,13 @@ export class PositionController extends Controller { where: { posMasterId: posMaster.id }, relations: ["posType", "posLevel", "posExecutive"], // order: { lastUpdatedAt: "ASC" }, - order: { + order: { posType: { - posTypeRank: "ASC" + posTypeRank: "ASC", }, posLevel: { - posLevelRank: "ASC" - } + posLevelRank: "ASC", + }, }, }); const formattedData = { @@ -1423,7 +1423,7 @@ export class PositionController extends Controller { .andWhere(checkChildConditions) .andWhere(typeCondition) .andWhere(revisionCondition); - }) + }), ) .orWhere( new Brackets((qb) => { @@ -1438,13 +1438,13 @@ export class PositionController extends Controller { .andWhere(checkChildConditions) .andWhere(typeCondition) .andWhere(revisionCondition); - }) + }), ) .orderBy("posMaster.posMasterOrder", "ASC") .skip((body.page - 1) * body.pageSize) .take(body.pageSize) .getManyAndCount(); - + //แก้ค้นหา let _position: any[] = []; let x: any = null; @@ -2005,6 +2005,7 @@ export class PositionController extends Controller { profilePostype: type == null || type.posTypeName == null ? null : type.posTypeName, profilePoslevel: level == null || level.posLevelName == null ? null : level.posLevelName, authRoleId: posMaster.authRoleId, + isCondition: posMaster.isCondition, authRoleName: authRoleName == null || authRoleName.roleName == null ? null : authRoleName.roleName, positions: positions.map((position: any) => ({ diff --git a/src/controllers/UserController.ts b/src/controllers/UserController.ts index 1b9a7435..54aa5f0b 100644 --- a/src/controllers/UserController.ts +++ b/src/controllers/UserController.ts @@ -435,7 +435,7 @@ export class KeycloakController extends Controller { ) { let condition: any = {}; - if (req.user.role.includes("ADMIN")) { + if (req.user.role.includes("ADMIN") && !req.user.role.includes("SUPER_ADMIN")) { const profile = await this.profileRepo.findOne({ relations: ["current_holders", "current_holders.orgRevision"], where: { From 04406080dc0041e545b0ed329317d2e839d33d99 Mon Sep 17 00:00:00 2001 From: kittapath Date: Thu, 21 Nov 2024 11:11:16 +0700 Subject: [PATCH 6/7] =?UTF-8?q?=E0=B8=AB=E0=B8=A1=E0=B8=B2=E0=B8=A2?= =?UTF-8?q?=E0=B9=80=E0=B8=AB=E0=B8=95=E0=B8=B8=E0=B9=80=E0=B8=87=E0=B8=B7?= =?UTF-8?q?=E0=B9=88=E0=B8=AD=E0=B8=99=E0=B9=84=E0=B8=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/PositionController.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index 209e0633..3501cac9 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -2006,6 +2006,7 @@ export class PositionController extends Controller { profilePoslevel: level == null || level.posLevelName == null ? null : level.posLevelName, authRoleId: posMaster.authRoleId, isCondition: posMaster.isCondition, + conditionReason: posMaster.conditionReason, authRoleName: authRoleName == null || authRoleName.roleName == null ? null : authRoleName.roleName, positions: positions.map((position: any) => ({ From fb5a30c6990c69ea08fcc677cc2c56fde667da8c Mon Sep 17 00:00:00 2001 From: kittapath Date: Thu, 21 Nov 2024 11:33:35 +0700 Subject: [PATCH 7/7] no message --- src/controllers/OrganizationController.ts | 1 - src/controllers/PositionController.ts | 99 +++++++++++++++++++ src/entities/OrgRevision.ts | 10 ++ .../1732163306077-updata_org_add_remark.ts | 14 +++ 4 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 src/migration/1732163306077-updata_org_add_remark.ts diff --git a/src/controllers/OrganizationController.ts b/src/controllers/OrganizationController.ts index 089d50bb..069bc57e 100644 --- a/src/controllers/OrganizationController.ts +++ b/src/controllers/OrganizationController.ts @@ -95,7 +95,6 @@ export class OrganizationController extends Controller { activeName: orgRevisionActive == null ? null : orgRevisionActive.orgRevisionName, draftId: orgRevisionDraf == null ? null : orgRevisionDraf.id, draftName: orgRevisionDraf == null ? null : orgRevisionDraf.orgRevisionName, - orgPublishDate: orgRevisionDraf == null ? null : orgRevisionDraf.orgPublishDate, isPublic: orgRevisionDraf == null || orgRevisionDraf.orgRevisionName == null ? false : true, }; diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index 3501cac9..087ca901 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -337,6 +337,105 @@ export class PositionController extends Controller { return new HttpSuccess(posDict.id); } + /** + * API แก้ไขตำแหน่ง + * + * @summary แก้ไขตำแหน่ง (ADMIN) + * + */ + @Put("position/executive/{id}") + @Example([ + { + positionName: "นักบริหาร", + positionField: "บริหาร", + posTypeId: "08db9e81-fc46-4e95-8b33-be4ca0016abf", + posLevelId: "08db9e81-fc46-4e95-8b33-be4ca0016abf", + posExecutiveId: "08db9e81-fc46-4e95-8b33-be4ca0016abf", + positionExecutiveField: "นักบริหาร", + positionArea: "บริหาร", + }, + ]) + async updatePositionExecutive( + @Path() id: string, + @Body() + requestBody: UpdatePosDict, + @Request() request: RequestWithUser, + ) { + // await new permission().PermissionUpdate(request, "SYS_ORG"); + const posDict = await this.posDictRepository.findOne({ + where: { id: id }, + }); + if (!posDict) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + } + + const checkPosTypeId = await this.posTypeRepository.findOne({ + where: { id: requestBody.posTypeId }, + }); + if (!checkPosTypeId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล PosTypeId"); + } + + const checkPosLevelId = await this.posLevelRepository.findOne({ + where: { id: requestBody.posLevelId }, + }); + if (!checkPosLevelId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล PosLevelId"); + } + + const _null: any = null; + if (requestBody.posExecutiveId == "") { + requestBody.posExecutiveId = _null; + } + + if (requestBody.posExecutiveId != null && requestBody.posExecutiveId != "") { + const checkPosExecutiveId = await this.posExecutiveRepository.findOne({ + where: { id: requestBody.posExecutiveId }, + }); + if (!checkPosExecutiveId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล PosExecutiveId"); + } + } + + const rowRepeated = await this.posDictRepository.findOne({ + where: { + id: Not(id), + posDictName: requestBody.posDictName, + posDictField: requestBody.posDictField, + posTypeId: requestBody.posTypeId, + posLevelId: requestBody.posLevelId, + posExecutiveId: requestBody.posExecutiveId ? requestBody.posExecutiveId : "", + posDictExecutiveField: requestBody.posDictExecutiveField + ? requestBody.posDictExecutiveField + : "", + posDictArea: requestBody.posDictArea ? requestBody.posDictArea : "", + isSpecial: requestBody.isSpecial, + }, + }); + if (rowRepeated) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ข้อมูล Row นี้มีอยู่ในระบบแล้ว"); + } + const before = structuredClone(posDict); + Object.assign(posDict, requestBody); + posDict.lastUpdateUserId = request.user.sub; + posDict.lastUpdateFullName = request.user.name; + posDict.lastUpdatedAt = new Date(); + posDict.posDictName = requestBody.posDictName; + posDict.posDictField = requestBody.posDictField; + posDict.posTypeId = requestBody.posTypeId; + posDict.posLevelId = requestBody.posLevelId; + posDict.posExecutiveId = requestBody.posExecutiveId ? requestBody.posExecutiveId : null; + posDict.posDictExecutiveField = requestBody.posDictExecutiveField + ? requestBody.posDictExecutiveField + : ""; + posDict.posDictArea = requestBody.posDictArea ? requestBody.posDictArea : ""; + posDict.isSpecial = requestBody.isSpecial; + // this.posDictRepository.merge(posDict, requestBody); + await this.posDictRepository.save(posDict, { data: request }); + setLogDataDiff(request, { before, after: posDict }); + return new HttpSuccess(); + } + /** * API แก้ไขตำแหน่ง * diff --git a/src/entities/OrgRevision.ts b/src/entities/OrgRevision.ts index 3f65c7df..48175f0f 100644 --- a/src/entities/OrgRevision.ts +++ b/src/entities/OrgRevision.ts @@ -17,6 +17,13 @@ export class OrgRevision extends EntityBase { }) orgRevisionName: string; + @Column({ + comment: "หมายเหตุ", + length: 255, + default: null, + }) + remark: string; + @Column({ comment: "สถานะเป็นโครงสร้างปัจจุบันหรือไม่", default: false, @@ -82,5 +89,8 @@ export class CreateOrgRevision { @Column("uuid") orgRevisionId?: string; + + @Column() + remark: string; } export type UpdateOrgRevision = Partial; diff --git a/src/migration/1732163306077-updata_org_add_remark.ts b/src/migration/1732163306077-updata_org_add_remark.ts new file mode 100644 index 00000000..bc37c689 --- /dev/null +++ b/src/migration/1732163306077-updata_org_add_remark.ts @@ -0,0 +1,14 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdataOrgAddRemark1732163306077 implements MigrationInterface { + name = 'UpdataOrgAddRemark1732163306077' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`orgRevision\` ADD \`remark\` varchar(255) NULL COMMENT 'หมายเหตุ'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`orgRevision\` DROP COLUMN \`remark\``); + } + +}