From 91222163d3e34e38a617de3548139fa0c1ab0b67 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Thu, 1 Feb 2024 17:12:10 +0700 Subject: [PATCH] no message --- src/controllers/PositionController.ts | 91 +++++++++++++++------------ 1 file changed, 52 insertions(+), 39 deletions(-) diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index 4533b37a..c5e340b9 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -779,21 +779,22 @@ export class PositionController extends Controller { }; } const keywordCondition = {} - ? { - posMasterNoPrefix: Like(`%${body.keyword}%`), - positionName: Like(`%${body.keyword}%`), - posTypeName: Like(`%${body.keyword}%`), - posLevelName: Like(`%${body.keyword}%`), - } - : {}; - + ? { + posMasterNoPrefix: Like(`%${body.keyword}%`), + positionName: Like(`%${body.keyword}%`), + posTypeName: Like(`%${body.keyword}%`), + posLevelName: Like(`%${body.keyword}%`), + } + : {}; + const posMaster = await this.posMasterRepository.find({ where: { ...typeCondition, ...checkChildConditions, - ...keywordCondition, + // ...keywordCondition, }, order: { posMasterOrder: "ASC" }, + relations: ["orgRoot", "orgChild1", "orgChild2", "orgChild3", "orgChild4"], skip: (body.page - 1) * body.pageSize, take: body.pageSize, }); @@ -815,6 +816,20 @@ export class PositionController extends Controller { posMasterNoPrefix: posMaster.posMasterNoPrefix, posMasterNo: posMaster.posMasterNo, posMasterNoSuffix: posMaster.posMasterNoSuffix, + orgShortname: + body.type === 0 + ? posMaster.orgRoot.orgRootShortName + : body.type === 1 + ? posMaster.orgChild1.orgChild1ShortName + : body.type === 2 + ? posMaster.orgChild2.orgChild2ShortName + : body.type === 3 + ? posMaster.orgChild3.orgChild3ShortName + : body.type === 4 + ? posMaster.orgChild4.orgChild4ShortName + : "-", + // profileIdCurrentHolder: posMaster.profileIdCurrentHolder, + // profileIdNextHolder: posMaster.profileIdNextHolder, positions: positions.map((position) => ({ id: position.id, positionName: position.positionName, @@ -1004,27 +1019,27 @@ export class PositionController extends Controller { * @summary ORG_041 - เพิ่มตำแหน่งทางการบริหาร (ADMIN) #44 * */ - @Post("executive") - async createPosExecutive( + @Post("executive") + async createPosExecutive( @Body() - requestBody: CreatePosMaster, - @Request() request: { user: Record } - ) { + requestBody: CreatePosMaster, + @Request() request: { user: Record }, + ) { const posExecutive = Object.assign(new PosExecutive(), requestBody); if (!posExecutive) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } - try { - posExecutive.createdUserId = request.user.sub; - posExecutive.createdFullName = request.user.name; - posExecutive.lastUpdateUserId = request.user.sub; - posExecutive.lastUpdateFullName = request.user.name; - await this.posExecutiveRepository.save(posExecutive); - return new HttpSuccess(); - } catch (error) { - return error; - } + try { + posExecutive.createdUserId = request.user.sub; + posExecutive.createdFullName = request.user.name; + posExecutive.lastUpdateUserId = request.user.sub; + posExecutive.lastUpdateFullName = request.user.name; + await this.posExecutiveRepository.save(posExecutive); + return new HttpSuccess(); + } catch (error) { + return error; } + } /** * API แก้ไขตำแหน่งทางการบริหาร @@ -1033,28 +1048,27 @@ export class PositionController extends Controller { * * @param {string} id Id ตำแหน่งทางการบริหาร */ - @Put("executive/{id}") - async updatePosExecutive( + @Put("executive/{id}") + async updatePosExecutive( @Path() id: string, @Body() - requestBody: CreatePosMaster, - @Request() request: { user: Record } - ) { + requestBody: CreatePosMaster, + @Request() request: { user: Record }, + ) { const posExecutive = Object.assign(new PosExecutive(), requestBody); if (!posExecutive) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id); } - try { - posExecutive.lastUpdateUserId = request.user.sub; - posExecutive.lastUpdateFullName = request.user.name; - await this.posExecutiveRepository.save(posExecutive); - return new HttpSuccess(); - } catch (error) { - return error; - } + try { + posExecutive.lastUpdateUserId = request.user.sub; + posExecutive.lastUpdateFullName = request.user.name; + await this.posExecutiveRepository.save(posExecutive); + return new HttpSuccess(); + } catch (error) { + return error; } + } - /** * API ลบอัตรากำลัง * @@ -1078,5 +1092,4 @@ export class PositionController extends Controller { return error; } } - }