From ca7d2f2a75fcae46a8915d3370123442bd3a496a Mon Sep 17 00:00:00 2001 From: Adisak Date: Tue, 4 Nov 2025 09:51:33 +0700 Subject: [PATCH 1/9] #54 --- src/controllers/AuthRoleController.ts | 20 ++++++++++++++++++-- src/controllers/UserController.ts | 12 +++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/controllers/AuthRoleController.ts b/src/controllers/AuthRoleController.ts index 5d007fb3..78220ab7 100644 --- a/src/controllers/AuthRoleController.ts +++ b/src/controllers/AuthRoleController.ts @@ -6,6 +6,7 @@ import { Patch, Path, Post, + Query, Request, Route, Security, @@ -36,8 +37,21 @@ export class AuthRoleController extends Controller { private redis = require("redis"); @Get("list") - public async listAuthRole() { - const getList = await this.authRoleRepo.find(); + public async listAuthRole( + @Request() req: RequestWithUser, + @Query("isAdminVisibled ") isAdminVisibled : string = "false", + ) { + let condition: any = {}; + if(isAdminVisibled.toLowerCase() === "true"){ + condition = { isAdminVisibled: true }; + }else{ + condition = {}; + } + const getList = await this.authRoleRepo.find( + { + where: condition, + } + ); // if (!getList || getList.length === 0) { // throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); // } @@ -161,6 +175,7 @@ export class AuthRoleController extends Controller { body: { roleName: string; roleDescription: string; + isAdminVisibled?: boolean; authRoleAttrs: Array<{ // id: string; authSysId: string; @@ -187,6 +202,7 @@ export class AuthRoleController extends Controller { })); Object.assign(record, { + isAdminVisibled: body.isAdminVisibled?body.isAdminVisibled:false, roleName: body.roleName, roleDescription: body.roleDescription, lastUpdateFullName: req.user.name, diff --git a/src/controllers/UserController.ts b/src/controllers/UserController.ts index 6f2fd217..5d7d4910 100644 --- a/src/controllers/UserController.ts +++ b/src/controllers/UserController.ts @@ -758,11 +758,21 @@ export class KeycloakController extends Controller { } @Get("user/role/{id}") - async getRoleUser(@Path("id") id: string) { + async getRoleUser(@Request() req: RequestWithUser,@Path("id") id: string) { + const profile = await this.profileRepo.findOne({ where: { keycloak: id }, relations: ["roleKeycloaks"], }); + + if ( + req.user.sub === id && + req.user.role.some(x => x === 'ADMIN') && + !req.user.role.some(x => x === 'SUPER_ADMIN') + ) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่มีสิทธิ์เข้าถึงข้อมูลนี้"); + } + if (!profile) { const profileEmp = await this.profileEmpRepo.findOne({ where: { keycloak: id, employeeClass: "PERM" }, From b1a9c77c8c3210e38f844a6b0096da6a8e9a98f4 Mon Sep 17 00:00:00 2001 From: Adisak Date: Tue, 4 Nov 2025 10:03:35 +0700 Subject: [PATCH 2/9] fix --- src/controllers/AuthRoleController.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/AuthRoleController.ts b/src/controllers/AuthRoleController.ts index 78220ab7..4159c5ec 100644 --- a/src/controllers/AuthRoleController.ts +++ b/src/controllers/AuthRoleController.ts @@ -39,7 +39,7 @@ export class AuthRoleController extends Controller { @Get("list") public async listAuthRole( @Request() req: RequestWithUser, - @Query("isAdminVisibled ") isAdminVisibled : string = "false", + @Query("isAdminVisibled") isAdminVisibled : string = "false", ) { let condition: any = {}; if(isAdminVisibled.toLowerCase() === "true"){ From 6cc6bed80622a7289ff2baf0346d459f12afddd3 Mon Sep 17 00:00:00 2001 From: Adisak Date: Tue, 4 Nov 2025 15:16:53 +0700 Subject: [PATCH 3/9] migration --- src/entities/ApiHistory.ts | 6 +++--- ...rApi_and_tokenApi_field_ApiHistoryTable.ts | 20 +++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 src/migration/1762243747843-update_size_headerApi_and_tokenApi_field_ApiHistoryTable.ts diff --git a/src/entities/ApiHistory.ts b/src/entities/ApiHistory.ts index c5f640d0..e84263b6 100644 --- a/src/entities/ApiHistory.ts +++ b/src/entities/ApiHistory.ts @@ -6,17 +6,17 @@ import { ApiName } from "./ApiName"; @Entity("apiHistory") export class ApiHistory extends EntityBase { @Column({ + type: 'longtext', nullable: true, comment: "header", - length: 255, - default: null, + default: null, }) headerApi: string; @Column({ + type: 'longtext', nullable: true, comment: "token", - length: 255, default: null, }) tokenApi: string; diff --git a/src/migration/1762243747843-update_size_headerApi_and_tokenApi_field_ApiHistoryTable.ts b/src/migration/1762243747843-update_size_headerApi_and_tokenApi_field_ApiHistoryTable.ts new file mode 100644 index 00000000..bed2927e --- /dev/null +++ b/src/migration/1762243747843-update_size_headerApi_and_tokenApi_field_ApiHistoryTable.ts @@ -0,0 +1,20 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateSizeHeaderApiAndTokenApiFieldApiHistoryTable1762243747843 implements MigrationInterface { + name = 'UpdateSizeHeaderApiAndTokenApiFieldApiHistoryTable1762243747843' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`apiHistory\` DROP COLUMN \`headerApi\``); + await queryRunner.query(`ALTER TABLE \`apiHistory\` ADD \`headerApi\` longtext NULL COMMENT 'header'`); + await queryRunner.query(`ALTER TABLE \`apiHistory\` DROP COLUMN \`tokenApi\``); + await queryRunner.query(`ALTER TABLE \`apiHistory\` ADD \`tokenApi\` longtext NULL COMMENT 'token'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`apiHistory\` DROP COLUMN \`tokenApi\``); + await queryRunner.query(`ALTER TABLE \`apiHistory\` ADD \`tokenApi\` varchar(255) NULL COMMENT 'token'`); + await queryRunner.query(`ALTER TABLE \`apiHistory\` DROP COLUMN \`headerApi\``); + await queryRunner.query(`ALTER TABLE \`apiHistory\` ADD \`headerApi\` varchar(255) NULL COMMENT 'header'`); + } + +} From 5d742fa8be02e83e0c9fae0ad08588117d51c4af Mon Sep 17 00:00:00 2001 From: Adisak Date: Tue, 4 Nov 2025 15:17:52 +0700 Subject: [PATCH 4/9] #206 --- src/controllers/PositionController.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index e9f8d99e..34be7a8e 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -3704,7 +3704,9 @@ export class PositionController extends Controller { dataMaster.current_holderId = _null; } await this.posMasterRepository.save(dataMaster, { data: request }); - await CreatePosMasterHistoryOfficer(dataMaster.id, request); + if (chkRevision?.orgRevisionIsCurrent) { + await CreatePosMasterHistoryOfficer(dataMaster.id, request); + } setLogDataDiff(request, { before, after: dataMaster }); return new HttpSuccess(); From 2f73ae28744aefefcced12332dce1e4d0724d82f Mon Sep 17 00:00:00 2001 From: harid Date: Wed, 5 Nov 2025 10:07:22 +0700 Subject: [PATCH 5/9] revert --- src/app.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/app.ts b/src/app.ts index 368be40f..7f0e0220 100644 --- a/src/app.ts +++ b/src/app.ts @@ -66,9 +66,7 @@ async function main() { } }); - // const cronTime_Oct = "0 0 1 10 *"; - // Test #1912 - const cronTime_Oct = "0 0 4 11 *"; + const cronTime_Oct = "0 0 1 10 *"; cron.schedule(cronTime_Oct, async () => { try { const commandController = new CommandController(); From 46ae2296194c9239a14280e5ad38d28a48d9719f Mon Sep 17 00:00:00 2001 From: Adisak Date: Fri, 7 Nov 2025 10:05:30 +0700 Subject: [PATCH 6/9] migration --- src/entities/view/viewDirectorActing.ts | 3 + ...762422995264-update_viewDirectiorActing.ts | 122 ++++++++++++++++++ 2 files changed, 125 insertions(+) create mode 100644 src/migration/1762422995264-update_viewDirectiorActing.ts diff --git a/src/entities/view/viewDirectorActing.ts b/src/entities/view/viewDirectorActing.ts index bf99391b..d4029ebb 100644 --- a/src/entities/view/viewDirectorActing.ts +++ b/src/entities/view/viewDirectorActing.ts @@ -8,6 +8,7 @@ import { ViewColumn, ViewEntity } from "typeorm"; \`profileChild\`.\`lastName\` AS \`lastName\`, \`profileChild\`.\`citizenId\` AS \`citizenId\`, \`profileChild\`.\`position\` AS \`position\`, + \`profile\`.\`isProbation\` AS \`isProbation\`, CONCAT((CASE WHEN (\`posMaster\`.\`orgChild1Id\` IS NULL) THEN \`orgRootChild\`.\`orgRootShortName\` WHEN (\`posMaster\`.\`orgChild2Id\` IS NULL) THEN \`orgChild1Child\`.\`orgChild1ShortName\` @@ -71,6 +72,8 @@ export class viewDirectorActing { @ViewColumn() position: string; @ViewColumn() + isProbation: string; + @ViewColumn() posNo: string; @ViewColumn() posLevel: string; diff --git a/src/migration/1762422995264-update_viewDirectiorActing.ts b/src/migration/1762422995264-update_viewDirectiorActing.ts new file mode 100644 index 00000000..611a5347 --- /dev/null +++ b/src/migration/1762422995264-update_viewDirectiorActing.ts @@ -0,0 +1,122 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateViewDirectiorActing1762422995264 implements MigrationInterface { + name = 'UpdateViewDirectiorActing1762422995264' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DROP VIEW \`view_director_acting\``); + await queryRunner.query(`CREATE VIEW \`view_director_acting\` AS SELECT + \`profileChild\`.\`id\` AS \`Id\`, + \`profileChild\`.\`prefix\` AS \`prefix\`, + \`profileChild\`.\`firstName\` AS \`firstName\`, + \`profileChild\`.\`lastName\` AS \`lastName\`, + \`profileChild\`.\`citizenId\` AS \`citizenId\`, + \`profileChild\`.\`position\` AS \`position\`, + \`profile\`.\`isProbation\` AS \`isProbation\`, + CONCAT((CASE + WHEN (\`posMaster\`.\`orgChild1Id\` IS NULL) THEN \`orgRootChild\`.\`orgRootShortName\` + WHEN (\`posMaster\`.\`orgChild2Id\` IS NULL) THEN \`orgChild1Child\`.\`orgChild1ShortName\` + WHEN (\`posMaster\`.\`orgChild3Id\` IS NULL) THEN \`orgChild2Child\`.\`orgChild2ShortName\` + WHEN (\`posMaster\`.\`orgChild4Id\` IS NULL) THEN \`orgChild3Child\`.\`orgChild3ShortName\` + ELSE \`orgChild4Child\`.\`orgChild4ShortName\` + END), + \`posMaster\`.\`posMasterNo\`) AS \`posNo\`, + \`posMasterChild\`.\`isDirector\` AS \`isDirectorChild\`, + \`posMaster\`.\`isDirector\` AS \`isDirector\`, + \`posLevel\`.\`posLevelName\` AS \`posLevel\`, + \`posType\`.\`posTypeName\` AS \`posType\`, + \`posExecutive\`.\`posExecutiveName\` AS \`posExecutiveName\`, + \`orgRoot\`.\`isDeputy\` AS \`isDeputy\`, + \`orgChild1\`.\`isOfficer\` AS \`isOfficer\`, + \`posMaster\`.\`orgRevisionId\` AS \`orgRevisionId\`, + \`posMaster\`.\`orgRootId\` AS \`orgRootId\`, + \`posMaster\`.\`orgChild1Id\` AS \`orgChild1Id\`, + \`posMaster\`.\`orgChild2Id\` AS \`orgChild2Id\`, + \`posMaster\`.\`orgChild3Id\` AS \`orgChild3Id\`, + \`posMaster\`.\`orgChild4Id\` AS \`orgChild4Id\`, + CONCAT(\`posMaster\`.\`id\`, \`profileChild\`.\`id\`) AS \`key\`, + \`profile\`.\`id\` AS \`actFullNameId\`, + CONCAT(\`profile\`.\`prefix\`, + \`profile\`.\`firstName\`, + ' ', + \`profile\`.\`lastName\`) AS \`actFullName\` + FROM + (((((((((((((((\`posMasterAct\` + JOIN \`posMaster\` \`posMasterChild\` ON ((\`posMasterAct\`.\`posMasterChildId\` = \`posMasterChild\`.\`id\`))) + JOIN \`profile\` \`profileChild\` ON ((\`posMasterChild\`.\`current_holderId\` = \`profileChild\`.\`id\`))) + LEFT JOIN \`orgRoot\` \`orgRootChild\` ON ((\`posMasterChild\`.\`orgRootId\` = \`orgRootChild\`.\`id\`))) + LEFT JOIN \`orgChild1\` \`orgChild1Child\` ON ((\`posMasterChild\`.\`orgChild1Id\` = \`orgChild1Child\`.\`id\`))) + LEFT JOIN \`orgChild2\` \`orgChild2Child\` ON ((\`posMasterChild\`.\`orgChild2Id\` = \`orgChild2Child\`.\`id\`))) + LEFT JOIN \`orgChild3\` \`orgChild3Child\` ON ((\`posMasterChild\`.\`orgChild3Id\` = \`orgChild3Child\`.\`id\`))) + LEFT JOIN \`orgChild4\` \`orgChild4Child\` ON ((\`posMasterChild\`.\`orgChild4Id\` = \`orgChild4Child\`.\`id\`))) + JOIN \`posLevel\` ON ((\`profileChild\`.\`posLevelId\` = \`posLevel\`.\`id\`))) + JOIN \`posType\` ON ((\`profileChild\`.\`posTypeId\` = \`posType\`.\`id\`))) + JOIN \`posMaster\` ON ((\`posMasterAct\`.\`posMasterId\` = \`posMaster\`.\`id\`))) + LEFT JOIN \`orgRoot\` ON ((\`posMaster\`.\`orgRootId\` = \`orgRoot\`.\`id\`))) + LEFT JOIN \`orgChild1\` ON ((\`posMaster\`.\`orgChild1Id\` = \`orgChild1\`.\`id\`))) + JOIN \`profile\` ON ((\`posMaster\`.\`current_holderId\` = \`profile\`.\`id\`))) + LEFT JOIN \`position\` ON ((\`posMasterChild\`.\`id\` = \`position\`.\`posMasterId\`))) + LEFT JOIN \`posExecutive\` ON ((\`position\`.\`posExecutiveId\` = \`posExecutive\`.\`id\`))) + WHERE + (\`position\`.\`positionIsSelected\` = TRUE)`); + + } + + public async down(queryRunner: QueryRunner): Promise {; + await queryRunner.query(`DROP VIEW \`view_director_acting\``); + await queryRunner.query(`CREATE VIEW \`view_director_acting\` AS SELECT + \`profileChild\`.\`id\` AS \`Id\`, + \`profileChild\`.\`prefix\` AS \`prefix\`, + \`profileChild\`.\`firstName\` AS \`firstName\`, + \`profileChild\`.\`lastName\` AS \`lastName\`, + \`profileChild\`.\`citizenId\` AS \`citizenId\`, + \`profileChild\`.\`position\` AS \`position\`, + CONCAT((CASE + WHEN (\`posMaster\`.\`orgChild1Id\` IS NULL) THEN \`orgRootChild\`.\`orgRootShortName\` + WHEN (\`posMaster\`.\`orgChild2Id\` IS NULL) THEN \`orgChild1Child\`.\`orgChild1ShortName\` + WHEN (\`posMaster\`.\`orgChild3Id\` IS NULL) THEN \`orgChild2Child\`.\`orgChild2ShortName\` + WHEN (\`posMaster\`.\`orgChild4Id\` IS NULL) THEN \`orgChild3Child\`.\`orgChild3ShortName\` + ELSE \`orgChild4Child\`.\`orgChild4ShortName\` + END), + \`posMaster\`.\`posMasterNo\`) AS \`posNo\`, + \`posMasterChild\`.\`isDirector\` AS \`isDirectorChild\`, + \`posMaster\`.\`isDirector\` AS \`isDirector\`, + \`posLevel\`.\`posLevelName\` AS \`posLevel\`, + \`posType\`.\`posTypeName\` AS \`posType\`, + \`posExecutive\`.\`posExecutiveName\` AS \`posExecutiveName\`, + \`orgRoot\`.\`isDeputy\` AS \`isDeputy\`, + \`orgChild1\`.\`isOfficer\` AS \`isOfficer\`, + \`posMaster\`.\`orgRevisionId\` AS \`orgRevisionId\`, + \`posMaster\`.\`orgRootId\` AS \`orgRootId\`, + \`posMaster\`.\`orgChild1Id\` AS \`orgChild1Id\`, + \`posMaster\`.\`orgChild2Id\` AS \`orgChild2Id\`, + \`posMaster\`.\`orgChild3Id\` AS \`orgChild3Id\`, + \`posMaster\`.\`orgChild4Id\` AS \`orgChild4Id\`, + CONCAT(\`posMaster\`.\`id\`, \`profileChild\`.\`id\`) AS \`key\`, + \`profile\`.\`id\` AS \`actFullNameId\`, + CONCAT(\`profile\`.\`prefix\`, + \`profile\`.\`firstName\`, + ' ', + \`profile\`.\`lastName\`) AS \`actFullName\` + FROM + (((((((((((((((\`posMasterAct\` + JOIN \`posMaster\` \`posMasterChild\` ON ((\`posMasterAct\`.\`posMasterChildId\` = \`posMasterChild\`.\`id\`))) + JOIN \`profile\` \`profileChild\` ON ((\`posMasterChild\`.\`current_holderId\` = \`profileChild\`.\`id\`))) + LEFT JOIN \`orgRoot\` \`orgRootChild\` ON ((\`posMasterChild\`.\`orgRootId\` = \`orgRootChild\`.\`id\`))) + LEFT JOIN \`orgChild1\` \`orgChild1Child\` ON ((\`posMasterChild\`.\`orgChild1Id\` = \`orgChild1Child\`.\`id\`))) + LEFT JOIN \`orgChild2\` \`orgChild2Child\` ON ((\`posMasterChild\`.\`orgChild2Id\` = \`orgChild2Child\`.\`id\`))) + LEFT JOIN \`orgChild3\` \`orgChild3Child\` ON ((\`posMasterChild\`.\`orgChild3Id\` = \`orgChild3Child\`.\`id\`))) + LEFT JOIN \`orgChild4\` \`orgChild4Child\` ON ((\`posMasterChild\`.\`orgChild4Id\` = \`orgChild4Child\`.\`id\`))) + JOIN \`posLevel\` ON ((\`profileChild\`.\`posLevelId\` = \`posLevel\`.\`id\`))) + JOIN \`posType\` ON ((\`profileChild\`.\`posTypeId\` = \`posType\`.\`id\`))) + JOIN \`posMaster\` ON ((\`posMasterAct\`.\`posMasterId\` = \`posMaster\`.\`id\`))) + LEFT JOIN \`orgRoot\` ON ((\`posMaster\`.\`orgRootId\` = \`orgRoot\`.\`id\`))) + LEFT JOIN \`orgChild1\` ON ((\`posMaster\`.\`orgChild1Id\` = \`orgChild1\`.\`id\`))) + JOIN \`profile\` ON ((\`posMaster\`.\`current_holderId\` = \`profile\`.\`id\`))) + LEFT JOIN \`position\` ON ((\`posMasterChild\`.\`id\` = \`position\`.\`posMasterId\`))) + LEFT JOIN \`posExecutive\` ON ((\`position\`.\`posExecutiveId\` = \`posExecutive\`.\`id\`))) + WHERE + (\`position\`.\`positionIsSelected\` = TRUE)`); + } + +} From 7d5d6bb43e38c28d74d5d04e099197047f9576cf Mon Sep 17 00:00:00 2001 From: Adisak Date: Fri, 7 Nov 2025 12:30:03 +0700 Subject: [PATCH 7/9] migration --- src/entities/view/viewDirector.ts | 15 + src/entities/view/viewDirectorActing.ts | 4 + ...762422995264-update_viewDirectiorActing.ts | 122 -------- ...e_viewDirectior_and_viewDirectiorActing.ts | 290 ++++++++++++++++++ 4 files changed, 309 insertions(+), 122 deletions(-) delete mode 100644 src/migration/1762422995264-update_viewDirectiorActing.ts create mode 100644 src/migration/1762489522691-update_viewDirectior_and_viewDirectiorActing.ts diff --git a/src/entities/view/viewDirector.ts b/src/entities/view/viewDirector.ts index a13f9ebf..d2ed5b65 100644 --- a/src/entities/view/viewDirector.ts +++ b/src/entities/view/viewDirector.ts @@ -31,6 +31,21 @@ import { ViewColumn, ViewEntity } from "typeorm"; posMaster.orgChild3Id AS orgChild3Id, posMaster.orgChild4Id AS orgChild4Id, CONCAT(posMaster.id, profile.id) AS \`key\`, + ( + SELECT hrms_organization.acting.actFullNameKeycloakId + FROM hrms_organization.view_director_acting acting + WHERE ((hrms_organization.acting.Id = hrms_organization.posMaster.current_holderId) + AND (hrms_organization.acting.orgRootId = hrms_organization.posMaster.orgRootId) + AND ((hrms_organization.acting.orgChild1Id = hrms_organization.posMaster.orgChild1Id) + OR (hrms_organization.acting.orgChild1Id IS NULL)) + AND ((hrms_organization.acting.orgChild2Id = hrms_organization.posMaster.orgChild2Id) + OR (hrms_organization.acting.orgChild2Id IS NULL)) + AND ((hrms_organization.acting.orgChild3Id = hrms_organization.posMaster.orgChild3Id) + OR (hrms_organization.acting.orgChild3Id IS NULL)) + AND ((hrms_organization.acting.orgChild4Id = hrms_organization.posMaster.orgChild4Id) + OR (hrms_organization.acting.orgChild4Id IS NULL))) + LIMIT 1 + ) AS actFullNameKeycloakId, ( SELECT actFullNameId FROM view_director_acting AS acting diff --git a/src/entities/view/viewDirectorActing.ts b/src/entities/view/viewDirectorActing.ts index d4029ebb..1f56d027 100644 --- a/src/entities/view/viewDirectorActing.ts +++ b/src/entities/view/viewDirectorActing.ts @@ -30,6 +30,10 @@ import { ViewColumn, ViewEntity } from "typeorm"; \`posMaster\`.\`orgChild2Id\` AS \`orgChild2Id\`, \`posMaster\`.\`orgChild3Id\` AS \`orgChild3Id\`, \`posMaster\`.\`orgChild4Id\` AS \`orgChild4Id\`, + CONCAT(\`hrms_organization\`.\`posMaster\`.\`id\`, + \`profileChild\`.\`id\`) AS \`key\`, + \`hrms_organization\`.\`profile\`.\`id\` AS \`actFullNameId\`, + \`hrms_organization\`.\`profile\`.\`keycloak\` AS \`actFullNameKeycloakId\`, CONCAT(\`posMaster\`.\`id\`, \`profileChild\`.\`id\`) AS \`key\`, \`profile\`.\`id\` AS \`actFullNameId\`, CONCAT(\`profile\`.\`prefix\`, diff --git a/src/migration/1762422995264-update_viewDirectiorActing.ts b/src/migration/1762422995264-update_viewDirectiorActing.ts deleted file mode 100644 index 611a5347..00000000 --- a/src/migration/1762422995264-update_viewDirectiorActing.ts +++ /dev/null @@ -1,122 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; - -export class UpdateViewDirectiorActing1762422995264 implements MigrationInterface { - name = 'UpdateViewDirectiorActing1762422995264' - - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`DROP VIEW \`view_director_acting\``); - await queryRunner.query(`CREATE VIEW \`view_director_acting\` AS SELECT - \`profileChild\`.\`id\` AS \`Id\`, - \`profileChild\`.\`prefix\` AS \`prefix\`, - \`profileChild\`.\`firstName\` AS \`firstName\`, - \`profileChild\`.\`lastName\` AS \`lastName\`, - \`profileChild\`.\`citizenId\` AS \`citizenId\`, - \`profileChild\`.\`position\` AS \`position\`, - \`profile\`.\`isProbation\` AS \`isProbation\`, - CONCAT((CASE - WHEN (\`posMaster\`.\`orgChild1Id\` IS NULL) THEN \`orgRootChild\`.\`orgRootShortName\` - WHEN (\`posMaster\`.\`orgChild2Id\` IS NULL) THEN \`orgChild1Child\`.\`orgChild1ShortName\` - WHEN (\`posMaster\`.\`orgChild3Id\` IS NULL) THEN \`orgChild2Child\`.\`orgChild2ShortName\` - WHEN (\`posMaster\`.\`orgChild4Id\` IS NULL) THEN \`orgChild3Child\`.\`orgChild3ShortName\` - ELSE \`orgChild4Child\`.\`orgChild4ShortName\` - END), - \`posMaster\`.\`posMasterNo\`) AS \`posNo\`, - \`posMasterChild\`.\`isDirector\` AS \`isDirectorChild\`, - \`posMaster\`.\`isDirector\` AS \`isDirector\`, - \`posLevel\`.\`posLevelName\` AS \`posLevel\`, - \`posType\`.\`posTypeName\` AS \`posType\`, - \`posExecutive\`.\`posExecutiveName\` AS \`posExecutiveName\`, - \`orgRoot\`.\`isDeputy\` AS \`isDeputy\`, - \`orgChild1\`.\`isOfficer\` AS \`isOfficer\`, - \`posMaster\`.\`orgRevisionId\` AS \`orgRevisionId\`, - \`posMaster\`.\`orgRootId\` AS \`orgRootId\`, - \`posMaster\`.\`orgChild1Id\` AS \`orgChild1Id\`, - \`posMaster\`.\`orgChild2Id\` AS \`orgChild2Id\`, - \`posMaster\`.\`orgChild3Id\` AS \`orgChild3Id\`, - \`posMaster\`.\`orgChild4Id\` AS \`orgChild4Id\`, - CONCAT(\`posMaster\`.\`id\`, \`profileChild\`.\`id\`) AS \`key\`, - \`profile\`.\`id\` AS \`actFullNameId\`, - CONCAT(\`profile\`.\`prefix\`, - \`profile\`.\`firstName\`, - ' ', - \`profile\`.\`lastName\`) AS \`actFullName\` - FROM - (((((((((((((((\`posMasterAct\` - JOIN \`posMaster\` \`posMasterChild\` ON ((\`posMasterAct\`.\`posMasterChildId\` = \`posMasterChild\`.\`id\`))) - JOIN \`profile\` \`profileChild\` ON ((\`posMasterChild\`.\`current_holderId\` = \`profileChild\`.\`id\`))) - LEFT JOIN \`orgRoot\` \`orgRootChild\` ON ((\`posMasterChild\`.\`orgRootId\` = \`orgRootChild\`.\`id\`))) - LEFT JOIN \`orgChild1\` \`orgChild1Child\` ON ((\`posMasterChild\`.\`orgChild1Id\` = \`orgChild1Child\`.\`id\`))) - LEFT JOIN \`orgChild2\` \`orgChild2Child\` ON ((\`posMasterChild\`.\`orgChild2Id\` = \`orgChild2Child\`.\`id\`))) - LEFT JOIN \`orgChild3\` \`orgChild3Child\` ON ((\`posMasterChild\`.\`orgChild3Id\` = \`orgChild3Child\`.\`id\`))) - LEFT JOIN \`orgChild4\` \`orgChild4Child\` ON ((\`posMasterChild\`.\`orgChild4Id\` = \`orgChild4Child\`.\`id\`))) - JOIN \`posLevel\` ON ((\`profileChild\`.\`posLevelId\` = \`posLevel\`.\`id\`))) - JOIN \`posType\` ON ((\`profileChild\`.\`posTypeId\` = \`posType\`.\`id\`))) - JOIN \`posMaster\` ON ((\`posMasterAct\`.\`posMasterId\` = \`posMaster\`.\`id\`))) - LEFT JOIN \`orgRoot\` ON ((\`posMaster\`.\`orgRootId\` = \`orgRoot\`.\`id\`))) - LEFT JOIN \`orgChild1\` ON ((\`posMaster\`.\`orgChild1Id\` = \`orgChild1\`.\`id\`))) - JOIN \`profile\` ON ((\`posMaster\`.\`current_holderId\` = \`profile\`.\`id\`))) - LEFT JOIN \`position\` ON ((\`posMasterChild\`.\`id\` = \`position\`.\`posMasterId\`))) - LEFT JOIN \`posExecutive\` ON ((\`position\`.\`posExecutiveId\` = \`posExecutive\`.\`id\`))) - WHERE - (\`position\`.\`positionIsSelected\` = TRUE)`); - - } - - public async down(queryRunner: QueryRunner): Promise {; - await queryRunner.query(`DROP VIEW \`view_director_acting\``); - await queryRunner.query(`CREATE VIEW \`view_director_acting\` AS SELECT - \`profileChild\`.\`id\` AS \`Id\`, - \`profileChild\`.\`prefix\` AS \`prefix\`, - \`profileChild\`.\`firstName\` AS \`firstName\`, - \`profileChild\`.\`lastName\` AS \`lastName\`, - \`profileChild\`.\`citizenId\` AS \`citizenId\`, - \`profileChild\`.\`position\` AS \`position\`, - CONCAT((CASE - WHEN (\`posMaster\`.\`orgChild1Id\` IS NULL) THEN \`orgRootChild\`.\`orgRootShortName\` - WHEN (\`posMaster\`.\`orgChild2Id\` IS NULL) THEN \`orgChild1Child\`.\`orgChild1ShortName\` - WHEN (\`posMaster\`.\`orgChild3Id\` IS NULL) THEN \`orgChild2Child\`.\`orgChild2ShortName\` - WHEN (\`posMaster\`.\`orgChild4Id\` IS NULL) THEN \`orgChild3Child\`.\`orgChild3ShortName\` - ELSE \`orgChild4Child\`.\`orgChild4ShortName\` - END), - \`posMaster\`.\`posMasterNo\`) AS \`posNo\`, - \`posMasterChild\`.\`isDirector\` AS \`isDirectorChild\`, - \`posMaster\`.\`isDirector\` AS \`isDirector\`, - \`posLevel\`.\`posLevelName\` AS \`posLevel\`, - \`posType\`.\`posTypeName\` AS \`posType\`, - \`posExecutive\`.\`posExecutiveName\` AS \`posExecutiveName\`, - \`orgRoot\`.\`isDeputy\` AS \`isDeputy\`, - \`orgChild1\`.\`isOfficer\` AS \`isOfficer\`, - \`posMaster\`.\`orgRevisionId\` AS \`orgRevisionId\`, - \`posMaster\`.\`orgRootId\` AS \`orgRootId\`, - \`posMaster\`.\`orgChild1Id\` AS \`orgChild1Id\`, - \`posMaster\`.\`orgChild2Id\` AS \`orgChild2Id\`, - \`posMaster\`.\`orgChild3Id\` AS \`orgChild3Id\`, - \`posMaster\`.\`orgChild4Id\` AS \`orgChild4Id\`, - CONCAT(\`posMaster\`.\`id\`, \`profileChild\`.\`id\`) AS \`key\`, - \`profile\`.\`id\` AS \`actFullNameId\`, - CONCAT(\`profile\`.\`prefix\`, - \`profile\`.\`firstName\`, - ' ', - \`profile\`.\`lastName\`) AS \`actFullName\` - FROM - (((((((((((((((\`posMasterAct\` - JOIN \`posMaster\` \`posMasterChild\` ON ((\`posMasterAct\`.\`posMasterChildId\` = \`posMasterChild\`.\`id\`))) - JOIN \`profile\` \`profileChild\` ON ((\`posMasterChild\`.\`current_holderId\` = \`profileChild\`.\`id\`))) - LEFT JOIN \`orgRoot\` \`orgRootChild\` ON ((\`posMasterChild\`.\`orgRootId\` = \`orgRootChild\`.\`id\`))) - LEFT JOIN \`orgChild1\` \`orgChild1Child\` ON ((\`posMasterChild\`.\`orgChild1Id\` = \`orgChild1Child\`.\`id\`))) - LEFT JOIN \`orgChild2\` \`orgChild2Child\` ON ((\`posMasterChild\`.\`orgChild2Id\` = \`orgChild2Child\`.\`id\`))) - LEFT JOIN \`orgChild3\` \`orgChild3Child\` ON ((\`posMasterChild\`.\`orgChild3Id\` = \`orgChild3Child\`.\`id\`))) - LEFT JOIN \`orgChild4\` \`orgChild4Child\` ON ((\`posMasterChild\`.\`orgChild4Id\` = \`orgChild4Child\`.\`id\`))) - JOIN \`posLevel\` ON ((\`profileChild\`.\`posLevelId\` = \`posLevel\`.\`id\`))) - JOIN \`posType\` ON ((\`profileChild\`.\`posTypeId\` = \`posType\`.\`id\`))) - JOIN \`posMaster\` ON ((\`posMasterAct\`.\`posMasterId\` = \`posMaster\`.\`id\`))) - LEFT JOIN \`orgRoot\` ON ((\`posMaster\`.\`orgRootId\` = \`orgRoot\`.\`id\`))) - LEFT JOIN \`orgChild1\` ON ((\`posMaster\`.\`orgChild1Id\` = \`orgChild1\`.\`id\`))) - JOIN \`profile\` ON ((\`posMaster\`.\`current_holderId\` = \`profile\`.\`id\`))) - LEFT JOIN \`position\` ON ((\`posMasterChild\`.\`id\` = \`position\`.\`posMasterId\`))) - LEFT JOIN \`posExecutive\` ON ((\`position\`.\`posExecutiveId\` = \`posExecutive\`.\`id\`))) - WHERE - (\`position\`.\`positionIsSelected\` = TRUE)`); - } - -} diff --git a/src/migration/1762489522691-update_viewDirectior_and_viewDirectiorActing.ts b/src/migration/1762489522691-update_viewDirectior_and_viewDirectiorActing.ts new file mode 100644 index 00000000..26c26b8f --- /dev/null +++ b/src/migration/1762489522691-update_viewDirectior_and_viewDirectiorActing.ts @@ -0,0 +1,290 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateViewDirectiorAndViewDirectiorActing1762489522691 implements MigrationInterface { + name = 'UpdateViewDirectiorAndViewDirectiorActing1762489522691' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DELETE FROM \`hrms_organization\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW", "view_director_acting", "hrms_organization"]); + await queryRunner.query(`DROP VIEW IF EXISTS \`view_director_acting\``); + // await queryRunner.query(`INSERT INTO \`hrms_organization\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["hrms_organization", "VIEW", "view_director", "SELECT \n profile.id AS Id,\n profile.prefix AS prefix,\n profile.firstName AS firstName,\n profile.lastName AS lastName,\n profile.citizenId AS citizenId,\n profile.position AS position,\n CONCAT(\n CASE \n WHEN posMaster.orgChild1Id IS NULL THEN orgRoot.orgRootShortName\n WHEN posMaster.orgChild2Id IS NULL THEN orgChild1.orgChild1ShortName\n WHEN posMaster.orgChild3Id IS NULL THEN orgChild2.orgChild2ShortName\n WHEN posMaster.orgChild4Id IS NULL THEN orgChild3.orgChild3ShortName\n ELSE orgChild4.orgChild4ShortName\n END,\n posMaster.posMasterNo\n ) AS posNo,\n posMaster.isDirector AS isDirector,\n posLevel.posLevelName AS posLevel,\n posType.posTypeName AS posType,\n posExecutive.posExecutiveName AS posExecutiveName,\n orgRoot.isDeputy AS isDeputy,\n orgChild1.isOfficer AS isOfficer,\n posMaster.orgRevisionId AS orgRevisionId,\n posMaster.orgRootId AS orgRootId,\n posMaster.orgChild1Id AS orgChild1Id,\n posMaster.orgChild2Id AS orgChild2Id,\n posMaster.orgChild3Id AS orgChild3Id,\n posMaster.orgChild4Id AS orgChild4Id,\n CONCAT(posMaster.id, profile.id) AS `key`,\n (\n SELECT hrms_organization.acting.actFullNameKeycloakId\n FROM hrms_organization.view_director_acting acting\n WHERE ((hrms_organization.acting.Id = hrms_organization.posMaster.current_holderId)\n AND (hrms_organization.acting.orgRootId = hrms_organization.posMaster.orgRootId)\n AND ((hrms_organization.acting.orgChild1Id = hrms_organization.posMaster.orgChild1Id)\n OR (hrms_organization.acting.orgChild1Id IS NULL))\n AND ((hrms_organization.acting.orgChild2Id = hrms_organization.posMaster.orgChild2Id)\n OR (hrms_organization.acting.orgChild2Id IS NULL))\n AND ((hrms_organization.acting.orgChild3Id = hrms_organization.posMaster.orgChild3Id)\n OR (hrms_organization.acting.orgChild3Id IS NULL))\n AND ((hrms_organization.acting.orgChild4Id = hrms_organization.posMaster.orgChild4Id)\n OR (hrms_organization.acting.orgChild4Id IS NULL)))\n LIMIT 1\n ) AS actFullNameKeycloakId,\n (\n SELECT actFullNameId \n FROM view_director_acting AS acting\n WHERE acting.Id = posMaster.current_holderId \n AND acting.orgRootId = posMaster.orgRootId \n AND (acting.orgChild1Id = posMaster.orgChild1Id OR acting.orgChild1Id IS NULL)\n AND (acting.orgChild2Id = posMaster.orgChild2Id OR acting.orgChild2Id IS NULL)\n AND (acting.orgChild3Id = posMaster.orgChild3Id OR acting.orgChild3Id IS NULL)\n AND (acting.orgChild4Id = posMaster.orgChild4Id OR acting.orgChild4Id IS NULL)\n LIMIT 1\n ) AS actFullNameId,\n (\n SELECT actFullName \n FROM view_director_acting AS acting\n WHERE acting.Id = posMaster.current_holderId \n AND acting.orgRootId = posMaster.orgRootId \n AND (acting.orgChild1Id = posMaster.orgChild1Id OR acting.orgChild1Id IS NULL)\n AND (acting.orgChild2Id = posMaster.orgChild2Id OR acting.orgChild2Id IS NULL)\n AND (acting.orgChild3Id = posMaster.orgChild3Id OR acting.orgChild3Id IS NULL)\n AND (acting.orgChild4Id = posMaster.orgChild4Id OR acting.orgChild4Id IS NULL)\n LIMIT 1\n ) AS actFullName\n FROM\n posMaster\n JOIN profile ON posMaster.current_holderId = profile.id\n LEFT JOIN orgRoot ON posMaster.orgRootId = orgRoot.id\n LEFT JOIN orgChild1 ON posMaster.orgChild1Id = orgChild1.id\n LEFT JOIN orgChild2 ON posMaster.orgChild2Id = orgChild2.id\n LEFT JOIN orgChild3 ON posMaster.orgChild3Id = orgChild3.id\n LEFT JOIN orgChild4 ON posMaster.orgChild4Id = orgChild4.id\n JOIN posLevel ON profile.posLevelId = posLevel.id\n JOIN posType ON profile.posTypeId = posType.id\n LEFT JOIN position ON posMaster.id = position.posMasterId\n LEFT JOIN posExecutive ON position.posExecutiveId = posExecutive.id\n INNER JOIN orgRevision ON posMaster.orgRevisionId = orgRevision.id\n WHERE\n (position.positionIsSelected = TRUE)\n AND (orgRevision.orgRevisionIsCurrent = TRUE\n AND orgRevision.orgRevisionIsDraft = FALSE)"]); + await queryRunner.query(`CREATE VIEW \`view_director_acting\` AS SELECT + \`profileChild\`.\`id\` AS \`Id\`, + \`profileChild\`.\`prefix\` AS \`prefix\`, + \`profileChild\`.\`firstName\` AS \`firstName\`, + \`profileChild\`.\`lastName\` AS \`lastName\`, + \`profileChild\`.\`citizenId\` AS \`citizenId\`, + \`profileChild\`.\`position\` AS \`position\`, + \`profile\`.\`isProbation\` AS \`isProbation\`, + CONCAT((CASE + WHEN (\`posMaster\`.\`orgChild1Id\` IS NULL) THEN \`orgRootChild\`.\`orgRootShortName\` + WHEN (\`posMaster\`.\`orgChild2Id\` IS NULL) THEN \`orgChild1Child\`.\`orgChild1ShortName\` + WHEN (\`posMaster\`.\`orgChild3Id\` IS NULL) THEN \`orgChild2Child\`.\`orgChild2ShortName\` + WHEN (\`posMaster\`.\`orgChild4Id\` IS NULL) THEN \`orgChild3Child\`.\`orgChild3ShortName\` + ELSE \`orgChild4Child\`.\`orgChild4ShortName\` + END), + \`posMaster\`.\`posMasterNo\`) AS \`posNo\`, + \`posMasterChild\`.\`isDirector\` AS \`isDirectorChild\`, + \`posMaster\`.\`isDirector\` AS \`isDirector\`, + \`posLevel\`.\`posLevelName\` AS \`posLevel\`, + \`posType\`.\`posTypeName\` AS \`posType\`, + \`posExecutive\`.\`posExecutiveName\` AS \`posExecutiveName\`, + \`orgRoot\`.\`isDeputy\` AS \`isDeputy\`, + \`orgChild1\`.\`isOfficer\` AS \`isOfficer\`, + \`posMaster\`.\`orgRevisionId\` AS \`orgRevisionId\`, + \`posMaster\`.\`orgRootId\` AS \`orgRootId\`, + \`posMaster\`.\`orgChild1Id\` AS \`orgChild1Id\`, + \`posMaster\`.\`orgChild2Id\` AS \`orgChild2Id\`, + \`posMaster\`.\`orgChild3Id\` AS \`orgChild3Id\`, + \`posMaster\`.\`orgChild4Id\` AS \`orgChild4Id\`, + CONCAT(\`hrms_organization\`.\`profile\`.\`keycloak\`) AS \`actFullNameKeycloakId\`, + CONCAT(\`posMaster\`.\`id\`, \`profileChild\`.\`id\`) AS \`key\`, + \`profile\`.\`id\` AS \`actFullNameId\`, + CONCAT(\`profile\`.\`prefix\`, + \`profile\`.\`firstName\`, + ' ', + \`profile\`.\`lastName\`) AS \`actFullName\` + FROM + (((((((((((((((\`posMasterAct\` + JOIN \`posMaster\` \`posMasterChild\` ON ((\`posMasterAct\`.\`posMasterChildId\` = \`posMasterChild\`.\`id\`))) + JOIN \`profile\` \`profileChild\` ON ((\`posMasterChild\`.\`current_holderId\` = \`profileChild\`.\`id\`))) + LEFT JOIN \`orgRoot\` \`orgRootChild\` ON ((\`posMasterChild\`.\`orgRootId\` = \`orgRootChild\`.\`id\`))) + LEFT JOIN \`orgChild1\` \`orgChild1Child\` ON ((\`posMasterChild\`.\`orgChild1Id\` = \`orgChild1Child\`.\`id\`))) + LEFT JOIN \`orgChild2\` \`orgChild2Child\` ON ((\`posMasterChild\`.\`orgChild2Id\` = \`orgChild2Child\`.\`id\`))) + LEFT JOIN \`orgChild3\` \`orgChild3Child\` ON ((\`posMasterChild\`.\`orgChild3Id\` = \`orgChild3Child\`.\`id\`))) + LEFT JOIN \`orgChild4\` \`orgChild4Child\` ON ((\`posMasterChild\`.\`orgChild4Id\` = \`orgChild4Child\`.\`id\`))) + JOIN \`posLevel\` ON ((\`profileChild\`.\`posLevelId\` = \`posLevel\`.\`id\`))) + JOIN \`posType\` ON ((\`profileChild\`.\`posTypeId\` = \`posType\`.\`id\`))) + JOIN \`posMaster\` ON ((\`posMasterAct\`.\`posMasterId\` = \`posMaster\`.\`id\`))) + LEFT JOIN \`orgRoot\` ON ((\`posMaster\`.\`orgRootId\` = \`orgRoot\`.\`id\`))) + LEFT JOIN \`orgChild1\` ON ((\`posMaster\`.\`orgChild1Id\` = \`orgChild1\`.\`id\`))) + JOIN \`profile\` ON ((\`posMaster\`.\`current_holderId\` = \`profile\`.\`id\`))) + LEFT JOIN \`position\` ON ((\`posMasterChild\`.\`id\` = \`position\`.\`posMasterId\`))) + LEFT JOIN \`posExecutive\` ON ((\`position\`.\`posExecutiveId\` = \`posExecutive\`.\`id\`))) + WHERE + (\`position\`.\`positionIsSelected\` = TRUE)`); + + await queryRunner.query(`DELETE FROM \`hrms_organization\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW", "view_director", "hrms_organization"]); + await queryRunner.query(`DROP VIEW IF EXISTS \`view_director\``); + // await queryRunner.query(`INSERT INTO \`hrms_organization\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["hrms_organization", "VIEW", "view_employee_pos_master", "SELECT \n employeePosMaster.id,\n employeePosMaster.posMasterNoPrefix,\n employeePosMaster.posMasterNo,\n employeePosMaster.posMasterNoSuffix,\n employeePosMaster.orgRevisionId,\n employeePosMaster.orgRootId,\n employeePosMaster.orgChild1Id,\n employeePosMaster.orgChild2Id,\n employeePosMaster.orgChild3Id,\n employeePosMaster.orgChild4Id,\n employeePosMaster.current_holderId,\n profileEmployee.id as profileId,\n profileEmployee.prefix,\n profileEmployee.firstName,\n profileEmployee.lastName,\n profileEmployee.citizenId,\n profileEmployee.position,\n profileEmployee.amount,\n profileEmployee.dateRetire,\n profileEmployee.birthDate,\n profileEmployee.salaryLevel,\n profileEmployee.group,\n orgRoot.id as rootId,\n orgRoot.orgRootShortName,\n orgRoot.orgRootOrder,\n orgRoot.orgRootName,\n orgChild1.id as child1Id,\n orgChild1.orgChild1ShortName,\n orgChild1.orgChild1Order,\n orgChild1.orgChild1Name,\n orgChild2.id as child2Id,\n orgChild2.orgChild2ShortName,\n orgChild2.orgChild2Order,\n orgChild2.orgChild2Name,\n orgChild3.id as child3Id,\n orgChild3.orgChild3ShortName,\n orgChild3.orgChild3Order,\n orgChild3.orgChild3Name,\n orgChild4.id as child4Id,\n orgChild4.orgChild4ShortName,\n orgChild4.orgChild4Order,\n orgChild4.orgChild4Name,\n position.id as positionId,\n position.positionIsSelected,\n position.posExecutiveId as positionPosExecutiveId,\n position.isSpecial,\n posExecutive.id as posExecutiveId,\n posExecutive.posExecutiveName,\n profileDiscipline.id as profileDisciplineId,\n profileDiscipline.date as disCriplineDate,\n profileLeave.id as profileLeaveId,\n profileAssessment.id as profileAssessmentId,\n profileAssessment.pointSum,\n employeePosLevel.id as posLevelId,\n employeePosLevel.posLevelName,\n\temployeePosType.id as posTypeId,\n employeePosType.posTypeName,\n employeePosType.posTypeShortName\n FROM \n employeePosMaster\n LEFT JOIN \n profileEmployee ON employeePosMaster.current_holderId = profileEmployee.id \n LEFT JOIN \n orgRoot ON employeePosMaster.orgRootId = orgRoot.id\n LEFT JOIN \n orgChild1 ON employeePosMaster.orgChild1Id = orgChild1.id\n LEFT JOIN \n orgChild2 ON employeePosMaster.orgChild2Id = orgChild2.id\n LEFT JOIN \n orgChild3 ON employeePosMaster.orgChild3Id = orgChild3.id\n LEFT JOIN \n orgChild4 ON employeePosMaster.orgChild4Id = orgChild4.id\n LEFT JOIN \n position ON employeePosMaster.id = position.posMasterId\n LEFT JOIN \n posExecutive ON position.posExecutiveId = posExecutive.id\n LEFT JOIN (\n SELECT *\n FROM profileDisciplineEmployee pd1\n WHERE pd1.date = (\n SELECT MAX(pd2.date)\n FROM profileDisciplineEmployee pd2\n WHERE pd2.profileId = pd1.profileId\n )\n ) AS profileDiscipline ON profileDiscipline.profileId = profileEmployee.id\n LEFT JOIN (\n SELECT pl1.*\n FROM profileLeave pl1\n INNER JOIN (\n SELECT profileId, MAX(createdAt) AS maxDate\n FROM profileLeave\n GROUP BY profileId\n ) pl2 ON pl1.profileId = pl2.profileId\n AND pl1.createdAt = pl2.maxDate\n ) AS profileLeave ON profileLeave.profileId = employeePosMaster.current_holderId\n LEFT JOIN (\n SELECT pa1.*\n FROM profileAssessment pa1\n INNER JOIN (\n SELECT profileId, MAX(createdAt) AS maxDate\n FROM profileAssessment\n GROUP BY profileId\n ) pa2 ON pa1.profileId = pa2.profileId\n AND pa1.createdAt = pa2.maxDate\n ) AS profileAssessment \n ON profileAssessment.profileId = profileEmployee.id\n LEFT JOIN \n employeePosLevel ON profileEmployee.posLevelId = employeePosLevel.id\n LEFT JOIN \n employeePosType ON profileEmployee.posTypeId = employeePosType.id\n WHERE \t\n employeePosMaster.current_holderId IS NOT NULL\n ORDER BY \n profileEmployee.citizenId ASC"]); + await queryRunner.query(`CREATE VIEW \`view_director\` AS SELECT + profile.id AS Id, + profile.prefix AS prefix, + profile.firstName AS firstName, + profile.lastName AS lastName, + profile.citizenId AS citizenId, + profile.position AS position, + CONCAT( + CASE + WHEN posMaster.orgChild1Id IS NULL THEN orgRoot.orgRootShortName + WHEN posMaster.orgChild2Id IS NULL THEN orgChild1.orgChild1ShortName + WHEN posMaster.orgChild3Id IS NULL THEN orgChild2.orgChild2ShortName + WHEN posMaster.orgChild4Id IS NULL THEN orgChild3.orgChild3ShortName + ELSE orgChild4.orgChild4ShortName + END, + posMaster.posMasterNo + ) AS posNo, + posMaster.isDirector AS isDirector, + posLevel.posLevelName AS posLevel, + posType.posTypeName AS posType, + posExecutive.posExecutiveName AS posExecutiveName, + orgRoot.isDeputy AS isDeputy, + orgChild1.isOfficer AS isOfficer, + posMaster.orgRevisionId AS orgRevisionId, + posMaster.orgRootId AS orgRootId, + posMaster.orgChild1Id AS orgChild1Id, + posMaster.orgChild2Id AS orgChild2Id, + posMaster.orgChild3Id AS orgChild3Id, + posMaster.orgChild4Id AS orgChild4Id, + CONCAT(posMaster.id, profile.id) AS \`key\`, + ( + SELECT hrms_organization.acting.actFullNameKeycloakId + FROM hrms_organization.view_director_acting acting + WHERE ((hrms_organization.acting.Id = hrms_organization.posMaster.current_holderId) + AND (hrms_organization.acting.orgRootId = hrms_organization.posMaster.orgRootId) + AND ((hrms_organization.acting.orgChild1Id = hrms_organization.posMaster.orgChild1Id) + OR (hrms_organization.acting.orgChild1Id IS NULL)) + AND ((hrms_organization.acting.orgChild2Id = hrms_organization.posMaster.orgChild2Id) + OR (hrms_organization.acting.orgChild2Id IS NULL)) + AND ((hrms_organization.acting.orgChild3Id = hrms_organization.posMaster.orgChild3Id) + OR (hrms_organization.acting.orgChild3Id IS NULL)) + AND ((hrms_organization.acting.orgChild4Id = hrms_organization.posMaster.orgChild4Id) + OR (hrms_organization.acting.orgChild4Id IS NULL))) + LIMIT 1 + ) AS actFullNameKeycloakId, + ( + SELECT actFullNameId + FROM view_director_acting AS acting + WHERE acting.Id = posMaster.current_holderId + AND acting.orgRootId = posMaster.orgRootId + AND (acting.orgChild1Id = posMaster.orgChild1Id OR acting.orgChild1Id IS NULL) + AND (acting.orgChild2Id = posMaster.orgChild2Id OR acting.orgChild2Id IS NULL) + AND (acting.orgChild3Id = posMaster.orgChild3Id OR acting.orgChild3Id IS NULL) + AND (acting.orgChild4Id = posMaster.orgChild4Id OR acting.orgChild4Id IS NULL) + LIMIT 1 + ) AS actFullNameId, + ( + SELECT actFullName + FROM view_director_acting AS acting + WHERE acting.Id = posMaster.current_holderId + AND acting.orgRootId = posMaster.orgRootId + AND (acting.orgChild1Id = posMaster.orgChild1Id OR acting.orgChild1Id IS NULL) + AND (acting.orgChild2Id = posMaster.orgChild2Id OR acting.orgChild2Id IS NULL) + AND (acting.orgChild3Id = posMaster.orgChild3Id OR acting.orgChild3Id IS NULL) + AND (acting.orgChild4Id = posMaster.orgChild4Id OR acting.orgChild4Id IS NULL) + LIMIT 1 + ) AS actFullName + FROM + posMaster + JOIN profile ON posMaster.current_holderId = profile.id + LEFT JOIN orgRoot ON posMaster.orgRootId = orgRoot.id + LEFT JOIN orgChild1 ON posMaster.orgChild1Id = orgChild1.id + LEFT JOIN orgChild2 ON posMaster.orgChild2Id = orgChild2.id + LEFT JOIN orgChild3 ON posMaster.orgChild3Id = orgChild3.id + LEFT JOIN orgChild4 ON posMaster.orgChild4Id = orgChild4.id + JOIN posLevel ON profile.posLevelId = posLevel.id + JOIN posType ON profile.posTypeId = posType.id + LEFT JOIN position ON posMaster.id = position.posMasterId + LEFT JOIN posExecutive ON position.posExecutiveId = posExecutive.id + INNER JOIN orgRevision ON posMaster.orgRevisionId = orgRevision.id + WHERE + (position.positionIsSelected = TRUE) + AND (orgRevision.orgRevisionIsCurrent = TRUE + AND orgRevision.orgRevisionIsDraft = FALSE)`); + + await queryRunner.query(`INSERT INTO \`hrms_organization\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["hrms_organization", "VIEW", "view_current_tenure_employee", "WITH resultData AS (\n SELECT\n commandDateAffect,\n positionName,\n positionCee,\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) AS days_diff,\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 365.2524 AS 'Years',\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 30.4375 % 12 AS 'Months',\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) % 30.4375 AS 'Days',\n posNo,\n positionExecutive,\n positionType,\n positionLevel,\n OrgRoot,\n orgChild1,\n orgChild2,\n orgChild3,\n orgChild4,\n commandCode,\n commandName,\n commandNo,\n commandYear,\n remark,\n profileEmployeeId,\n ROW_NUMBER() OVER (PARTITION BY profileEmployeeId ORDER BY commandDateAffect ASC) AS orderNumber\n FROM (\n SELECT\n commandDateAffect,\n commandDateSign,\n positionName,\n positionCee,\n posNo,\n positionExecutive,\n positionType,\n positionLevel,\n OrgRoot,\n orgChild1,\n orgChild2,\n orgChild3,\n orgChild4,\n commandCode,\n commandName,\n commandNo,\n commandYear,\n remark,\n profileEmployeeId,\n LAG(commandDateSign) OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) AS prevCommandDateSign,\n ROW_NUMBER() OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) -\n ROW_NUMBER() OVER (PARTITION BY positionName ORDER BY commandDateAffect ASC, commandDateSign ASC) as groupedId\n FROM\n profileSalary\n WHERE\n commandCode IN (1, 2, 3, 4, 8, 10, 11, 12, 15, 16)\n ORDER BY\n commandDateAffect ASC, commandDateSign ASC\n ) AS groupedPosition\n WHERE\n prevCommandDateSign IS NULL OR commandDateSign >= prevCommandDateSign\n GROUP BY\n profileEmployeeId, groupedId, positionName\n )\n SELECT\n commandDateAffect,\n positionName,\n positionCee,\n days_diff,\n Years,\n Months,\n Days,\n posNo,\n positionExecutive,\n positionType,\n positionLevel,\n OrgRoot,\n orgChild1,\n orgChild2,\n orgChild3,\n orgChild4,\n commandCode,\n commandName,\n commandNo,\n commandYear,\n remark,\n profileEmployeeId,\n orderNumber\n FROM resultData\n\n UNION ALL\n\n SELECT\n CURDATE() AS commandDateAffect,\n NULL AS positionName,\n NULL AS positionCee,\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) AS days_diff,\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 365.2524 AS 'Years',\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 30.4375 % 12 AS 'Months',\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) % 30.4375 AS 'Days',\n NULL AS posNo,\n NULL AS positionExecutive,\n NULL AS positionType,\n NULL AS positionLevel,\n NULL AS OrgRoot,\n NULL AS orgChild1,\n NULL AS orgChild2,\n NULL AS orgChild3,\n NULL AS orgChild4,\n NULL AS commandCode,\n NULL AS commandName,\n NULL AS commandNo,\n NULL AS commandYear,\n NULL AS remark,\n profileEmployeeId,\n NULL AS orderNumber\n FROM resultData"]); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DELETE FROM \`hrms_organization\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW", "view_director_acting", "hrms_organization"]); + await queryRunner.query(`DROP VIEW IF EXISTS \`view_director_acting\``); + await queryRunner.query(`CREATE VIEW \`view_director_acting\` AS SELECT + \`profileChild\`.\`id\` AS \`Id\`, + \`profileChild\`.\`prefix\` AS \`prefix\`, + \`profileChild\`.\`firstName\` AS \`firstName\`, + \`profileChild\`.\`lastName\` AS \`lastName\`, + \`profileChild\`.\`citizenId\` AS \`citizenId\`, + \`profileChild\`.\`position\` AS \`position\`, + CONCAT((CASE + WHEN (\`posMaster\`.\`orgChild1Id\` IS NULL) THEN \`orgRootChild\`.\`orgRootShortName\` + WHEN (\`posMaster\`.\`orgChild2Id\` IS NULL) THEN \`orgChild1Child\`.\`orgChild1ShortName\` + WHEN (\`posMaster\`.\`orgChild3Id\` IS NULL) THEN \`orgChild2Child\`.\`orgChild2ShortName\` + WHEN (\`posMaster\`.\`orgChild4Id\` IS NULL) THEN \`orgChild3Child\`.\`orgChild3ShortName\` + ELSE \`orgChild4Child\`.\`orgChild4ShortName\` + END), + \`posMaster\`.\`posMasterNo\`) AS \`posNo\`, + \`posMasterChild\`.\`isDirector\` AS \`isDirectorChild\`, + \`posMaster\`.\`isDirector\` AS \`isDirector\`, + \`posLevel\`.\`posLevelName\` AS \`posLevel\`, + \`posType\`.\`posTypeName\` AS \`posType\`, + \`posExecutive\`.\`posExecutiveName\` AS \`posExecutiveName\`, + \`orgRoot\`.\`isDeputy\` AS \`isDeputy\`, + \`orgChild1\`.\`isOfficer\` AS \`isOfficer\`, + \`posMaster\`.\`orgRevisionId\` AS \`orgRevisionId\`, + \`posMaster\`.\`orgRootId\` AS \`orgRootId\`, + \`posMaster\`.\`orgChild1Id\` AS \`orgChild1Id\`, + \`posMaster\`.\`orgChild2Id\` AS \`orgChild2Id\`, + \`posMaster\`.\`orgChild3Id\` AS \`orgChild3Id\`, + \`posMaster\`.\`orgChild4Id\` AS \`orgChild4Id\`, + CONCAT(\`posMaster\`.\`id\`, \`profileChild\`.\`id\`) AS \`key\`, + \`profile\`.\`id\` AS \`actFullNameId\`, + CONCAT(\`profile\`.\`prefix\`, + \`profile\`.\`firstName\`, + ' ', + \`profile\`.\`lastName\`) AS \`actFullName\` + FROM + (((((((((((((((\`posMasterAct\` + JOIN \`posMaster\` \`posMasterChild\` ON ((\`posMasterAct\`.\`posMasterChildId\` = \`posMasterChild\`.\`id\`))) + JOIN \`profile\` \`profileChild\` ON ((\`posMasterChild\`.\`current_holderId\` = \`profileChild\`.\`id\`))) + LEFT JOIN \`orgRoot\` \`orgRootChild\` ON ((\`posMasterChild\`.\`orgRootId\` = \`orgRootChild\`.\`id\`))) + LEFT JOIN \`orgChild1\` \`orgChild1Child\` ON ((\`posMasterChild\`.\`orgChild1Id\` = \`orgChild1Child\`.\`id\`))) + LEFT JOIN \`orgChild2\` \`orgChild2Child\` ON ((\`posMasterChild\`.\`orgChild2Id\` = \`orgChild2Child\`.\`id\`))) + LEFT JOIN \`orgChild3\` \`orgChild3Child\` ON ((\`posMasterChild\`.\`orgChild3Id\` = \`orgChild3Child\`.\`id\`))) + LEFT JOIN \`orgChild4\` \`orgChild4Child\` ON ((\`posMasterChild\`.\`orgChild4Id\` = \`orgChild4Child\`.\`id\`))) + JOIN \`posLevel\` ON ((\`profileChild\`.\`posLevelId\` = \`posLevel\`.\`id\`))) + JOIN \`posType\` ON ((\`profileChild\`.\`posTypeId\` = \`posType\`.\`id\`))) + JOIN \`posMaster\` ON ((\`posMasterAct\`.\`posMasterId\` = \`posMaster\`.\`id\`))) + LEFT JOIN \`orgRoot\` ON ((\`posMaster\`.\`orgRootId\` = \`orgRoot\`.\`id\`))) + LEFT JOIN \`orgChild1\` ON ((\`posMaster\`.\`orgChild1Id\` = \`orgChild1\`.\`id\`))) + JOIN \`profile\` ON ((\`posMaster\`.\`current_holderId\` = \`profile\`.\`id\`))) + LEFT JOIN \`position\` ON ((\`posMasterChild\`.\`id\` = \`position\`.\`posMasterId\`))) + LEFT JOIN \`posExecutive\` ON ((\`position\`.\`posExecutiveId\` = \`posExecutive\`.\`id\`))) + WHERE + (\`position\`.\`positionIsSelected\` = TRUE)`); + + // await queryRunner.query(`INSERT INTO \`hrms_organization\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["hrms_organization", "VIEW", "view_director_acting", "SELECT \n `profileChild`.`id` AS `Id`,\n `profileChild`.`prefix` AS `prefix`,\n `profileChild`.`firstName` AS `firstName`,\n `profileChild`.`lastName` AS `lastName`,\n `profileChild`.`citizenId` AS `citizenId`,\n `profileChild`.`position` AS `position`,\n CONCAT((CASE\n WHEN (`posMaster`.`orgChild1Id` IS NULL) THEN `orgRootChild`.`orgRootShortName`\n WHEN (`posMaster`.`orgChild2Id` IS NULL) THEN `orgChild1Child`.`orgChild1ShortName`\n WHEN (`posMaster`.`orgChild3Id` IS NULL) THEN `orgChild2Child`.`orgChild2ShortName`\n WHEN (`posMaster`.`orgChild4Id` IS NULL) THEN `orgChild3Child`.`orgChild3ShortName`\n ELSE `orgChild4Child`.`orgChild4ShortName`\n END),\n `posMaster`.`posMasterNo`) AS `posNo`,\n `posMasterChild`.`isDirector` AS `isDirectorChild`,\n `posMaster`.`isDirector` AS `isDirector`,\n `posLevel`.`posLevelName` AS `posLevel`,\n `posType`.`posTypeName` AS `posType`,\n `posExecutive`.`posExecutiveName` AS `posExecutiveName`,\n `orgRoot`.`isDeputy` AS `isDeputy`,\n `orgChild1`.`isOfficer` AS `isOfficer`,\n `posMaster`.`orgRevisionId` AS `orgRevisionId`,\n `posMaster`.`orgRootId` AS `orgRootId`,\n `posMaster`.`orgChild1Id` AS `orgChild1Id`,\n `posMaster`.`orgChild2Id` AS `orgChild2Id`,\n `posMaster`.`orgChild3Id` AS `orgChild3Id`,\n `posMaster`.`orgChild4Id` AS `orgChild4Id`,\n CONCAT(`posMaster`.`id`, `profileChild`.`id`) AS `key`,\n `profile`.`id` AS `actFullNameId`,\n CONCAT(`profile`.`prefix`,\n `profile`.`firstName`,\n ' ',\n `profile`.`lastName`) AS `actFullName`\n FROM\n (((((((((((((((`posMasterAct`\n JOIN `posMaster` `posMasterChild` ON ((`posMasterAct`.`posMasterChildId` = `posMasterChild`.`id`)))\n JOIN `profile` `profileChild` ON ((`posMasterChild`.`current_holderId` = `profileChild`.`id`)))\n LEFT JOIN `orgRoot` `orgRootChild` ON ((`posMasterChild`.`orgRootId` = `orgRootChild`.`id`)))\n LEFT JOIN `orgChild1` `orgChild1Child` ON ((`posMasterChild`.`orgChild1Id` = `orgChild1Child`.`id`)))\n LEFT JOIN `orgChild2` `orgChild2Child` ON ((`posMasterChild`.`orgChild2Id` = `orgChild2Child`.`id`)))\n LEFT JOIN `orgChild3` `orgChild3Child` ON ((`posMasterChild`.`orgChild3Id` = `orgChild3Child`.`id`)))\n LEFT JOIN `orgChild4` `orgChild4Child` ON ((`posMasterChild`.`orgChild4Id` = `orgChild4Child`.`id`)))\n JOIN `posLevel` ON ((`profileChild`.`posLevelId` = `posLevel`.`id`)))\n JOIN `posType` ON ((`profileChild`.`posTypeId` = `posType`.`id`)))\n JOIN `posMaster` ON ((`posMasterAct`.`posMasterId` = `posMaster`.`id`)))\n LEFT JOIN `orgRoot` ON ((`posMaster`.`orgRootId` = `orgRoot`.`id`)))\n LEFT JOIN `orgChild1` ON ((`posMaster`.`orgChild1Id` = `orgChild1`.`id`)))\n JOIN `profile` ON ((`posMaster`.`current_holderId` = `profile`.`id`)))\n LEFT JOIN `position` ON ((`posMasterChild`.`id` = `position`.`posMasterId`)))\n LEFT JOIN `posExecutive` ON ((`position`.`posExecutiveId` = `posExecutive`.`id`)))\n WHERE\n (`position`.`positionIsSelected` = TRUE)"]); + await queryRunner.query(`DELETE FROM \`hrms_organization\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW", "view_director", "hrms_organization"]); + await queryRunner.query(`DROP VIEW IF EXISTS \`view_director\``); + await queryRunner.query(`CREATE VIEW \`view_director\` AS SELECT + profile.id AS Id, + profile.prefix AS prefix, + profile.firstName AS firstName, + profile.lastName AS lastName, + profile.citizenId AS citizenId, + profile.position AS position, + CONCAT( + CASE + WHEN posMaster.orgChild1Id IS NULL THEN orgRoot.orgRootShortName + WHEN posMaster.orgChild2Id IS NULL THEN orgChild1.orgChild1ShortName + WHEN posMaster.orgChild3Id IS NULL THEN orgChild2.orgChild2ShortName + WHEN posMaster.orgChild4Id IS NULL THEN orgChild3.orgChild3ShortName + ELSE orgChild4.orgChild4ShortName + END, + posMaster.posMasterNo + ) AS posNo, + posMaster.isDirector AS isDirector, + posLevel.posLevelName AS posLevel, + posType.posTypeName AS posType, + posExecutive.posExecutiveName AS posExecutiveName, + orgRoot.isDeputy AS isDeputy, + orgChild1.isOfficer AS isOfficer, + posMaster.orgRevisionId AS orgRevisionId, + posMaster.orgRootId AS orgRootId, + posMaster.orgChild1Id AS orgChild1Id, + posMaster.orgChild2Id AS orgChild2Id, + posMaster.orgChild3Id AS orgChild3Id, + posMaster.orgChild4Id AS orgChild4Id, + CONCAT(posMaster.id, profile.id) AS \`key\`, + ( + SELECT actFullNameId + FROM view_director_acting AS acting + WHERE acting.Id = posMaster.current_holderId + AND acting.orgRootId = posMaster.orgRootId + AND (acting.orgChild1Id = posMaster.orgChild1Id OR acting.orgChild1Id IS NULL) + AND (acting.orgChild2Id = posMaster.orgChild2Id OR acting.orgChild2Id IS NULL) + AND (acting.orgChild3Id = posMaster.orgChild3Id OR acting.orgChild3Id IS NULL) + AND (acting.orgChild4Id = posMaster.orgChild4Id OR acting.orgChild4Id IS NULL) + LIMIT 1 + ) AS actFullNameId, + ( + SELECT actFullName + FROM view_director_acting AS acting + WHERE acting.Id = posMaster.current_holderId + AND acting.orgRootId = posMaster.orgRootId + AND (acting.orgChild1Id = posMaster.orgChild1Id OR acting.orgChild1Id IS NULL) + AND (acting.orgChild2Id = posMaster.orgChild2Id OR acting.orgChild2Id IS NULL) + AND (acting.orgChild3Id = posMaster.orgChild3Id OR acting.orgChild3Id IS NULL) + AND (acting.orgChild4Id = posMaster.orgChild4Id OR acting.orgChild4Id IS NULL) + LIMIT 1 + ) AS actFullName + FROM + posMaster + JOIN profile ON posMaster.current_holderId = profile.id + LEFT JOIN orgRoot ON posMaster.orgRootId = orgRoot.id + LEFT JOIN orgChild1 ON posMaster.orgChild1Id = orgChild1.id + LEFT JOIN orgChild2 ON posMaster.orgChild2Id = orgChild2.id + LEFT JOIN orgChild3 ON posMaster.orgChild3Id = orgChild3.id + LEFT JOIN orgChild4 ON posMaster.orgChild4Id = orgChild4.id + JOIN posLevel ON profile.posLevelId = posLevel.id + JOIN posType ON profile.posTypeId = posType.id + LEFT JOIN position ON posMaster.id = position.posMasterId + LEFT JOIN posExecutive ON position.posExecutiveId = posExecutive.id + INNER JOIN orgRevision ON posMaster.orgRevisionId = orgRevision.id + WHERE + (position.positionIsSelected = TRUE) + AND (orgRevision.orgRevisionIsCurrent = TRUE + AND orgRevision.orgRevisionIsDraft = FALSE)`); + + // await queryRunner.query(`INSERT INTO \`hrms_organization\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["hrms_organization", "VIEW", "view_director", "SELECT \n profile.id AS Id,\n profile.prefix AS prefix,\n profile.firstName AS firstName,\n profile.lastName AS lastName,\n profile.citizenId AS citizenId,\n profile.position AS position,\n CONCAT(\n CASE \n WHEN posMaster.orgChild1Id IS NULL THEN orgRoot.orgRootShortName\n WHEN posMaster.orgChild2Id IS NULL THEN orgChild1.orgChild1ShortName\n WHEN posMaster.orgChild3Id IS NULL THEN orgChild2.orgChild2ShortName\n WHEN posMaster.orgChild4Id IS NULL THEN orgChild3.orgChild3ShortName\n ELSE orgChild4.orgChild4ShortName\n END,\n posMaster.posMasterNo\n ) AS posNo,\n posMaster.isDirector AS isDirector,\n posLevel.posLevelName AS posLevel,\n posType.posTypeName AS posType,\n posExecutive.posExecutiveName AS posExecutiveName,\n orgRoot.isDeputy AS isDeputy,\n orgChild1.isOfficer AS isOfficer,\n posMaster.orgRevisionId AS orgRevisionId,\n posMaster.orgRootId AS orgRootId,\n posMaster.orgChild1Id AS orgChild1Id,\n posMaster.orgChild2Id AS orgChild2Id,\n posMaster.orgChild3Id AS orgChild3Id,\n posMaster.orgChild4Id AS orgChild4Id,\n CONCAT(posMaster.id, profile.id) AS `key`,\n (\n SELECT actFullNameId \n FROM view_director_acting AS acting\n WHERE acting.Id = posMaster.current_holderId \n AND acting.orgRootId = posMaster.orgRootId \n AND (acting.orgChild1Id = posMaster.orgChild1Id OR acting.orgChild1Id IS NULL)\n AND (acting.orgChild2Id = posMaster.orgChild2Id OR acting.orgChild2Id IS NULL)\n AND (acting.orgChild3Id = posMaster.orgChild3Id OR acting.orgChild3Id IS NULL)\n AND (acting.orgChild4Id = posMaster.orgChild4Id OR acting.orgChild4Id IS NULL)\n LIMIT 1\n ) AS actFullNameId,\n (\n SELECT actFullName \n FROM view_director_acting AS acting\n WHERE acting.Id = posMaster.current_holderId \n AND acting.orgRootId = posMaster.orgRootId \n AND (acting.orgChild1Id = posMaster.orgChild1Id OR acting.orgChild1Id IS NULL)\n AND (acting.orgChild2Id = posMaster.orgChild2Id OR acting.orgChild2Id IS NULL)\n AND (acting.orgChild3Id = posMaster.orgChild3Id OR acting.orgChild3Id IS NULL)\n AND (acting.orgChild4Id = posMaster.orgChild4Id OR acting.orgChild4Id IS NULL)\n LIMIT 1\n ) AS actFullName\n FROM\n posMaster\n JOIN profile ON posMaster.current_holderId = profile.id\n LEFT JOIN orgRoot ON posMaster.orgRootId = orgRoot.id\n LEFT JOIN orgChild1 ON posMaster.orgChild1Id = orgChild1.id\n LEFT JOIN orgChild2 ON posMaster.orgChild2Id = orgChild2.id\n LEFT JOIN orgChild3 ON posMaster.orgChild3Id = orgChild3.id\n LEFT JOIN orgChild4 ON posMaster.orgChild4Id = orgChild4.id\n JOIN posLevel ON profile.posLevelId = posLevel.id\n JOIN posType ON profile.posTypeId = posType.id\n LEFT JOIN position ON posMaster.id = position.posMasterId\n LEFT JOIN posExecutive ON position.posExecutiveId = posExecutive.id\n INNER JOIN orgRevision ON posMaster.orgRevisionId = orgRevision.id\n WHERE\n (position.positionIsSelected = TRUE)\n AND (orgRevision.orgRevisionIsCurrent = TRUE\n AND orgRevision.orgRevisionIsDraft = FALSE)"]); + } + +} From 13ed3450ddfbad17a52bf2d095aecf364d157ef1 Mon Sep 17 00:00:00 2001 From: Adisak Date: Fri, 7 Nov 2025 13:57:03 +0700 Subject: [PATCH 8/9] #208 and update migration --- src/controllers/ProfileController.ts | 12 +++++++----- src/entities/view/viewDirector.ts | 2 ++ ...1-update_viewDirectior_and_viewDirectiorActing.ts | 2 ++ 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 7a114b6e..e907d801 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -2886,8 +2886,8 @@ export class ProfileController extends Controller { } else if ((posMaster?.current_holder?.posLevel?.posLevelAuthority ?? null) == "GOVERNOR") { return new HttpSuccess({ data: [], total: 0 }); } - console.log(posMaster); - console.log(posMaster.id); + // console.log(posMaster); + // console.log(posMaster.id); let condition: any = { orgRootId: posMaster.orgRootId, id: Not(posMaster.current_holderId || ""), @@ -2917,9 +2917,9 @@ export class ProfileController extends Controller { condition.isDirector = true; conditionNow.isDirector = true; } - console.log(condition); - console.log("------------------"); - console.log(conditionNow); + // console.log(condition); + // console.log("------------------"); + // console.log(conditionNow); if (body.isAct == true) { const [lists, total] = await AppDataSource.getRepository(viewDirectorActing) .createQueryBuilder("viewDirectorActing") @@ -2928,6 +2928,7 @@ export class ProfileController extends Controller { qb.orWhere(condition).orWhere(conditionNow); }), ) + .andWhere("viewDirectorActing.isProbation = :isProbation", { isProbation: false }) .andWhere( new Brackets((qb) => { qb.orWhere( @@ -2992,6 +2993,7 @@ export class ProfileController extends Controller { qb.orWhere(condition).orWhere(conditionNow); }), ) + .andWhere("viewDirectorActing.isProbation = :isProbation", { isProbation: false }) .andWhere( new Brackets((qb) => { qb.orWhere( diff --git a/src/entities/view/viewDirector.ts b/src/entities/view/viewDirector.ts index d2ed5b65..717265e2 100644 --- a/src/entities/view/viewDirector.ts +++ b/src/entities/view/viewDirector.ts @@ -8,6 +8,8 @@ import { ViewColumn, ViewEntity } from "typeorm"; profile.lastName AS lastName, profile.citizenId AS citizenId, profile.position AS position, + profile.keycloak AS keycloakId, + profile.isProbation AS isProbation, CONCAT( CASE WHEN posMaster.orgChild1Id IS NULL THEN orgRoot.orgRootShortName diff --git a/src/migration/1762489522691-update_viewDirectior_and_viewDirectiorActing.ts b/src/migration/1762489522691-update_viewDirectior_and_viewDirectiorActing.ts index 26c26b8f..f3db9b44 100644 --- a/src/migration/1762489522691-update_viewDirectior_and_viewDirectiorActing.ts +++ b/src/migration/1762489522691-update_viewDirectior_and_viewDirectiorActing.ts @@ -73,6 +73,8 @@ export class UpdateViewDirectiorAndViewDirectiorActing1762489522691 implements M profile.lastName AS lastName, profile.citizenId AS citizenId, profile.position AS position, + profile.keycloak AS keycloakId, + profile.isProbation AS isProbation, CONCAT( CASE WHEN posMaster.orgChild1Id IS NULL THEN orgRoot.orgRootShortName From 7739af7d44ed4f36d43e0e4296b6cba475193caf Mon Sep 17 00:00:00 2001 From: Adisak Date: Fri, 7 Nov 2025 14:04:09 +0700 Subject: [PATCH 9/9] fix --- src/controllers/ProfileController.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index e907d801..57d618c6 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -2993,7 +2993,7 @@ export class ProfileController extends Controller { qb.orWhere(condition).orWhere(conditionNow); }), ) - .andWhere("viewDirectorActing.isProbation = :isProbation", { isProbation: false }) + .andWhere("viewDirector.isProbation = :isProbation", { isProbation: false }) .andWhere( new Brackets((qb) => { qb.orWhere(