From a4786c4bb93c69e34198d21e6c2da415674a4f81 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Fri, 2 Feb 2024 13:16:40 +0700 Subject: [PATCH] org_041-044 posExecutive --- src/controllers/PosExecutiveController.ts | 41 +++++++++++++++++++---- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/src/controllers/PosExecutiveController.ts b/src/controllers/PosExecutiveController.ts index 3e360b45..0bfcecf4 100644 --- a/src/controllers/PosExecutiveController.ts +++ b/src/controllers/PosExecutiveController.ts @@ -11,13 +11,13 @@ import { Request, SuccessResponse, Response, + Get, } from "tsoa"; import { AppDataSource } from "../database/data-source"; import HttpSuccess from "../interfaces/http-success"; import HttpStatusCode from "../interfaces/http-status"; -import { PosExecutive } from "../entities/PosExecutive"; import HttpError from "../interfaces/http-error"; -import { CreatePosMaster, PosMaster } from "../entities/PosMaster"; +import { CreatePosExecutive, PosExecutive } from "../entities/PosExecutive"; import { Position } from "../entities/Position"; @Route("api/v1/org/pos") @Tags("PosExecutive") @@ -40,7 +40,7 @@ export class PosExecutiveController extends Controller { @Post("executive") async createPosExecutive( @Body() - requestBody: CreatePosMaster, + requestBody: CreatePosExecutive, @Request() request: { user: Record }, ) { const posExecutive = Object.assign(new PosExecutive(), requestBody); @@ -70,16 +70,17 @@ export class PosExecutiveController extends Controller { async updatePosExecutive( @Path() id: string, @Body() - requestBody: CreatePosMaster, + requestBody: CreatePosExecutive, @Request() request: { user: Record }, ) { - const posExecutive = Object.assign(new PosExecutive(), requestBody); + const posExecutive = await this.posExecutiveRepository.findOne({where: {id: id}}); if (!posExecutive) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id); } try { posExecutive.lastUpdateUserId = request.user.sub; posExecutive.lastUpdateFullName = request.user.name; + this.posExecutiveRepository.merge(posExecutive, requestBody); await this.posExecutiveRepository.save(posExecutive); return new HttpSuccess(); } catch (error) { @@ -92,7 +93,7 @@ export class PosExecutiveController extends Controller { * * @summary ORG_043 - ลบตำแหน่งทางการบริหาร (ADMIN) #46 * - * @param {string} id Id ตำแหน่ง + * @param {string} id Id ตำแหน่งทางการบริหาร */ @Delete("executive/{id}") async deletePosExecutive(@Path() id: string) { @@ -110,4 +111,32 @@ export class PosExecutiveController extends Controller { return error; } } + + /** + * API รายละเอียดตำแหน่งทางการบริหาร + * + * @summary ORG_044 - รายละเอียดตำแหน่งทางการบริหาร (ADMIN) #47 + * + * @param {string} id Id ตำแหน่งทางการบริหาร + */ + @Get("executive/{id}") + async detailPosExecutive(@Path() id: string) { + + const posExecutive = await this.posExecutiveRepository.findOne({ + where: { id }, + select:[ + "id", + "posExecutiveName", + "posExecutivePriority" + ] + }); + if (!posExecutive) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + } + try { + return new HttpSuccess(posExecutive); + } catch (error) { + return error; + } + } }