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(); }