diff --git a/src/controllers/AuthRoleController.ts b/src/controllers/AuthRoleController.ts index 3f222267..175c749e 100644 --- a/src/controllers/AuthRoleController.ts +++ b/src/controllers/AuthRoleController.ts @@ -78,9 +78,18 @@ export class AuthRoleController extends Controller { @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, "ไม่พบข้อมูลสิทธิ์"); + let _NULL_ : any = null; + let getDetail + + if(body.authRoleId == "") { + body.authRoleId = _NULL_ + } + else { + 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, "ไม่พบข้อมูลตำแหน่ง"); @@ -93,8 +102,18 @@ export class AuthRoleController extends Controller { @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, "ไม่พบข้อมูลสิทธิ์"); + + let _NULL_ : any = null; + let getDetail + + if(body.authRoleId == "") { + body.authRoleId = _NULL_ + } + else { + 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, "ไม่พบข้อมูลตำแหน่ง");