diff --git a/src/controllers/KpiUserEvaluationController.ts b/src/controllers/KpiUserEvaluationController.ts index dceecbf..c429776 100644 --- a/src/controllers/KpiUserEvaluationController.ts +++ b/src/controllers/KpiUserEvaluationController.ts @@ -202,19 +202,39 @@ export class KpiUserEvaluationController extends Controller { } const kpiUserEvaluation = Object.assign(new KpiUserEvaluation(), requestBody); - await new CallAPI() - .GetData(request, "org/profile/keycloak/position") - .then((x) => { - kpiUserEvaluation.profileId = x.profileId; - kpiUserEvaluation.prefix = x.prefix; - kpiUserEvaluation.firstName = x.firstName; - kpiUserEvaluation.lastName = x.lastName; - kpiUserEvaluation.position = x.position; - kpiUserEvaluation.posLevelName = x.posLevelName; - kpiUserEvaluation.posTypeName = x.posTypeName; - kpiUserEvaluation.posExecutiveName = x.posExecutiveName; - }) - .catch((x) => {}); + if (requestBody.profileId == undefined || requestBody.profileId == null) { + await new CallAPI() + .GetData(request, "org/profile/profileid/position/" + requestBody.profileId) + .then((x) => { + kpiUserEvaluation.profileId = x.profileId; + kpiUserEvaluation.prefix = x.prefix; + kpiUserEvaluation.firstName = x.firstName; + kpiUserEvaluation.lastName = x.lastName; + kpiUserEvaluation.position = x.position; + kpiUserEvaluation.posLevelName = x.posLevelName; + kpiUserEvaluation.posTypeName = x.posTypeName; + kpiUserEvaluation.posExecutiveName = x.posExecutiveName; + }) + .catch((x) => { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลในทะเบียนประวัติ"); + }); + } else { + await new CallAPI() + .GetData(request, "org/profile/keycloak/position") + .then((x) => { + kpiUserEvaluation.profileId = x.profileId; + kpiUserEvaluation.prefix = x.prefix; + kpiUserEvaluation.firstName = x.firstName; + kpiUserEvaluation.lastName = x.lastName; + kpiUserEvaluation.position = x.position; + kpiUserEvaluation.posLevelName = x.posLevelName; + kpiUserEvaluation.posTypeName = x.posTypeName; + kpiUserEvaluation.posExecutiveName = x.posExecutiveName; + }) + .catch((x) => { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลในทะเบียนประวัติ"); + }); + } kpiUserEvaluation.evaluationStatus = "NEW"; kpiUserEvaluation.evaluationResults = "PENDING"; kpiUserEvaluation.createdUserId = request.user.sub; diff --git a/src/entities/kpiUserEvaluation.ts b/src/entities/kpiUserEvaluation.ts index 04d1b9d..fbbac9e 100644 --- a/src/entities/kpiUserEvaluation.ts +++ b/src/entities/kpiUserEvaluation.ts @@ -202,7 +202,7 @@ export class createKpiUserEvaluation { @Column() kpiPeriodId: string; @Column() - profileId: string; + profileId?: string | null; @Column() evaluatorId: string | null; @Column()