From 9750b6225536465b2809326124120e7a7d511293 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Thu, 15 Feb 2024 09:24:27 +0700 Subject: [PATCH 1/7] no message --- src/controllers/OrganizationController.ts | 40 +++++++++++++++-------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/src/controllers/OrganizationController.ts b/src/controllers/OrganizationController.ts index e6e01f5f..e03f8e0c 100644 --- a/src/controllers/OrganizationController.ts +++ b/src/controllers/OrganizationController.ts @@ -1692,6 +1692,7 @@ export class OrganizationController extends Controller { const formattedData = { departmentName: "กรุงเทพมหานคร", deptID: data.id, + type: 0, // heads: totalPositionCount: await this.posMasterRepository.count({ where: { orgRevisionId: data.id }, @@ -1729,6 +1730,7 @@ export class OrganizationController extends Controller { return { departmentName: orgRoot.orgRootName, deptID: orgRoot.id, + type: 1, // heads: totalPositionCount: await this.posMasterRepository.count({ where: { orgRevisionId: data.id, orgRootId: orgRoot.id }, @@ -1769,6 +1771,7 @@ export class OrganizationController extends Controller { .map(async (orgChild1) => ({ departmentName: orgChild1.orgChild1Name, deptID: orgChild1.id, + type: 2, // heads: totalPositionCount: await this.posMasterRepository.count({ where: { @@ -1817,6 +1820,7 @@ export class OrganizationController extends Controller { .map(async (orgChild2) => ({ departmentName: orgChild2.orgChild2Name, deptID: orgChild2.id, + type: 3, // heads: totalPositionCount: await this.posMasterRepository.count({ where: { @@ -1870,6 +1874,7 @@ export class OrganizationController extends Controller { .map(async (orgChild3) => ({ departmentName: orgChild3.orgChild3Name, deptID: orgChild3.id, + type: 4, // heads: totalPositionCount: await this.posMasterRepository.count({ where: { @@ -1929,9 +1934,9 @@ export class OrganizationController extends Controller { orgChild3.orgChild4s .sort((a, b) => a.orgChild4Order - b.orgChild4Order) .map(async (orgChild4) => ({ - orgTreeId: orgChild4.id, departmentName: orgChild4.orgChild4Name, deptID: orgChild4.id, + type: 5, // heads: totalPositionCount: await this.posMasterRepository.count({ @@ -2004,7 +2009,7 @@ export class OrganizationController extends Controller { }), ), }; - return new HttpSuccess(formattedData); + return new HttpSuccess([formattedData]); } case 1: { const data = await this.orgRootRepository.findOne({ @@ -2024,6 +2029,7 @@ export class OrganizationController extends Controller { const formattedData = { departmentName: data.orgRootName, deptID: data.id, + type: 1, // heads: totalPositionCount: await this.posMasterRepository.count({ where: { orgRootId: data.id }, @@ -2061,6 +2067,7 @@ export class OrganizationController extends Controller { .map(async (orgChild1) => ({ departmentName: orgChild1.orgChild1Name, deptID: orgChild1.id, + type: 2, // heads: totalPositionCount: await this.posMasterRepository.count({ where: { orgRootId: data.id, orgChild1Id: orgChild1.id }, @@ -2101,6 +2108,7 @@ export class OrganizationController extends Controller { .map(async (orgChild2) => ({ departmentName: orgChild2.orgChild2Name, deptID: orgChild2.id, + type: 3, // heads: totalPositionCount: await this.posMasterRepository.count({ where: { @@ -2149,6 +2157,7 @@ export class OrganizationController extends Controller { .map(async (orgChild3) => ({ departmentName: orgChild3.orgChild3Name, deptID: orgChild3.id, + type: 4, // heads: totalPositionCount: await this.posMasterRepository.count({ where: { @@ -2200,9 +2209,9 @@ export class OrganizationController extends Controller { orgChild3.orgChild4s .sort((a, b) => a.orgChild4Order - b.orgChild4Order) .map(async (orgChild4) => ({ - orgTreeId: orgChild4.id, departmentName: orgChild4.orgChild4Name, deptID: orgChild4.id, + type: 5, // heads: totalPositionCount: await this.posMasterRepository.count({ where: { @@ -2265,7 +2274,7 @@ export class OrganizationController extends Controller { })), ), }; - return new HttpSuccess(formattedData); + return new HttpSuccess([formattedData]); } case 2: { const data = await this.child1Repository.findOne({ @@ -2284,6 +2293,7 @@ export class OrganizationController extends Controller { const formattedData = { departmentName: data.orgChild1Name, deptID: data.id, + type: 2, // heads: totalPositionCount: await this.posMasterRepository.count({ where: { orgRevisionId: data.id }, @@ -2321,6 +2331,7 @@ export class OrganizationController extends Controller { .map(async (orgChild2) => ({ departmentName: orgChild2.orgChild2Name, deptID: orgChild2.id, + type: 3, // heads: totalPositionCount: await this.posMasterRepository.count({ where: { orgChild1Id: data.id, orgChild2Id: orgChild2.id }, @@ -2361,6 +2372,7 @@ export class OrganizationController extends Controller { .map(async (orgChild3) => ({ departmentName: orgChild3.orgChild3Name, deptID: orgChild3.id, + type: 4, // heads: totalPositionCount: await this.posMasterRepository.count({ where: { @@ -2407,9 +2419,9 @@ export class OrganizationController extends Controller { orgChild3.orgChild4s .sort((a, b) => a.orgChild4Order - b.orgChild4Order) .map(async (orgChild4) => ({ - orgTreeId: orgChild4.id, departmentName: orgChild4.orgChild4Name, deptID: orgChild4.id, + type: 5, // heads: totalPositionCount: await this.posMasterRepository.count({ where: { @@ -2464,7 +2476,7 @@ export class OrganizationController extends Controller { })), ), }; - return new HttpSuccess(formattedData); + return new HttpSuccess([formattedData]); } case 3: { const data = await this.child2Repository.findOne({ @@ -2478,6 +2490,7 @@ export class OrganizationController extends Controller { const formattedData = { departmentName: data.orgChild2Name, deptID: data.id, + type: 3, // heads: totalPositionCount: await this.posMasterRepository.count({ where: { orgChild2Id: data.id }, @@ -2515,6 +2528,7 @@ export class OrganizationController extends Controller { .map(async (orgChild3) => ({ departmentName: orgChild3.orgChild3Name, deptID: orgChild3.id, + type: 4, // heads: totalPositionCount: await this.posMasterRepository.count({ where: { orgChild2Id: data.id, orgChild3Id: orgChild3.id }, @@ -2553,9 +2567,9 @@ export class OrganizationController extends Controller { orgChild3.orgChild4s .sort((a, b) => a.orgChild4Order - b.orgChild4Order) .map(async (orgChild4) => ({ - orgTreeId: orgChild4.id, departmentName: orgChild4.orgChild4Name, deptID: orgChild4.id, + type: 5, // heads: totalPositionCount: await this.posMasterRepository.count({ where: { @@ -2603,7 +2617,7 @@ export class OrganizationController extends Controller { })), ), }; - return new HttpSuccess(formattedData); + return new HttpSuccess([formattedData]); } case 4: { const data = await this.child3Repository.findOne({ @@ -2615,9 +2629,9 @@ export class OrganizationController extends Controller { } const formattedData = { - orgTreeId: data.id, departmentName: data.orgChild3Name, deptID: data.id, + type: 4, // heads: totalPositionCount: await this.posMasterRepository.count({ where: { orgChild3Id: data.id }, @@ -2653,9 +2667,9 @@ export class OrganizationController extends Controller { data.orgChild4s .sort((a, b) => a.orgChild4Order - b.orgChild4Order) .map(async (orgChild4) => ({ - orgTreeId: orgChild4.id, departmentName: orgChild4.orgChild4Name, deptID: orgChild4.id, + type: 5, // heads: totalPositionCount: await this.posMasterRepository.count({ where: { orgChild3Id: data.id, orgChild4Id: orgChild4.id }, @@ -2693,7 +2707,7 @@ export class OrganizationController extends Controller { })), ), }; - return new HttpSuccess(formattedData); + return new HttpSuccess([formattedData]); } case 5: { const data = await this.child4Repository.findOne({ @@ -2705,9 +2719,9 @@ export class OrganizationController extends Controller { } const formattedData = { - orgTreeId: data.id, departmentName: data.orgChild4Name, deptID: data.id, + type: 5, // heads: totalPositionCount: await this.posMasterRepository.count({ where: { orgChild4Id: data.id }, @@ -2739,7 +2753,7 @@ export class OrganizationController extends Controller { // }, // }), }; - return new HttpSuccess(formattedData); + return new HttpSuccess([formattedData]); } default: throw new HttpError(HttpStatusCode.NOT_FOUND, "not found type: "); From 507b527c5e86a9969683b9aceff0bb8899f5c4f6 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Thu, 15 Feb 2024 09:26:40 +0700 Subject: [PATCH 2/7] no message --- src/controllers/OrganizationController.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/OrganizationController.ts b/src/controllers/OrganizationController.ts index a3fd7da8..eb937777 100644 --- a/src/controllers/OrganizationController.ts +++ b/src/controllers/OrganizationController.ts @@ -1692,7 +1692,7 @@ export class OrganizationController extends Controller { const formattedData = { departmentName: data.orgRevisionName, deptID: data.id, - type: data.posMasters.length, + type: 0, // heads: totalPositionCount: await this.posMasterRepository.count({ where: { orgRevisionId: data.id }, From edd5fdb3aa963bee9296ad1518cd984b8c5b09e4 Mon Sep 17 00:00:00 2001 From: Bright Date: Thu, 15 Feb 2024 09:39:13 +0700 Subject: [PATCH 3/7] add fields api master/list --- src/controllers/PositionController.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index 61df770a..9be38242 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -33,6 +33,7 @@ import { OrgChild2 } from "../entities/OrgChild2"; import { OrgChild3 } from "../entities/OrgChild3"; import { OrgChild4 } from "../entities/OrgChild4"; import { Position } from "../entities/Position"; +import { Profile } from "../entities/Profile"; @Route("api/v1/org/pos") @Tags("Position") // @Security("bearerAuth") @@ -48,7 +49,7 @@ export class PositionController extends Controller { private posDictRepository = AppDataSource.getRepository(PosDict); private posMasterRepository = AppDataSource.getRepository(PosMaster); private positionRepository = AppDataSource.getRepository(Position); - + private profileRepository = AppDataSource.getRepository(Profile); private orgRevisionRepository = AppDataSource.getRepository(OrgRevision); private orgRootRepository = AppDataSource.getRepository(OrgRoot); private child1Repository = AppDataSource.getRepository(OrgChild1); @@ -887,6 +888,15 @@ export class PositionController extends Controller { }, relations: ["posLevel", "posType", "posExecutive"], }); + const profile = await this.profileRepository.findOne({ + where: { id: String(posMaster.next_holderId) } + }) + const type = await this.posTypeRepository.findOne({ + where: { id: String(profile?.posTypeId) } + }) + const level = await this.posLevelRepository.findOne({ + where: { id: String(profile?.posLevelId)} + }) let shortName = ""; @@ -953,6 +963,10 @@ export class PositionController extends Controller { ? null : `${posMaster.next_holder.prefix}${posMaster.next_holder.firstName} ${posMaster.next_holder.lastName}`, orgShortname: shortName, + isSit: posMaster.isSit, + positionNextHolder: profile == null || profile.position == null? null : profile.position, + postypeNextHolder: type == null || type.posTypeName == null ? null : type.posTypeName, + poslevelNextHolder: level == null || level.posLevelName == null ? null : level.posLevelName, positions: positions.map((position) => ({ id: position.id, positionName: position.positionName, From 951b5a936e56e5c13808ac688facc99300ce517b Mon Sep 17 00:00:00 2001 From: Kittapath Date: Thu, 15 Feb 2024 09:41:27 +0700 Subject: [PATCH 4/7] no message --- src/controllers/OrganizationController.ts | 2 +- src/controllers/PositionController.ts | 162 ++++++++++++---------- 2 files changed, 91 insertions(+), 73 deletions(-) diff --git a/src/controllers/OrganizationController.ts b/src/controllers/OrganizationController.ts index eb937777..4f2ecdfb 100644 --- a/src/controllers/OrganizationController.ts +++ b/src/controllers/OrganizationController.ts @@ -33,7 +33,7 @@ import { log } from "console"; @Route("api/v1/org") @Tags("Organization") -// @Security("bearerAuth") +@Security("bearerAuth") @Response( HttpStatusCode.INTERNAL_SERVER_ERROR, "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง", diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index 61df770a..2fe69e48 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -24,7 +24,7 @@ import { PosType } from "../entities/PosType"; import { PosLevel } from "../entities/PosLevel"; import { CreatePosDict, PosDict } from "../entities/PosDict"; import HttpError from "../interfaces/http-error"; -import { Equal, ILike, In, IsNull, Like, Not ,Brackets } from "typeorm"; +import { Equal, ILike, In, IsNull, Like, Not, Brackets } from "typeorm"; import { CreatePosMaster, PosMaster } from "../entities/PosMaster"; import { OrgRevision } from "../entities/OrgRevision"; import { OrgRoot } from "../entities/OrgRoot"; @@ -35,7 +35,7 @@ import { OrgChild4 } from "../entities/OrgChild4"; import { Position } from "../entities/Position"; @Route("api/v1/org/pos") @Tags("Position") -// @Security("bearerAuth") +@Security("bearerAuth") @Response( HttpStatusCode.INTERNAL_SERVER_ERROR, "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง", @@ -112,52 +112,75 @@ export class PositionController extends Controller { } const chk_posDictName = await this.posDictRepository.findOne({ - where: { posDictName: posDict.posDictName } - }) - if(chk_posDictName){ - throw new HttpError(HttpStatusCode.NOT_FOUND, "ตำแหน่งในสายงาน: " + chk_posDictName.posDictName + " มีอยู่ในระบบแล้ว"); + where: { posDictName: posDict.posDictName }, + }); + if (chk_posDictName) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ตำแหน่งในสายงาน: " + chk_posDictName.posDictName + " มีอยู่ในระบบแล้ว", + ); } const chk_posDictField = await this.posDictRepository.findOne({ - where: { posDictField: posDict.posDictField } - }) - if(chk_posDictField){ - throw new HttpError(HttpStatusCode.NOT_FOUND, "สายงาน: " + chk_posDictField.posDictField + " มีอยู่ในระบบแล้ว"); + where: { posDictField: posDict.posDictField }, + }); + if (chk_posDictField) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "สายงาน: " + chk_posDictField.posDictField + " มีอยู่ในระบบแล้ว", + ); } const chk_posTypeId = await this.posDictRepository.findOne({ - where: { posTypeId: posDict.posTypeId } - }) - if(chk_posTypeId){ - throw new HttpError(HttpStatusCode.NOT_FOUND, "ตำแหน่งประเภท: " + chk_posTypeId.posTypeId + " มีอยู่ในระบบแล้ว"); + where: { posTypeId: posDict.posTypeId }, + }); + if (chk_posTypeId) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ตำแหน่งประเภท: " + chk_posTypeId.posTypeId + " มีอยู่ในระบบแล้ว", + ); } const chk_posLevelId = await this.posDictRepository.findOne({ - where: { posLevelId: posDict.posLevelId } - }) - if(chk_posLevelId){ - throw new HttpError(HttpStatusCode.NOT_FOUND, "ระดับตำแหน่ง: " + chk_posLevelId.posLevelId + " มีอยู่ในระบบแล้ว"); + where: { posLevelId: posDict.posLevelId }, + }); + if (chk_posLevelId) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ระดับตำแหน่ง: " + chk_posLevelId.posLevelId + " มีอยู่ในระบบแล้ว", + ); } const chk_posExecutiveId = await this.posDictRepository.findOne({ - where: { posExecutiveId: String(posDict.posExecutiveId) } - }) - if(chk_posExecutiveId){ - throw new HttpError(HttpStatusCode.NOT_FOUND, "ตำแหน่งทางการบริหาร: " + chk_posExecutiveId.posExecutiveId + " มีอยู่ในระบบแล้ว"); + where: { posExecutiveId: String(posDict.posExecutiveId) }, + }); + if (chk_posExecutiveId) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ตำแหน่งทางการบริหาร: " + chk_posExecutiveId.posExecutiveId + " มีอยู่ในระบบแล้ว", + ); } const chk_posDictExecutiveField = await this.posDictRepository.findOne({ - where: { posDictExecutiveField: posDict.posDictExecutiveField } - }) - if(chk_posDictExecutiveField){ - throw new HttpError(HttpStatusCode.NOT_FOUND, "ด้านทางการบริหาร: " + chk_posDictExecutiveField.posDictExecutiveField + " มีอยู่ในระบบแล้ว"); + where: { posDictExecutiveField: posDict.posDictExecutiveField }, + }); + if (chk_posDictExecutiveField) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ด้านทางการบริหาร: " + + chk_posDictExecutiveField.posDictExecutiveField + + " มีอยู่ในระบบแล้ว", + ); } - const chk_posDictArea= await this.posDictRepository.findOne({ - where: { posDictArea: posDict.posDictArea } - }) - if(chk_posDictArea){ - throw new HttpError(HttpStatusCode.NOT_FOUND, "ด้าน/สาขา: " + chk_posDictArea.posDictArea + " มีอยู่ในระบบแล้ว"); + const chk_posDictArea = await this.posDictRepository.findOne({ + where: { posDictArea: posDict.posDictArea }, + }); + if (chk_posDictArea) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ด้าน/สาขา: " + chk_posDictArea.posDictArea + " มีอยู่ในระบบแล้ว", + ); } try { @@ -650,6 +673,7 @@ export class PositionController extends Controller { const positions = await this.positionRepository.find({ where: { posMasterId: posMaster.id }, relations: ["posType", "posLevel", "posExecutive"], + order: { lastUpdatedAt: "ASC" }, }); const formattedData = { id: posMaster.id, @@ -808,19 +832,17 @@ export class PositionController extends Controller { } masterId = [...new Set(masterId)]; } - + const conditions = [ { ...checkChildConditions, ...typeCondition, - ...(body.keyword && ( - masterId.length > 0 - ? { id: In(masterId)} - : { posMasterNo: Like(`%${body.keyword}%`) } - - )), + ...(body.keyword && + (masterId.length > 0 + ? { id: In(masterId) } + : { posMasterNo: Like(`%${body.keyword}%`) })), }, - ] + ]; // if (body.keyword) { // conditions.push({ @@ -831,7 +853,7 @@ export class PositionController extends Controller { // const [posMaster, total] = await this.posMasterRepository.findAndCount({ // where: conditions, - // order: { posMasterOrder: "ASC" }, + // order: { posMasterOrder: "ASC" }, // relations: [ // "orgRoot", // "orgChild1", @@ -846,38 +868,34 @@ export class PositionController extends Controller { // }); const [posMaster, total] = await AppDataSource.getRepository(PosMaster) - .createQueryBuilder('posMaster') - .leftJoinAndSelect('posMaster.orgRoot', 'orgRoot') - .leftJoinAndSelect('posMaster.orgChild1', 'orgChild1') - .leftJoinAndSelect('posMaster.orgChild2', 'orgChild2') - .leftJoinAndSelect('posMaster.orgChild3', 'orgChild3') - .leftJoinAndSelect('posMaster.orgChild4', 'orgChild4') - .leftJoinAndSelect('posMaster.current_holder', 'current_holder') - .leftJoinAndSelect('posMaster.next_holder', 'next_holder') - .where(conditions) - // .orWhere('(current_holder.prefix LIKE :keyword OR current_holder.firstName LIKE :keyword OR current_holder.lastName LIKE :keyword)', { keyword: `%${body.keyword}%` }) - .orWhere( - new Brackets((qb) => { - qb.where( - body.keyword != null && body.keyword != "" - ? "current_holder.prefix LIKE :keyword OR current_holder.firstName LIKE :keyword OR current_holder.lastName LIKE :keyword OR :keyword LIKE current_holder.prefix OR :keyword LIKE current_holder.firstName OR :keyword LIKE current_holder.lastName" - : "1=1", - { - keyword: `%${body.keyword}%`, - }, - ) - .andWhere( - checkChildConditions - ) - .andWhere( - typeCondition - ); - }) - ) - .orderBy('posMaster.posMasterOrder', 'ASC') - .skip((body.page - 1) * body.pageSize) - .take(body.pageSize) - .getManyAndCount(); + .createQueryBuilder("posMaster") + .leftJoinAndSelect("posMaster.orgRoot", "orgRoot") + .leftJoinAndSelect("posMaster.orgChild1", "orgChild1") + .leftJoinAndSelect("posMaster.orgChild2", "orgChild2") + .leftJoinAndSelect("posMaster.orgChild3", "orgChild3") + .leftJoinAndSelect("posMaster.orgChild4", "orgChild4") + .leftJoinAndSelect("posMaster.current_holder", "current_holder") + .leftJoinAndSelect("posMaster.next_holder", "next_holder") + .where(conditions) + // .orWhere('(current_holder.prefix LIKE :keyword OR current_holder.firstName LIKE :keyword OR current_holder.lastName LIKE :keyword)', { keyword: `%${body.keyword}%` }) + .orWhere( + new Brackets((qb) => { + qb.where( + body.keyword != null && body.keyword != "" + ? "current_holder.prefix LIKE :keyword OR current_holder.firstName LIKE :keyword OR current_holder.lastName LIKE :keyword OR :keyword LIKE current_holder.prefix OR :keyword LIKE current_holder.firstName OR :keyword LIKE current_holder.lastName" + : "1=1", + { + keyword: `%${body.keyword}%`, + }, + ) + .andWhere(checkChildConditions) + .andWhere(typeCondition); + }), + ) + .orderBy("posMaster.posMasterOrder", "ASC") + .skip((body.page - 1) * body.pageSize) + .take(body.pageSize) + .getManyAndCount(); const formattedData = await Promise.all( posMaster.map(async (posMaster) => { From 875627930910e42a1e11faa0b0413834cd3809d1 Mon Sep 17 00:00:00 2001 From: Bright Date: Thu, 15 Feb 2024 10:25:10 +0700 Subject: [PATCH 5/7] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B9=80?= =?UTF-8?q?=E0=B8=8A=E0=B9=87=E0=B8=84=E0=B8=8B=E0=B9=89=E0=B8=B3=20posDic?= =?UTF-8?q?t?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/PositionController.ts | 78 +++++---------------------- 1 file changed, 12 insertions(+), 66 deletions(-) diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index 02364f8e..b97728fd 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -112,75 +112,21 @@ export class PositionController extends Controller { } } - const chk_posDictName = await this.posDictRepository.findOne({ - where: { posDictName: posDict.posDictName }, + const rowRepeated = await this.posDictRepository.findOne({ + where: { + posDictName: Like(`%${posDict.posDictName.trim()}%`), + posDictField: Like(`%${posDict.posDictField.trim()}%`), + posTypeId: posDict.posTypeId, + posLevelId: posDict.posLevelId, + posExecutiveId: String(posDict.posExecutiveId), + posDictExecutiveField: Like(`%${posDict.posDictExecutiveField.trim()}%`), + posDictArea: Like(`%${posDict.posDictArea.trim()}%`) + }, }); - if (chk_posDictName) { + if (rowRepeated) { throw new HttpError( HttpStatusCode.NOT_FOUND, - "ตำแหน่งในสายงาน: " + chk_posDictName.posDictName + " มีอยู่ในระบบแล้ว", - ); - } - - const chk_posDictField = await this.posDictRepository.findOne({ - where: { posDictField: posDict.posDictField }, - }); - if (chk_posDictField) { - throw new HttpError( - HttpStatusCode.NOT_FOUND, - "สายงาน: " + chk_posDictField.posDictField + " มีอยู่ในระบบแล้ว", - ); - } - - const chk_posTypeId = await this.posDictRepository.findOne({ - where: { posTypeId: posDict.posTypeId }, - }); - if (chk_posTypeId) { - throw new HttpError( - HttpStatusCode.NOT_FOUND, - "ตำแหน่งประเภท: " + chk_posTypeId.posTypeId + " มีอยู่ในระบบแล้ว", - ); - } - - const chk_posLevelId = await this.posDictRepository.findOne({ - where: { posLevelId: posDict.posLevelId }, - }); - if (chk_posLevelId) { - throw new HttpError( - HttpStatusCode.NOT_FOUND, - "ระดับตำแหน่ง: " + chk_posLevelId.posLevelId + " มีอยู่ในระบบแล้ว", - ); - } - - const chk_posExecutiveId = await this.posDictRepository.findOne({ - where: { posExecutiveId: String(posDict.posExecutiveId) }, - }); - if (chk_posExecutiveId) { - throw new HttpError( - HttpStatusCode.NOT_FOUND, - "ตำแหน่งทางการบริหาร: " + chk_posExecutiveId.posExecutiveId + " มีอยู่ในระบบแล้ว", - ); - } - - const chk_posDictExecutiveField = await this.posDictRepository.findOne({ - where: { posDictExecutiveField: posDict.posDictExecutiveField }, - }); - if (chk_posDictExecutiveField) { - throw new HttpError( - HttpStatusCode.NOT_FOUND, - "ด้านทางการบริหาร: " + - chk_posDictExecutiveField.posDictExecutiveField + - " มีอยู่ในระบบแล้ว", - ); - } - - const chk_posDictArea = await this.posDictRepository.findOne({ - where: { posDictArea: posDict.posDictArea }, - }); - if (chk_posDictArea) { - throw new HttpError( - HttpStatusCode.NOT_FOUND, - "ด้าน/สาขา: " + chk_posDictArea.posDictArea + " มีอยู่ในระบบแล้ว", + "ข้อมูล Row นี้มีอยู่ในระบบแล้ว", ); } From d76af2c88cf8f7217a04189ac9b7fc7f7698be6d Mon Sep 17 00:00:00 2001 From: Kittapath Date: Thu, 15 Feb 2024 10:31:47 +0700 Subject: [PATCH 6/7] =?UTF-8?q?=E0=B9=80=E0=B8=8A=E0=B9=87=E0=B8=84?= =?UTF-8?q?=E0=B8=84=E0=B9=88=E0=B8=B2=E0=B8=8B=E0=B9=89=E0=B8=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/PositionController.ts | 33 +++++++++++++-------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index b97728fd..eae9dadf 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -113,21 +113,18 @@ export class PositionController extends Controller { } const rowRepeated = await this.posDictRepository.findOne({ - where: { - posDictName: Like(`%${posDict.posDictName.trim()}%`), - posDictField: Like(`%${posDict.posDictField.trim()}%`), + where: { + posDictName: posDict.posDictName, + posDictField: posDict.posDictField, posTypeId: posDict.posTypeId, posLevelId: posDict.posLevelId, posExecutiveId: String(posDict.posExecutiveId), - posDictExecutiveField: Like(`%${posDict.posDictExecutiveField.trim()}%`), - posDictArea: Like(`%${posDict.posDictArea.trim()}%`) + posDictExecutiveField: posDict.posDictExecutiveField, + posDictArea: posDict.posDictArea, }, }); if (rowRepeated) { - throw new HttpError( - HttpStatusCode.NOT_FOUND, - "ข้อมูล Row นี้มีอยู่ในระบบแล้ว", - ); + throw new HttpError(HttpStatusCode.NOT_FOUND, "ข้อมูล Row นี้มีอยู่ในระบบแล้ว"); } try { @@ -853,14 +850,14 @@ export class PositionController extends Controller { relations: ["posLevel", "posType", "posExecutive"], }); const profile = await this.profileRepository.findOne({ - where: { id: String(posMaster.next_holderId) } - }) + where: { id: String(posMaster.next_holderId) }, + }); const type = await this.posTypeRepository.findOne({ - where: { id: String(profile?.posTypeId) } - }) + where: { id: String(profile?.posTypeId) }, + }); const level = await this.posLevelRepository.findOne({ - where: { id: String(profile?.posLevelId)} - }) + where: { id: String(profile?.posLevelId) }, + }); let shortName = ""; @@ -928,9 +925,11 @@ export class PositionController extends Controller { : `${posMaster.next_holder.prefix}${posMaster.next_holder.firstName} ${posMaster.next_holder.lastName}`, orgShortname: shortName, isSit: posMaster.isSit, - positionNextHolder: profile == null || profile.position == null? null : profile.position, + positionNextHolder: + profile == null || profile.position == null ? null : profile.position, postypeNextHolder: type == null || type.posTypeName == null ? null : type.posTypeName, - poslevelNextHolder: level == null || level.posLevelName == null ? null : level.posLevelName, + poslevelNextHolder: + level == null || level.posLevelName == null ? null : level.posLevelName, positions: positions.map((position) => ({ id: position.id, positionName: position.positionName, From a1610880f03610accf8d379d84cd67708f51e7c1 Mon Sep 17 00:00:00 2001 From: Bright Date: Thu, 15 Feb 2024 12:13:34 +0700 Subject: [PATCH 7/7] =?UTF-8?q?=E0=B8=9B=E0=B8=A3=E0=B8=B1=E0=B8=9A=20api?= =?UTF-8?q?=20master/list?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/PositionController.ts | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index eae9dadf..08be12d2 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -849,9 +849,21 @@ export class PositionController extends Controller { }, relations: ["posLevel", "posType", "posExecutive"], }); - const profile = await this.profileRepository.findOne({ - where: { id: String(posMaster.next_holderId) }, - }); + + let profile: any; + const chkRevision = await this.orgRevisionRepository.findOne({ + where: { id: posMaster.orgRevisionId } + }) + if(chkRevision?.orgRevisionIsCurrent && !chkRevision?.orgRevisionIsDraft){ + profile = await this.profileRepository.findOne({ + where: { id: String(posMaster.current_holderId) }, + }); + } + else if(!chkRevision?.orgRevisionIsCurrent && chkRevision?.orgRevisionIsDraft){ + profile = await this.profileRepository.findOne({ + where: { id: String(posMaster.next_holderId) }, + }); + } const type = await this.posTypeRepository.findOne({ where: { id: String(profile?.posTypeId) }, }); @@ -925,10 +937,11 @@ export class PositionController extends Controller { : `${posMaster.next_holder.prefix}${posMaster.next_holder.firstName} ${posMaster.next_holder.lastName}`, orgShortname: shortName, isSit: posMaster.isSit, - positionNextHolder: + profilePosition: profile == null || profile.position == null ? null : profile.position, - postypeNextHolder: type == null || type.posTypeName == null ? null : type.posTypeName, - poslevelNextHolder: + profilePostype: + type == null || type.posTypeName == null ? null : type.posTypeName, + profilePoslevel: level == null || level.posLevelName == null ? null : level.posLevelName, positions: positions.map((position) => ({ id: position.id,