From 644a1e9b5de0f01d059c0faf1e08176f85793dcd Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Tue, 11 Jun 2024 16:33:51 +0700 Subject: [PATCH] fix --- src/controllers/AuthRoleAttrController.ts | 11 +---------- src/controllers/AuthRoleController.ts | 10 +++++++--- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/controllers/AuthRoleAttrController.ts b/src/controllers/AuthRoleAttrController.ts index b7a07a96..e3f5779a 100644 --- a/src/controllers/AuthRoleAttrController.ts +++ b/src/controllers/AuthRoleAttrController.ts @@ -16,7 +16,6 @@ import { RequestWithUser } from "../middlewares/user"; import HttpError from "../interfaces/http-error"; import HttpStatus from "../interfaces/http-status"; import HttpSuccess from "../interfaces/http-success"; -import HttpStatusCode from "../interfaces/http-status"; import { AuthRoleAttr, CreateAuthRoleAttr, UpdateAuthRoleAttr } from "../entities/AuthRoleAttr"; import { AuthRole } from "../entities/AuthRole"; import { AuthSys } from "../entities/AuthSys"; @@ -111,15 +110,7 @@ export class AuthRoleAttrController extends Controller { @Delete("{roleAttrId}") public async deleteRole(@Path() roleAttrId: string) { - let result: any; - try { - result = await this.authRoleAttrRepo.delete({ id: roleAttrId }); - } catch { - throw new HttpError( - HttpStatusCode.NOT_FOUND, - "ไม่สามารถลบข้อมูลได้", - ); - } + const result = await this.authRoleAttrRepo.delete({ id: roleAttrId }); if (result.affected == undefined || result.affected <= 0) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); diff --git a/src/controllers/AuthRoleController.ts b/src/controllers/AuthRoleController.ts index ce2cd791..d9382464 100644 --- a/src/controllers/AuthRoleController.ts +++ b/src/controllers/AuthRoleController.ts @@ -16,6 +16,7 @@ import { RequestWithUser } from "../middlewares/user"; import HttpError from "../interfaces/http-error"; import HttpStatus from "../interfaces/http-status"; import HttpSuccess from "../interfaces/http-success"; +import HttpStatusCode from "../interfaces/http-status"; import { AuthRole, CreateAuthRole, UpdateAuthRole } from "../entities/AuthRole"; @Route("api/v1/org/auth/authRole") @@ -44,7 +45,6 @@ export class AuthRoleController extends Controller { @Post() public async newAuthRole(@Request() req: RequestWithUser, @Body() body: CreateAuthRole) { - const data = new AuthRole(); const meta = { createdUserId: req.user.sub, @@ -78,8 +78,12 @@ export class AuthRoleController extends Controller { @Delete("{roleId}") public async deleteRole(@Path() roleId: string) { - const result = await this.authRoleRepo.delete({ id: roleId }); - + let result: any; + try { + result = await this.authRoleRepo.delete({ id: roleId }); + } catch { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถลบข้อมูลได้"); + } if (result.affected == undefined || result.affected <= 0) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");