From e977582bd0069fc2f9ed21be56ff4491168be1d8 Mon Sep 17 00:00:00 2001 From: Bright Date: Thu, 13 Jun 2024 15:35:59 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=81=E0=B8=94=E0=B8=AB=E0=B8=99=E0=B8=94?= =?UTF-8?q?=E0=B8=AA=E0=B8=B4=E0=B8=97=E0=B8=98=E0=B8=B4=E0=B9=8C=E0=B8=95?= =?UTF-8?q?=E0=B8=B3=E0=B9=81=E0=B8=AB=E0=B8=99=E0=B9=88=E0=B8=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/AuthRoleController.ts | 34 +++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/src/controllers/AuthRoleController.ts b/src/controllers/AuthRoleController.ts index 0c83d910..3f222267 100644 --- a/src/controllers/AuthRoleController.ts +++ b/src/controllers/AuthRoleController.ts @@ -27,7 +27,9 @@ import { EmployeePosMaster } from "../entities/EmployeePosMaster"; @Security("bearerAuth") export class AuthRoleController extends Controller { private authRoleRepo = AppDataSource.getRepository(AuthRole); - private authRoleAttrRepo = AppDataSource.getRepository(AuthRoleAttr); + private authRoleAttrRepo = AppDataSource.getRepository(AuthRoleAttr); + private posMasterRepository = AppDataSource.getRepository(PosMaster); + private employeePosMasterRepository = AppDataSource.getRepository(EmployeePosMaster) @Get("list") public async listAuthRole() { @@ -74,9 +76,33 @@ export class AuthRoleController extends Controller { return new HttpSuccess(data.id); } - @Post("assign") - public async AddAuthRole(@Request() req: RequestWithUser, @Body() body: CreateAddAuthRole) { - // console pasMater = await this + @Post("govoment") + public async AddAuthRoleGovoment(@Request() req: RequestWithUser, @Body() body: CreateAddAuthRole) { + const getDetail = await this.authRoleRepo.findOneBy({ id: body.authRoleId }); + if (!getDetail) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลสิทธิ์"); + + const posMaster = await this.posMasterRepository.findOneBy({ id : body.posMasterId }) + if (!posMaster) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลตำแหน่ง"); + + posMaster.lastUpdateUserId = req.user.sub; + posMaster.lastUpdateFullName = req.user.name; + posMaster.authRoleId = body.authRoleId + await this.posMasterRepository.save(posMaster); + return new HttpSuccess(); + } + + @Post("employee") + public async AddAuthRoleEmployee(@Request() req: RequestWithUser, @Body() body: CreateAddAuthRole) { + const getDetail = await this.authRoleRepo.findOneBy({ id: body.authRoleId }); + if (!getDetail) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลสิทธิ์"); + + const posMaster = await this.employeePosMasterRepository.findOneBy({ id : body.posMasterId }) + if (!posMaster) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลตำแหน่ง"); + + posMaster.lastUpdateUserId = req.user.sub; + posMaster.lastUpdateFullName = req.user.name; + posMaster.authRoleId = body.authRoleId + await this.employeePosMasterRepository.save(posMaster); return new HttpSuccess(); }