From 60f5203ff459761ddaf5daddf72e840291edc39a Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 7 Feb 2024 12:01:12 +0700 Subject: [PATCH] no message --- src/controllers/PositionController.ts | 16 +++++++++----- src/controllers/ReportController.ts | 32 ++++++++++++--------------- src/entities/PosDict.ts | 2 +- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index a65b07de..4e862e9b 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -99,12 +99,16 @@ export class PositionController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล PosLevelId"); } - // const checkPosExecutiveId = await this.posExecutiveRepository.findOne({ - // where: { id: requestBody.posExecutiveId }, - // }); - // if (!checkPosExecutiveId) { - // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล PosExecutiveId"); - // } + if (requestBody.posExecutiveId != "") requestBody.posExecutiveId = null; + + if (requestBody.posExecutiveId != null) { + const checkPosExecutiveId = await this.posExecutiveRepository.findOne({ + where: { id: requestBody.posExecutiveId }, + }); + if (!checkPosExecutiveId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล PosExecutiveId"); + } + } try { posDict.createdUserId = request.user.sub; diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index bffe8e04..d1eba316 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -231,18 +231,12 @@ export class ReportController extends Controller { // }; // }), // ); - const positionName = [ - ...new Set(posMaster.positions.map((x) => x.positionName)), - ].join(" หรือ "); - const posType = [ - ...new Set(posMaster.positions.map((x) => x.posType.posTypeName)), - ].join(" หรือ "); + const positionName = [...new Set(posMaster.positions.map((x) => x.positionName))]; + const posType = [...new Set(posMaster.positions.map((x) => x.posType.posTypeName))]; const posLevel = [ ...new Set(posMaster.positions.map((x) => x.posLevel.posLevelName)), - ].join(" หรือ "); - const positionField = [ - ...new Set(posMaster.positions.map((x) => x.positionField)), - ].join(" หรือ "); + ]; + const positionField = [...new Set(posMaster.positions.map((x) => x.positionField))]; return { posMasterNoPrefix: posMaster.posMasterNoPrefix, posMasterNo: posMaster.posMasterNo, @@ -252,19 +246,21 @@ export class ReportController extends Controller { ? "- ว่าง -" : `${posMaster.next_holder.prefix}${posMaster.next_holder.firstName} ${posMaster.next_holder.lastName}`, profilePosMasterNo: posMaster.next_holder == null ? null : "xxx", - profilePositionName: posMaster.next_holder == null ? positionName : "xxx", - profilePosType: posMaster.next_holder == null ? posType : "xxx", - profilePosLevel: posMaster.next_holder == null ? posLevel : "xxx", - profilePositionField: posMaster.next_holder == null ? positionField : "xxx", + profilePositionName: + posMaster.next_holder == null ? positionName.join(" หรือ ") : "xxx", + profilePosType: posMaster.next_holder == null ? posType.join(" หรือ ") : "xxx", + profilePosLevel: posMaster.next_holder == null ? posLevel.join(" หรือ ") : "xxx", + profilePositionField: + posMaster.next_holder == null ? positionField.join(" หรือ ") : "xxx", // profilePosMasterNo: (posMasterOld == null ? null : posMasterOld.posMasterNo), // profilePositionName: (positionOld == null ? null : positionOld.positionName), // profilePosType: (positionOld == null ? null : positionOld.posType.posTypeName), // profilePosLevel: (positionOld == null ? null : positionOld.posLevel.posLevelName), // profilePositionField: (positionOld == null ? null : positionOld.positionField), - PositionName: positionName, - PosType: posType, - PosLevel: posLevel, - PositionField: positionField, + PositionName: positionName.join(" หรือ "), + PosType: posType.join(" หรือ "), + PosLevel: posLevel.join(" หรือ "), + PositionField: positionField.join(" หรือ "), // positions: await Promise.all( // positions // .filter((position) => position.posMasterId === posMaster.id) diff --git a/src/entities/PosDict.ts b/src/entities/PosDict.ts index f31c32e8..b00c08eb 100644 --- a/src/entities/PosDict.ts +++ b/src/entities/PosDict.ts @@ -85,7 +85,7 @@ export class CreatePosDict { posLevelId: string; @Column() - posExecutiveId: string; + posExecutiveId?: string | null; @Column() posDictExecutiveField: string;