diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index 346184b2..eb141e13 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -112,6 +112,55 @@ export class PositionController extends Controller { } } + const chk_posDictName = await this.posDictRepository.findOne({ + where: { posDictName: posDict.posDictName } + }) + if(chk_posDictName){ + throw new HttpError(HttpStatusCode.NOT_FOUND, "ตำแหน่งในสายงาน: " + chk_posDictName.posDictName + " มีอยู่ในระบบแล้ว"); + } + + const chk_posDictField = await this.posDictRepository.findOne({ + where: { posDictField: posDict.posDictField } + }) + if(chk_posDictField){ + throw new HttpError(HttpStatusCode.NOT_FOUND, "สายงาน: " + chk_posDictField.posDictField + " มีอยู่ในระบบแล้ว"); + } + + const chk_posTypeId = await this.posDictRepository.findOne({ + where: { posTypeId: posDict.posTypeId } + }) + if(chk_posTypeId){ + throw new HttpError(HttpStatusCode.NOT_FOUND, "ตำแหน่งประเภท: " + chk_posTypeId.posTypeId + " มีอยู่ในระบบแล้ว"); + } + + const chk_posLevelId = await this.posDictRepository.findOne({ + where: { posLevelId: posDict.posLevelId } + }) + if(chk_posLevelId){ + throw new HttpError(HttpStatusCode.NOT_FOUND, "ระดับตำแหน่ง: " + chk_posLevelId.posLevelId + " มีอยู่ในระบบแล้ว"); + } + + const chk_posExecutiveId = await this.posDictRepository.findOne({ + where: { posExecutiveId: String(posDict.posExecutiveId) } + }) + if(chk_posExecutiveId){ + throw new HttpError(HttpStatusCode.NOT_FOUND, "ตำแหน่งทางการบริหาร: " + chk_posExecutiveId.posExecutiveId + " มีอยู่ในระบบแล้ว"); + } + + const chk_posDictExecutiveField = await this.posDictRepository.findOne({ + where: { posDictExecutiveField: posDict.posDictExecutiveField } + }) + if(chk_posDictExecutiveField){ + throw new HttpError(HttpStatusCode.NOT_FOUND, "ด้านทางการบริหาร: " + chk_posDictExecutiveField.posDictExecutiveField + " มีอยู่ในระบบแล้ว"); + } + + const chk_posDictArea= await this.posDictRepository.findOne({ + where: { posDictArea: posDict.posDictArea } + }) + if(chk_posDictArea){ + throw new HttpError(HttpStatusCode.NOT_FOUND, "ด้าน/สาขา: " + chk_posDictArea.posDictArea + " มีอยู่ในระบบแล้ว"); + } + try { posDict.createdUserId = request.user.sub; posDict.createdFullName = request.user.name;