From cd416a4ebb195d8e73cdb1653d7a5ea4259dad83 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Mon, 29 Jan 2024 17:22:05 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89path=20root?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/OrgRootController.ts | 55 +++++++++++++++++----------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/src/controllers/OrgRootController.ts b/src/controllers/OrgRootController.ts index 10b9382d..ea059974 100644 --- a/src/controllers/OrgRootController.ts +++ b/src/controllers/OrgRootController.ts @@ -21,7 +21,7 @@ import HttpError from "../interfaces/http-error"; import HttpStatusCode from "../interfaces/http-status"; import { OrgRevision } from "../entities/OrgRevision"; -@Route("api/v1/org") +@Route("api/v1/org/root") @Tags("OrgRoot") @Security("bearerAuth") export class OrgRootController extends Controller { @@ -36,7 +36,7 @@ export class OrgRootController extends Controller { * * @param {string} id Id Root */ - @Get("root/{id}") + @Get("{id}") async GetRoot(@Path() id: string) { try { const orgRoot = await this.orgRootRepository.findOne({ where: { id } }); @@ -44,30 +44,30 @@ export class OrgRootController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล โครงสร้างระดับ Root"); } const getOrgRoot = { - "orgRootId" : orgRoot.id, - "orgRootName" : orgRoot.orgRootName, - "orgRootShortName" : orgRoot.orgRootShortName, - "orgRootCode" : orgRoot.orgRootCode, - "orgRootOrder" : orgRoot.orgRootOrder, - "orgRootPhoneEx" : orgRoot.orgRootPhoneEx, - "orgRootPhoneIn" : orgRoot.orgRootPhoneIn, - "orgRootFax" : orgRoot.orgRootFax, - "orgRevisionId" : orgRoot.orgRevisionId, - "orgCode" : orgRoot.orgRootCode+"00" - } + orgRootId: orgRoot.id, + orgRootName: orgRoot.orgRootName, + orgRootShortName: orgRoot.orgRootShortName, + orgRootCode: orgRoot.orgRootCode, + orgRootOrder: orgRoot.orgRootOrder, + orgRootPhoneEx: orgRoot.orgRootPhoneEx, + orgRootPhoneIn: orgRoot.orgRootPhoneIn, + orgRootFax: orgRoot.orgRootFax, + orgRevisionId: orgRoot.orgRevisionId, + orgCode: orgRoot.orgRootCode + "00", + }; return new HttpSuccess(getOrgRoot); } catch (error) { return error; } } - + /** * สร้างโครงสร้างระดับ Root * * @summary ORG_001 - สร้างโครงสร้างระดับ Root (ADMIN) #1 * */ - @Post("root") + @Post() @Example([ { orgRootName: "string", //ชื่อหน่วยงาน @@ -104,7 +104,11 @@ export class OrgRootController extends Controller { } const orgRevision = await this.orgRevisionRepository.findOne({ - where: { id: requestBody.orgRevisionId, orgRevisionIsDraft: true, orgRevisionIsCurrent: false }, + where: { + id: requestBody.orgRevisionId, + orgRevisionIsDraft: true, + orgRevisionIsCurrent: false, + }, }); if (orgRevision) { @@ -131,7 +135,7 @@ export class OrgRootController extends Controller { * * @param {string} id Guid, *Id root */ - @Put("root/{id}") + @Put("{id}") @Example([ { orgRootName: "string", //ชื่อหน่วยงาน @@ -156,7 +160,11 @@ export class OrgRootController extends Controller { } const revisionIdExits = await this.orgRevisionRepository.findOne({ - where: { id: requestBody.orgRevisionId, orgRevisionIsDraft: true, orgRevisionIsCurrent: false }, + where: { + id: requestBody.orgRevisionId, + orgRevisionIsDraft: true, + orgRevisionIsCurrent: false, + }, }); if (!revisionIdExits) { throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. RevisionId"); @@ -193,7 +201,7 @@ export class OrgRootController extends Controller { * * @param {string} id Guid, *Id root */ - @Delete("root/{id}") + @Delete("{id}") async delete(@Path() id: string) { try { const orgRoot = await this.orgRootRepository.findOne({ where: { id } }); @@ -202,10 +210,13 @@ export class OrgRootController extends Controller { } const orgChild1 = await this.orgChild1Repository.findOne({ where: { orgRootId: id } }); - if(orgChild1 != null){ - throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR,"ไม่สามารถลบข้อมูลได้เมื่อมีข้อมูลโครงสร้างระดับ1",); + if (orgChild1 != null) { + throw new HttpError( + HttpStatusCode.INTERNAL_SERVER_ERROR, + "ไม่สามารถลบข้อมูลได้เมื่อมีข้อมูลโครงสร้างระดับ1", + ); } - + const revisionIdExits = await this.orgRevisionRepository.findOne({ where: { id: orgRoot.orgRevisionId, orgRevisionIsDraft: true, orgRevisionIsCurrent: false }, });