hrms-api-kpi/src/controllers/KpiReasonController.ts
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 dfd9ebb3c1 Merge branch 'nice' into develop
# Conflicts:
#	src/controllers/KpiUserCapacityController.ts
#	src/controllers/KpiUserEvaluationController.ts
2024-08-22 14:27:49 +07:00

1202 lines
49 KiB
TypeScript

import {
Controller,
Get,
Put,
Route,
Security,
Tags,
Body,
Path,
Request,
SuccessResponse,
Response,
} from "tsoa";
import { AppDataSource } from "../database/data-source";
import HttpSuccess from "../interfaces/http-success";
import HttpError from "../interfaces/http-error";
import HttpStatusCode from "../interfaces/http-status";
import { In } from "typeorm";
import { KpiUserEvaluationReasonPlan } from "../entities/kpiUserEvaluationReasonPlan";
import { KpiUserEvaluationReasonRole } from "../entities/kpiUserEvaluationReasonRole";
import { KpiUserEvaluationReasonSpecial } from "../entities/kpiUserEvaluationReasonSpecial";
import {
KpiUserEvaluationReasonCapacity,
updateKpiUserReasonEvaluation,
} from "../entities/kpiUserEvaluationReasonCapacity";
import { KpiUserEvaluationReasonDevelopment } from "../entities/kpiUserEvaluationReasonDevelopment";
import { KpiUserRole } from "../entities/kpiUserRole";
import { KpiUserSpecial } from "../entities/kpiUserSpecial";
import { KpiUserCapacity } from "../entities/kpiUserCapacity";
import { KpiUserDevelopment } from "../entities/kpiUserDevelopment";
import { KpiUserPlanned } from "../entities/kpiUserPlanned";
import { RequestWithUser } from "../middlewares/user";
import { addLogSequence, setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/kpi/reason")
@Tags("kpiReason")
@Security("bearerAuth")
@Response(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
)
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
export class kpiReasonController extends Controller {
private kpiUserEvaluationReasonPlan = AppDataSource.getRepository(KpiUserEvaluationReasonPlan);
private kpiUserEvaluationReasonRole = AppDataSource.getRepository(KpiUserEvaluationReasonRole);
private kpiUserEvaluationReasonSpecial = AppDataSource.getRepository(
KpiUserEvaluationReasonSpecial,
);
private kpiUserEvaluationReasonCapacity = AppDataSource.getRepository(
KpiUserEvaluationReasonCapacity,
);
private kpiUserEvaluationReasonDevelopment = AppDataSource.getRepository(
KpiUserEvaluationReasonDevelopment,
);
private kpiUserPlan = AppDataSource.getRepository(KpiUserPlanned);
private kpiUserRole = AppDataSource.getRepository(KpiUserRole);
private kpiUserSpecial = AppDataSource.getRepository(KpiUserSpecial);
private kpiUserCapacity = AppDataSource.getRepository(KpiUserCapacity);
private kpiUserDevelopment = AppDataSource.getRepository(KpiUserDevelopment);
/**
* API แก้ไขหมายเหตุ (USER)
*
* @summary แก้ไขหมายเหตุ (USER)
*
* @param {string} id Guid, *Id คนประเมิน (USER)
*/
@Put("{type}/plan/{user}/{id}")
async updateKpiPlanReason(
@Path() type: string,
@Path() user: string,
@Path() id: string,
@Body() requestBody: updateKpiUserReasonEvaluation,
@Request() request: RequestWithUser,
) {
if (user.trim().toUpperCase() == "USER") {
const kpiUserEvaluation = await this.kpiUserPlan.findOne({
where: { id: id },
relations: ["kpiUserEvaluation"],
});
let kpiUserEvaluationReason = Object.assign(new KpiUserEvaluationReasonPlan(), requestBody);
kpiUserEvaluationReason.type = type.trim().toUpperCase();
if (type.trim().toUpperCase() == "PROBLEM") {
const _kpiUserEvaluationReason = await this.kpiUserEvaluationReasonPlan.findOne({
where: { id: id },
relations: ["kpiUserPlanned", "kpiUserPlanned.kpiUserEvaluation"],
});
if (_kpiUserEvaluationReason != null) {
kpiUserEvaluationReason = _kpiUserEvaluationReason;
Object.assign(kpiUserEvaluationReason, requestBody);
kpiUserEvaluationReason.status =
kpiUserEvaluationReason.kpiUserPlanned.kpiUserEvaluation.evaluatorId == null ||
kpiUserEvaluationReason.kpiUserPlanned.kpiUserEvaluation.evaluatorId == ""
? "DONE"
: "DRAFT";
} else {
kpiUserEvaluationReason.status =
kpiUserEvaluation == null ||
kpiUserEvaluation.kpiUserEvaluation.evaluatorId == null ||
kpiUserEvaluation.kpiUserEvaluation.evaluatorId == ""
? "DONE"
: "DRAFT";
}
} else {
if (!kpiUserEvaluation) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
);
}
kpiUserEvaluationReason.status =
kpiUserEvaluation.kpiUserEvaluation.evaluatorId == null ||
kpiUserEvaluation.kpiUserEvaluation.evaluatorId == ""
? "DONE"
: "EVALUATOR";
}
const before = structuredClone(kpiUserEvaluationReason);
kpiUserEvaluationReason.kpiUserPlannedId = id;
kpiUserEvaluationReason.createdUserId = request.user.sub;
kpiUserEvaluationReason.createdFullName = request.user.name;
kpiUserEvaluationReason.lastUpdateUserId = request.user.sub;
kpiUserEvaluationReason.lastUpdateFullName = request.user.name;
await this.kpiUserEvaluationReasonPlan.save(kpiUserEvaluationReason, { data: request });
setLogDataDiff(request, { before, after: kpiUserEvaluationReason });
return new HttpSuccess(kpiUserEvaluationReason.id);
} else {
const kpiReason = await this.kpiUserEvaluationReasonPlan.findOne({
where: { id: id },
relations: ["kpiUserPlanned", "kpiUserPlanned.kpiUserEvaluation"],
});
if (!kpiReason) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
);
}
if (user.trim().toUpperCase() == "EVALUATOR") {
kpiReason.reasonEvaluator = requestBody.reason == null ? "" : requestBody.reason;
kpiReason.status =
kpiReason.kpiUserPlanned.kpiUserEvaluation.commanderId == null ||
kpiReason.kpiUserPlanned.kpiUserEvaluation.commanderId == ""
? "DONE"
: "COMMANDER";
} else if (user.trim().toUpperCase() == "COMMANDER") {
kpiReason.reasonCommander = requestBody.reason == null ? "" : requestBody.reason;
kpiReason.status =
kpiReason.kpiUserPlanned.kpiUserEvaluation.commanderHighId == null ||
kpiReason.kpiUserPlanned.kpiUserEvaluation.commanderHighId == ""
? "DONE"
: "COMMANDERHIGH";
} else if (user.trim().toUpperCase() == "COMMANDERHIGH") {
kpiReason.reasonCommanderHigh = requestBody.reason == null ? "" : requestBody.reason;
kpiReason.status = "DONE";
}
const before = structuredClone(kpiReason);
kpiReason.lastUpdateUserId = request.user.sub;
kpiReason.lastUpdateFullName = request.user.name;
await this.kpiUserEvaluationReasonPlan.save(kpiReason, { data: request });
setLogDataDiff(request, { before, after: kpiReason });
return new HttpSuccess(kpiReason.id);
}
}
/**
* API แก้ไขหมายเหตุ (USER)
*
* @summary แก้ไขหมายเหตุ (USER)
*
* @param {string} id Guid, *Id คนประเมิน (USER)
*/
@Put("problem/plansend/user/{id}")
async sendKpiPlanReason(
@Path() id: string,
@Body() requestBody: updateKpiUserReasonEvaluation,
@Request() request: RequestWithUser,
) {
const kpiReason = await this.kpiUserEvaluationReasonPlan.findOne({
where: { id: id },
relations: ["kpiUserPlanned", "kpiUserPlanned.kpiUserEvaluation"],
});
if (!kpiReason) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
);
}
const before = structuredClone(kpiReason);
kpiReason.status =
kpiReason.kpiUserPlanned.kpiUserEvaluation.evaluatorId == null ||
kpiReason.kpiUserPlanned.kpiUserEvaluation.evaluatorId == ""
? "DONE"
: "EVALUATOR";
kpiReason.reason = requestBody.reason == null ? "" : requestBody.reason;
kpiReason.lastUpdateUserId = request.user.sub;
kpiReason.lastUpdateFullName = request.user.name;
await this.kpiUserEvaluationReasonPlan.save(kpiReason, { data: request });
setLogDataDiff(request, { before, after: kpiReason });
return new HttpSuccess(kpiReason.id);
}
/**
* API list หมายเหตุ (USER)
*
* @summary list หมายเหตุ (USER)
*
* @param {string} id Guid, *Id คนประเมิน (USER)
*/
@Get("{type}/plan/{user}/{id}")
async listKpiUserPlanReason(@Path() id: string, @Path() type: string, @Path() user: string) {
if (type.trim().toUpperCase() == "PROBLEM") {
if (user.trim().toUpperCase() == "USER") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonPlan.find({
where: { kpiUserPlannedId: id, type: type.trim().toUpperCase() },
});
return new HttpSuccess(kpiUserEvaluationReason);
} else if (user.trim().toUpperCase() == "EVALUATOR") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonPlan.find({
where: {
kpiUserPlannedId: id,
type: type.trim().toUpperCase(),
status: In(["EVALUATOR", "COMMANDER", "COMMANDERHIGH", "DONE"]),
},
});
return new HttpSuccess(kpiUserEvaluationReason);
} else if (user.trim().toUpperCase() == "COMMANDER") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonPlan.find({
where: {
kpiUserPlannedId: id,
type: type.trim().toUpperCase(),
status: In(["COMMANDER", "COMMANDERHIGH", "DONE"]),
},
});
return new HttpSuccess(kpiUserEvaluationReason);
} else if (user.trim().toUpperCase() == "COMMANDERHIGH") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonPlan.find({
where: {
kpiUserPlannedId: id,
type: type.trim().toUpperCase(),
status: In(["COMMANDERHIGH", "DONE"]),
},
});
return new HttpSuccess(kpiUserEvaluationReason);
}
} else {
if (user.trim().toUpperCase() == "USER") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonPlan.find({
where: { kpiUserPlannedId: id, type: type.trim().toUpperCase() },
});
return new HttpSuccess(kpiUserEvaluationReason);
} else if (user.trim().toUpperCase() == "EVALUATOR") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonPlan.find({
where: {
kpiUserPlannedId: id,
type: type.trim().toUpperCase(),
status: In(["EVALUATOR", "COMMANDER", "COMMANDERHIGH", "DONE"]),
},
});
return new HttpSuccess(kpiUserEvaluationReason);
} else if (user.trim().toUpperCase() == "COMMANDER") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonPlan.find({
where: {
kpiUserPlannedId: id,
type: type.trim().toUpperCase(),
status: In(["COMMANDER", "COMMANDERHIGH", "DONE"]),
},
});
return new HttpSuccess(kpiUserEvaluationReason);
} else if (user.trim().toUpperCase() == "COMMANDERHIGH") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonPlan.find({
where: {
kpiUserPlannedId: id,
type: type.trim().toUpperCase(),
status: In(["COMMANDERHIGH", "DONE"]),
},
});
return new HttpSuccess(kpiUserEvaluationReason);
}
}
}
/**
* API แก้ไขหมายเหตุ (USER)
*
* @summary แก้ไขหมายเหตุ (USER)
*
* @param {string} id Guid, *Id คนประเมิน (USER)
*/
@Put("{type}/role/{user}/{id}")
async updateKpiRoleReason(
@Path() type: string,
@Path() user: string,
@Path() id: string,
@Body() requestBody: updateKpiUserReasonEvaluation,
@Request() request: RequestWithUser,
) {
if (user.trim().toUpperCase() == "USER") {
const kpiUserEvaluation = await this.kpiUserRole.findOne({
where: { id: id },
relations: ["kpiUserEvaluation"],
});
let kpiUserEvaluationReason = Object.assign(new KpiUserEvaluationReasonRole(), requestBody);
kpiUserEvaluationReason.type = type.trim().toUpperCase();
if (type.trim().toUpperCase() == "PROBLEM") {
const _kpiUserEvaluationReason = await this.kpiUserEvaluationReasonRole.findOne({
where: { id: id },
relations: ["kpiUserRole", "kpiUserRole.kpiUserEvaluation"],
});
if (_kpiUserEvaluationReason != null) {
kpiUserEvaluationReason = _kpiUserEvaluationReason;
Object.assign(kpiUserEvaluationReason, requestBody);
kpiUserEvaluationReason.status =
kpiUserEvaluationReason.kpiUserRole.kpiUserEvaluation.evaluatorId == null ||
kpiUserEvaluationReason.kpiUserRole.kpiUserEvaluation.evaluatorId == ""
? "DONE"
: "DRAFT";
} else {
kpiUserEvaluationReason.status =
kpiUserEvaluation == null ||
kpiUserEvaluation.kpiUserEvaluation.evaluatorId == null ||
kpiUserEvaluation.kpiUserEvaluation.evaluatorId == ""
? "DONE"
: "DRAFT";
}
} else {
if (!kpiUserEvaluation) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
);
}
kpiUserEvaluationReason.status =
kpiUserEvaluation.kpiUserEvaluation.evaluatorId == null ||
kpiUserEvaluation.kpiUserEvaluation.evaluatorId == ""
? "DONE"
: "EVALUATOR";
}
const before = structuredClone(kpiUserEvaluationReason);
kpiUserEvaluationReason.kpiUserRoleId = id;
kpiUserEvaluationReason.createdUserId = request.user.sub;
kpiUserEvaluationReason.createdFullName = request.user.name;
kpiUserEvaluationReason.lastUpdateUserId = request.user.sub;
kpiUserEvaluationReason.lastUpdateFullName = request.user.name;
await this.kpiUserEvaluationReasonRole.save(kpiUserEvaluationReason, { data: request });
setLogDataDiff(request, { before, after: kpiUserEvaluationReason });
return new HttpSuccess(kpiUserEvaluationReason.id);
} else {
const kpiReason = await this.kpiUserEvaluationReasonRole.findOne({
where: { id: id },
relations: ["kpiUserRole", "kpiUserRole.kpiUserEvaluation"],
});
if (!kpiReason) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
);
}
if (user.trim().toUpperCase() == "EVALUATOR") {
kpiReason.reasonEvaluator = requestBody.reason == null ? "" : requestBody.reason;
kpiReason.status =
kpiReason.kpiUserRole.kpiUserEvaluation.commanderId == null ||
kpiReason.kpiUserRole.kpiUserEvaluation.commanderId == ""
? "DONE"
: "COMMANDER";
} else if (user.trim().toUpperCase() == "COMMANDER") {
kpiReason.reasonCommander = requestBody.reason == null ? "" : requestBody.reason;
kpiReason.status =
kpiReason.kpiUserRole.kpiUserEvaluation.commanderHighId == null ||
kpiReason.kpiUserRole.kpiUserEvaluation.commanderHighId == ""
? "DONE"
: "COMMANDERHIGH";
} else if (user.trim().toUpperCase() == "COMMANDERHIGH") {
kpiReason.reasonCommanderHigh = requestBody.reason == null ? "" : requestBody.reason;
kpiReason.status = "DONE";
}
const before = structuredClone(kpiReason);
kpiReason.lastUpdateUserId = request.user.sub;
kpiReason.lastUpdateFullName = request.user.name;
await this.kpiUserEvaluationReasonRole.save(kpiReason, { data: request });
setLogDataDiff(request, { before, after: kpiReason });
return new HttpSuccess(kpiReason.id);
}
}
/**
* API แก้ไขหมายเหตุ (USER)
*
* @summary แก้ไขหมายเหตุ (USER)
*
* @param {string} id Guid, *Id คนประเมิน (USER)
*/
@Put("problem/rolesend/user/{id}")
async sendKpiRoleReason(
@Path() id: string,
@Body() requestBody: updateKpiUserReasonEvaluation,
@Request() request: RequestWithUser,
) {
const kpiReason = await this.kpiUserEvaluationReasonRole.findOne({
where: { id: id },
relations: ["kpiUserRole", "kpiUserRole.kpiUserEvaluation"],
});
if (!kpiReason) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
);
}
const before = structuredClone(kpiReason);
kpiReason.status =
kpiReason.kpiUserRole.kpiUserEvaluation.evaluatorId == null ||
kpiReason.kpiUserRole.kpiUserEvaluation.evaluatorId == ""
? "DONE"
: "EVALUATOR";
kpiReason.reason = requestBody.reason == null ? "" : requestBody.reason;
kpiReason.lastUpdateUserId = request.user.sub;
kpiReason.lastUpdateFullName = request.user.name;
await this.kpiUserEvaluationReasonRole.save(kpiReason, { data: request });
setLogDataDiff(request, { before, after: kpiReason });
return new HttpSuccess(kpiReason.id);
}
/**
* API list หมายเหตุ (USER)
*
* @summary list หมายเหตุ (USER)
*
* @param {string} id Guid, *Id คนประเมิน (USER)
*/
@Get("{type}/role/{user}/{id}")
async listKpiUserRoleReason(@Path() id: string, @Path() type: string, @Path() user: string) {
if (type.trim().toUpperCase() == "PROBLEM") {
if (user.trim().toUpperCase() == "USER") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonRole.find({
where: { kpiUserRoleId: id, type: type.trim().toUpperCase() },
});
return new HttpSuccess(kpiUserEvaluationReason);
} else if (user.trim().toUpperCase() == "EVALUATOR") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonRole.find({
where: {
kpiUserRoleId: id,
type: type.trim().toUpperCase(),
status: In(["EVALUATOR", "COMMANDER", "COMMANDERHIGH", "DONE"]),
},
});
return new HttpSuccess(kpiUserEvaluationReason);
} else if (user.trim().toUpperCase() == "COMMANDER") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonRole.find({
where: {
kpiUserRoleId: id,
type: type.trim().toUpperCase(),
status: In(["COMMANDER", "COMMANDERHIGH", "DONE"]),
},
});
return new HttpSuccess(kpiUserEvaluationReason);
} else if (user.trim().toUpperCase() == "COMMANDERHIGH") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonRole.find({
where: {
kpiUserRoleId: id,
type: type.trim().toUpperCase(),
status: In(["COMMANDERHIGH", "DONE"]),
},
});
return new HttpSuccess(kpiUserEvaluationReason);
}
} else {
if (user.trim().toUpperCase() == "USER") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonRole.find({
where: { kpiUserRoleId: id, type: type.trim().toUpperCase() },
});
return new HttpSuccess(kpiUserEvaluationReason);
} else if (user.trim().toUpperCase() == "EVALUATOR") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonRole.find({
where: {
kpiUserRoleId: id,
type: type.trim().toUpperCase(),
status: In(["EVALUATOR", "COMMANDER", "COMMANDERHIGH", "DONE"]),
},
});
return new HttpSuccess(kpiUserEvaluationReason);
} else if (user.trim().toUpperCase() == "COMMANDER") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonRole.find({
where: {
kpiUserRoleId: id,
type: type.trim().toUpperCase(),
status: In(["COMMANDER", "COMMANDERHIGH", "DONE"]),
},
});
return new HttpSuccess(kpiUserEvaluationReason);
} else if (user.trim().toUpperCase() == "COMMANDERHIGH") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonRole.find({
where: {
kpiUserRoleId: id,
type: type.trim().toUpperCase(),
status: In(["COMMANDERHIGH", "DONE"]),
},
});
return new HttpSuccess(kpiUserEvaluationReason);
}
}
}
/**
* API แก้ไขหมายเหตุ (USER)
*
* @summary แก้ไขหมายเหตุ (USER)
*
* @param {string} id Guid, *Id คนประเมิน (USER)
*/
@Put("{type}/special/{user}/{id}")
async updateKpiSpecialReason(
@Path() type: string,
@Path() user: string,
@Path() id: string,
@Body() requestBody: updateKpiUserReasonEvaluation,
@Request() request: RequestWithUser,
) {
if (user.trim().toUpperCase() == "USER") {
const kpiUserEvaluation = await this.kpiUserSpecial.findOne({
where: { id: id },
relations: ["kpiUserEvaluation"],
});
let kpiUserEvaluationReason = Object.assign(
new KpiUserEvaluationReasonSpecial(),
requestBody,
);
kpiUserEvaluationReason.type = type.trim().toUpperCase();
if (type.trim().toUpperCase() == "PROBLEM") {
const _kpiUserEvaluationReason = await this.kpiUserEvaluationReasonSpecial.findOne({
where: { id: id },
relations: ["kpiUserSpecial", "kpiUserSpecial.kpiUserEvaluation"],
});
if (_kpiUserEvaluationReason != null) {
kpiUserEvaluationReason = _kpiUserEvaluationReason;
Object.assign(kpiUserEvaluationReason, requestBody);
kpiUserEvaluationReason.status =
kpiUserEvaluationReason.kpiUserSpecial.kpiUserEvaluation.evaluatorId == null ||
kpiUserEvaluationReason.kpiUserSpecial.kpiUserEvaluation.evaluatorId == ""
? "DONE"
: "DRAFT";
} else {
kpiUserEvaluationReason.status =
kpiUserEvaluation == null ||
kpiUserEvaluation.kpiUserEvaluation.evaluatorId == null ||
kpiUserEvaluation.kpiUserEvaluation.evaluatorId == ""
? "DONE"
: "DRAFT";
}
} else {
if (!kpiUserEvaluation) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
);
}
kpiUserEvaluationReason.status =
kpiUserEvaluation.kpiUserEvaluation.evaluatorId == null ||
kpiUserEvaluation.kpiUserEvaluation.evaluatorId == ""
? "DONE"
: "EVALUATOR";
}
const before = structuredClone(kpiUserEvaluationReason);
kpiUserEvaluationReason.kpiUserSpecialId = id;
kpiUserEvaluationReason.createdUserId = request.user.sub;
kpiUserEvaluationReason.createdFullName = request.user.name;
kpiUserEvaluationReason.lastUpdateUserId = request.user.sub;
kpiUserEvaluationReason.lastUpdateFullName = request.user.name;
await this.kpiUserEvaluationReasonSpecial.save(kpiUserEvaluationReason, { data: request });
setLogDataDiff(request, { before, after: kpiUserEvaluationReason });
return new HttpSuccess(kpiUserEvaluationReason.id);
} else {
const kpiReason = await this.kpiUserEvaluationReasonSpecial.findOne({
where: { id: id },
relations: ["kpiUserSpecial", "kpiUserSpecial.kpiUserEvaluation"],
});
if (!kpiReason) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
);
}
if (user.trim().toUpperCase() == "EVALUATOR") {
kpiReason.reasonEvaluator = requestBody.reason == null ? "" : requestBody.reason;
kpiReason.status =
kpiReason.kpiUserSpecial.kpiUserEvaluation.commanderId == null ||
kpiReason.kpiUserSpecial.kpiUserEvaluation.commanderId == ""
? "DONE"
: "COMMANDER";
} else if (user.trim().toUpperCase() == "COMMANDER") {
kpiReason.reasonCommander = requestBody.reason == null ? "" : requestBody.reason;
kpiReason.status =
kpiReason.kpiUserSpecial.kpiUserEvaluation.commanderHighId == null ||
kpiReason.kpiUserSpecial.kpiUserEvaluation.commanderHighId == ""
? "DONE"
: "COMMANDERHIGH";
} else if (user.trim().toUpperCase() == "COMMANDERHIGH") {
kpiReason.reasonCommanderHigh = requestBody.reason == null ? "" : requestBody.reason;
kpiReason.status = "DONE";
}
const before = structuredClone(kpiReason);
kpiReason.lastUpdateUserId = request.user.sub;
kpiReason.lastUpdateFullName = request.user.name;
await this.kpiUserEvaluationReasonSpecial.save(kpiReason, { data: request });
setLogDataDiff(request, { before, after: kpiReason });
return new HttpSuccess(kpiReason.id);
}
}
/**
* API แก้ไขหมายเหตุ (USER)
*
* @summary แก้ไขหมายเหตุ (USER)
*
* @param {string} id Guid, *Id คนประเมิน (USER)
*/
@Put("problem/specialsend/user/{id}")
async sendKpiSpecialReason(
@Path() id: string,
@Body() requestBody: updateKpiUserReasonEvaluation,
@Request() request: RequestWithUser,
) {
const kpiReason = await this.kpiUserEvaluationReasonSpecial.findOne({
where: { id: id },
relations: ["kpiUserSpecial", "kpiUserSpecial.kpiUserEvaluation"],
});
if (!kpiReason) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
);
}
const before = structuredClone(kpiReason);
kpiReason.status =
kpiReason.kpiUserSpecial.kpiUserEvaluation.evaluatorId == null ||
kpiReason.kpiUserSpecial.kpiUserEvaluation.evaluatorId == ""
? "DONE"
: "EVALUATOR";
kpiReason.reason = requestBody.reason == null ? "" : requestBody.reason;
kpiReason.lastUpdateUserId = request.user.sub;
kpiReason.lastUpdateFullName = request.user.name;
await this.kpiUserEvaluationReasonSpecial.save(kpiReason, { data: request });
setLogDataDiff(request, { before, after: kpiReason });
return new HttpSuccess(kpiReason.id);
}
/**
* API list หมายเหตุ (USER)
*
* @summary list หมายเหตุ (USER)
*
* @param {string} id Guid, *Id คนประเมิน (USER)
*/
@Get("{type}/special/{user}/{id}")
async listKpiUserSpecialReason(@Path() id: string, @Path() type: string, @Path() user: string) {
if (type.trim().toUpperCase() == "PROBLEM") {
if (user.trim().toUpperCase() == "USER") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonSpecial.find({
where: { kpiUserSpecialId: id, type: type.trim().toUpperCase() },
});
return new HttpSuccess(kpiUserEvaluationReason);
} else if (user.trim().toUpperCase() == "EVALUATOR") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonSpecial.find({
where: {
kpiUserSpecialId: id,
type: type.trim().toUpperCase(),
status: In(["EVALUATOR", "COMMANDER", "COMMANDERHIGH", "DONE"]),
},
});
return new HttpSuccess(kpiUserEvaluationReason);
} else if (user.trim().toUpperCase() == "COMMANDER") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonSpecial.find({
where: {
kpiUserSpecialId: id,
type: type.trim().toUpperCase(),
status: In(["COMMANDER", "COMMANDERHIGH", "DONE"]),
},
});
return new HttpSuccess(kpiUserEvaluationReason);
} else if (user.trim().toUpperCase() == "COMMANDERHIGH") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonSpecial.find({
where: {
kpiUserSpecialId: id,
type: type.trim().toUpperCase(),
status: In(["COMMANDERHIGH", "DONE"]),
},
});
return new HttpSuccess(kpiUserEvaluationReason);
}
} else {
if (user.trim().toUpperCase() == "USER") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonSpecial.find({
where: { kpiUserSpecialId: id, type: type.trim().toUpperCase() },
});
return new HttpSuccess(kpiUserEvaluationReason);
} else if (user.trim().toUpperCase() == "EVALUATOR") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonSpecial.find({
where: {
kpiUserSpecialId: id,
type: type.trim().toUpperCase(),
status: In(["EVALUATOR", "COMMANDER", "COMMANDERHIGH", "DONE"]),
},
});
return new HttpSuccess(kpiUserEvaluationReason);
} else if (user.trim().toUpperCase() == "COMMANDER") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonSpecial.find({
where: {
kpiUserSpecialId: id,
type: type.trim().toUpperCase(),
status: In(["COMMANDER", "COMMANDERHIGH", "DONE"]),
},
});
return new HttpSuccess(kpiUserEvaluationReason);
} else if (user.trim().toUpperCase() == "COMMANDERHIGH") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonSpecial.find({
where: {
kpiUserSpecialId: id,
type: type.trim().toUpperCase(),
status: In(["COMMANDERHIGH", "DONE"]),
},
});
return new HttpSuccess(kpiUserEvaluationReason);
}
}
}
/**
* API แก้ไขหมายเหตุ (USER)
*
* @summary แก้ไขหมายเหตุ (USER)
*
* @param {string} id Guid, *Id คนประเมิน (USER)
*/
@Put("{type}/development/{user}/{id}")
async updateKpiDevelopmentReason(
@Path() type: string,
@Path() user: string,
@Path() id: string,
@Body() requestBody: updateKpiUserReasonEvaluation,
@Request() request: RequestWithUser,
) {
if (user.trim().toUpperCase() == "USER") {
const kpiUserEvaluation = await this.kpiUserDevelopment.findOne({
where: { id: id },
relations: ["kpiUserEvaluation"],
});
let kpiUserEvaluationReason = Object.assign(
new KpiUserEvaluationReasonDevelopment(),
requestBody,
);
kpiUserEvaluationReason.type = type.trim().toUpperCase();
if (type.trim().toUpperCase() == "PROBLEM") {
const _kpiUserEvaluationReason = await this.kpiUserEvaluationReasonDevelopment.findOne({
where: { id: id },
relations: ["kpiUserDevelopment", "kpiUserDevelopment.kpiUserEvaluation"],
});
if (_kpiUserEvaluationReason != null) {
kpiUserEvaluationReason = _kpiUserEvaluationReason;
Object.assign(kpiUserEvaluationReason, requestBody);
kpiUserEvaluationReason.status =
kpiUserEvaluationReason.kpiUserDevelopment.kpiUserEvaluation.evaluatorId == null ||
kpiUserEvaluationReason.kpiUserDevelopment.kpiUserEvaluation.evaluatorId == ""
? "DONE"
: "DRAFT";
} else {
kpiUserEvaluationReason.status =
kpiUserEvaluation == null ||
kpiUserEvaluation.kpiUserEvaluation.evaluatorId == null ||
kpiUserEvaluation.kpiUserEvaluation.evaluatorId == ""
? "DONE"
: "DRAFT";
}
} else {
if (!kpiUserEvaluation) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
);
}
kpiUserEvaluationReason.status = "DONE";
}
const before = structuredClone(kpiUserEvaluationReason);
kpiUserEvaluationReason.kpiUserDevelopmentId = id;
kpiUserEvaluationReason.createdUserId = request.user.sub;
kpiUserEvaluationReason.createdFullName = request.user.name;
kpiUserEvaluationReason.lastUpdateUserId = request.user.sub;
kpiUserEvaluationReason.lastUpdateFullName = request.user.name;
await this.kpiUserEvaluationReasonDevelopment.save(kpiUserEvaluationReason, {
data: request,
});
setLogDataDiff(request, { before, after: kpiUserEvaluationReason });
return new HttpSuccess(kpiUserEvaluationReason.id);
} else {
const kpiReason = await this.kpiUserEvaluationReasonDevelopment.findOne({
where: { id: id },
relations: ["kpiUserDevelopment", "kpiUserDevelopment.kpiUserEvaluation"],
});
if (!kpiReason) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
);
}
if (user.trim().toUpperCase() == "EVALUATOR") {
kpiReason.reasonEvaluator = requestBody.reason == null ? "" : requestBody.reason;
kpiReason.status =
kpiReason.kpiUserDevelopment.kpiUserEvaluation.commanderId == null ||
kpiReason.kpiUserDevelopment.kpiUserEvaluation.commanderId == ""
? "DONE"
: "COMMANDER";
} else if (user.trim().toUpperCase() == "COMMANDER") {
kpiReason.reasonCommander = requestBody.reason == null ? "" : requestBody.reason;
kpiReason.status =
kpiReason.kpiUserDevelopment.kpiUserEvaluation.commanderHighId == null ||
kpiReason.kpiUserDevelopment.kpiUserEvaluation.commanderHighId == ""
? "DONE"
: "COMMANDERHIGH";
} else if (user.trim().toUpperCase() == "COMMANDERHIGH") {
kpiReason.reasonCommanderHigh = requestBody.reason == null ? "" : requestBody.reason;
kpiReason.status = "DONE";
}
const before = structuredClone(kpiReason);
kpiReason.lastUpdateUserId = request.user.sub;
kpiReason.lastUpdateFullName = request.user.name;
await this.kpiUserEvaluationReasonDevelopment.save(kpiReason, { data: request });
setLogDataDiff(request, { before, after: kpiReason });
return new HttpSuccess(kpiReason.id);
}
}
/**
* API แก้ไขหมายเหตุ (USER)
*
* @summary แก้ไขหมายเหตุ (USER)
*
* @param {string} id Guid, *Id คนประเมิน (USER)
*/
@Put("problem/developmentsend/user/{id}")
async sendKpiDevelopmentReason(
@Path() id: string,
@Body() requestBody: updateKpiUserReasonEvaluation,
@Request() request: RequestWithUser,
) {
const kpiReason = await this.kpiUserEvaluationReasonDevelopment.findOne({
where: { id: id },
relations: ["kpiUserDevelopment", "kpiUserDevelopment.kpiUserEvaluation"],
});
if (!kpiReason) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
);
}
const before = structuredClone(kpiReason);
kpiReason.status =
kpiReason.kpiUserDevelopment.kpiUserEvaluation.evaluatorId == null ||
kpiReason.kpiUserDevelopment.kpiUserEvaluation.evaluatorId == ""
? "DONE"
: "EVALUATOR";
kpiReason.reason = requestBody.reason == null ? "" : requestBody.reason;
kpiReason.lastUpdateUserId = request.user.sub;
kpiReason.lastUpdateFullName = request.user.name;
await this.kpiUserEvaluationReasonDevelopment.save(kpiReason, { data: request });
setLogDataDiff(request, { before, after: kpiReason });
return new HttpSuccess(kpiReason.id);
}
/**
* API list หมายเหตุ (USER)
*
* @summary list หมายเหตุ (USER)
*
* @param {string} id Guid, *Id คนประเมิน (USER)
*/
@Get("{type}/development/{user}/{id}")
async listKpiUserDevelopmentReason(
@Path() id: string,
@Path() type: string,
@Path() user: string,
) {
if (type.trim().toUpperCase() == "PROBLEM") {
if (user.trim().toUpperCase() == "USER") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonDevelopment.find({
where: { kpiUserDevelopmentId: id, type: type.trim().toUpperCase() },
});
return new HttpSuccess(kpiUserEvaluationReason);
} else if (user.trim().toUpperCase() == "EVALUATOR") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonDevelopment.find({
where: {
kpiUserDevelopmentId: id,
type: type.trim().toUpperCase(),
status: In(["EVALUATOR", "COMMANDER", "COMMANDERHIGH", "DONE"]),
},
});
return new HttpSuccess(kpiUserEvaluationReason);
} else if (user.trim().toUpperCase() == "COMMANDER") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonDevelopment.find({
where: {
kpiUserDevelopmentId: id,
type: type.trim().toUpperCase(),
status: In(["COMMANDER", "COMMANDERHIGH", "DONE"]),
},
});
return new HttpSuccess(kpiUserEvaluationReason);
} else if (user.trim().toUpperCase() == "COMMANDERHIGH") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonDevelopment.find({
where: {
kpiUserDevelopmentId: id,
type: type.trim().toUpperCase(),
status: In(["COMMANDERHIGH", "DONE"]),
},
});
return new HttpSuccess(kpiUserEvaluationReason);
}
} else {
if (user.trim().toUpperCase() == "USER") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonDevelopment.find({
where: { kpiUserDevelopmentId: id, type: type.trim().toUpperCase() },
});
return new HttpSuccess(kpiUserEvaluationReason);
} else if (user.trim().toUpperCase() == "EVALUATOR") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonDevelopment.find({
where: {
kpiUserDevelopmentId: id,
type: type.trim().toUpperCase(),
status: In(["EVALUATOR", "COMMANDER", "COMMANDERHIGH", "DONE"]),
},
});
return new HttpSuccess(kpiUserEvaluationReason);
} else if (user.trim().toUpperCase() == "COMMANDER") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonDevelopment.find({
where: {
kpiUserDevelopmentId: id,
type: type.trim().toUpperCase(),
status: In(["COMMANDER", "COMMANDERHIGH", "DONE"]),
},
});
return new HttpSuccess(kpiUserEvaluationReason);
} else if (user.trim().toUpperCase() == "COMMANDERHIGH") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonDevelopment.find({
where: {
kpiUserDevelopmentId: id,
type: type.trim().toUpperCase(),
status: In(["COMMANDERHIGH", "DONE"]),
},
});
return new HttpSuccess(kpiUserEvaluationReason);
}
}
}
/**
* API แก้ไขหมายเหตุ (USER)
*
* @summary แก้ไขหมายเหตุ (USER)
*
* @param {string} id Guid, *Id คนประเมิน (USER)
*/
@Put("{type}/capacity/{user}/{id}")
async updateKpiCapacityReason(
@Path() type: string,
@Path() user: string,
@Path() id: string,
@Body() requestBody: updateKpiUserReasonEvaluation,
@Request() request: RequestWithUser,
) {
if (user.trim().toUpperCase() == "USER") {
const kpiUserEvaluation = await this.kpiUserCapacity.findOne({
where: { id: id },
relations: ["kpiUserEvaluation"],
});
let kpiUserEvaluationReason = Object.assign(
new KpiUserEvaluationReasonCapacity(),
requestBody,
);
kpiUserEvaluationReason.type = type.trim().toUpperCase();
if (type.trim().toUpperCase() == "PROBLEM") {
const _kpiUserEvaluationReason = await this.kpiUserEvaluationReasonCapacity.findOne({
where: { id: id },
relations: ["kpiUserCapacity", "kpiUserCapacity.kpiUserEvaluation"],
});
if (_kpiUserEvaluationReason != null) {
kpiUserEvaluationReason = _kpiUserEvaluationReason;
Object.assign(kpiUserEvaluationReason, requestBody);
kpiUserEvaluationReason.status =
kpiUserEvaluationReason.kpiUserCapacity.kpiUserEvaluation.evaluatorId == null ||
kpiUserEvaluationReason.kpiUserCapacity.kpiUserEvaluation.evaluatorId == ""
? "DONE"
: "DRAFT";
} else {
kpiUserEvaluationReason.status =
kpiUserEvaluation == null ||
kpiUserEvaluation.kpiUserEvaluation.evaluatorId == null ||
kpiUserEvaluation.kpiUserEvaluation.evaluatorId == ""
? "DONE"
: "DRAFT";
}
} else {
if (!kpiUserEvaluation) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
);
}
kpiUserEvaluationReason.status = "DONE";
}
const before = structuredClone(kpiUserEvaluationReason);
kpiUserEvaluationReason.kpiUserCapacityId = id;
kpiUserEvaluationReason.createdUserId = request.user.sub;
kpiUserEvaluationReason.createdFullName = request.user.name;
kpiUserEvaluationReason.lastUpdateUserId = request.user.sub;
kpiUserEvaluationReason.lastUpdateFullName = request.user.name;
await this.kpiUserEvaluationReasonCapacity.save(kpiUserEvaluationReason, { data: request });
setLogDataDiff(request, { before, after: kpiUserEvaluationReason });
return new HttpSuccess(kpiUserEvaluationReason.id);
} else {
const kpiReason = await this.kpiUserEvaluationReasonCapacity.findOne({
where: { id: id },
relations: ["kpiUserCapacity", "kpiUserCapacity.kpiUserEvaluation"],
});
if (!kpiReason) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
);
}
if (user.trim().toUpperCase() == "EVALUATOR") {
kpiReason.reasonEvaluator = requestBody.reason == null ? "" : requestBody.reason;
kpiReason.status =
kpiReason.kpiUserCapacity.kpiUserEvaluation.commanderId == null ||
kpiReason.kpiUserCapacity.kpiUserEvaluation.commanderId == ""
? "DONE"
: "COMMANDER";
} else if (user.trim().toUpperCase() == "COMMANDER") {
kpiReason.reasonCommander = requestBody.reason == null ? "" : requestBody.reason;
kpiReason.status =
kpiReason.kpiUserCapacity.kpiUserEvaluation.commanderHighId == null ||
kpiReason.kpiUserCapacity.kpiUserEvaluation.commanderHighId == ""
? "DONE"
: "COMMANDERHIGH";
} else if (user.trim().toUpperCase() == "COMMANDERHIGH") {
kpiReason.reasonCommanderHigh = requestBody.reason == null ? "" : requestBody.reason;
kpiReason.status = "DONE";
}
const before = structuredClone(kpiReason);
kpiReason.lastUpdateUserId = request.user.sub;
kpiReason.lastUpdateFullName = request.user.name;
await this.kpiUserEvaluationReasonCapacity.save(kpiReason, { data: request });
setLogDataDiff(request, { before, after: kpiReason });
return new HttpSuccess(kpiReason.id);
}
}
/**
* API แก้ไขหมายเหตุ (USER)
*
* @summary แก้ไขหมายเหตุ (USER)
*
* @param {string} id Guid, *Id คนประเมิน (USER)
*/
@Put("problem/capacitysend/user/{id}")
async sendKpiCapacityReason(
@Path() id: string,
@Body() requestBody: updateKpiUserReasonEvaluation,
@Request() request: RequestWithUser,
) {
const kpiReason = await this.kpiUserEvaluationReasonCapacity.findOne({
where: { id: id },
relations: ["kpiUserCapacity", "kpiUserCapacity.kpiUserEvaluation"],
});
if (!kpiReason) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
);
}
const before = structuredClone(kpiReason);
kpiReason.status =
kpiReason.kpiUserCapacity.kpiUserEvaluation.evaluatorId == null ||
kpiReason.kpiUserCapacity.kpiUserEvaluation.evaluatorId == ""
? "DONE"
: "EVALUATOR";
kpiReason.reason = requestBody.reason == null ? "" : requestBody.reason;
kpiReason.lastUpdateUserId = request.user.sub;
kpiReason.lastUpdateFullName = request.user.name;
await this.kpiUserEvaluationReasonCapacity.save(kpiReason, { data: request });
setLogDataDiff(request, { before, after: kpiReason });
return new HttpSuccess(kpiReason.id);
}
/**
* API list หมายเหตุ (USER)
*
* @summary list หมายเหตุ (USER)
*
* @param {string} id Guid, *Id คนประเมิน (USER)
*/
@Get("{type}/capacity/{user}/{id}")
async listKpiUserCapacityReason(@Path() id: string, @Path() type: string, @Path() user: string) {
if (type.trim().toUpperCase() == "PROBLEM") {
if (user.trim().toUpperCase() == "USER") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonCapacity.find({
where: { kpiUserCapacityId: id, type: type.trim().toUpperCase() },
});
return new HttpSuccess(kpiUserEvaluationReason);
} else if (user.trim().toUpperCase() == "EVALUATOR") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonCapacity.find({
where: {
kpiUserCapacityId: id,
type: type.trim().toUpperCase(),
status: In(["EVALUATOR", "COMMANDER", "COMMANDERHIGH", "DONE"]),
},
});
return new HttpSuccess(kpiUserEvaluationReason);
} else if (user.trim().toUpperCase() == "COMMANDER") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonCapacity.find({
where: {
kpiUserCapacityId: id,
type: type.trim().toUpperCase(),
status: In(["COMMANDER", "COMMANDERHIGH", "DONE"]),
},
});
return new HttpSuccess(kpiUserEvaluationReason);
} else if (user.trim().toUpperCase() == "COMMANDERHIGH") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonCapacity.find({
where: {
kpiUserCapacityId: id,
type: type.trim().toUpperCase(),
status: In(["COMMANDERHIGH", "DONE"]),
},
});
return new HttpSuccess(kpiUserEvaluationReason);
}
} else {
if (user.trim().toUpperCase() == "USER") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonCapacity.find({
where: { kpiUserCapacityId: id, type: type.trim().toUpperCase() },
});
return new HttpSuccess(kpiUserEvaluationReason);
} else if (user.trim().toUpperCase() == "EVALUATOR") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonCapacity.find({
where: {
kpiUserCapacityId: id,
type: type.trim().toUpperCase(),
status: In(["EVALUATOR", "COMMANDER", "COMMANDERHIGH", "DONE"]),
},
});
return new HttpSuccess(kpiUserEvaluationReason);
} else if (user.trim().toUpperCase() == "COMMANDER") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonCapacity.find({
where: {
kpiUserCapacityId: id,
type: type.trim().toUpperCase(),
status: In(["COMMANDER", "COMMANDERHIGH", "DONE"]),
},
});
return new HttpSuccess(kpiUserEvaluationReason);
} else if (user.trim().toUpperCase() == "COMMANDERHIGH") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonCapacity.find({
where: {
kpiUserCapacityId: id,
type: type.trim().toUpperCase(),
status: In(["COMMANDERHIGH", "DONE"]),
},
});
return new HttpSuccess(kpiUserEvaluationReason);
}
}
}
}