2024-05-08 23:48:19 +07:00
|
|
|
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";
|
2024-08-22 14:23:50 +07:00
|
|
|
import { RequestWithUser } from "../middlewares/user";
|
|
|
|
|
import { addLogSequence, setLogDataDiff } from "../interfaces/utils";
|
2024-05-08 23:48:19 +07:00
|
|
|
|
|
|
|
|
@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,
|
2024-08-22 14:23:50 +07:00
|
|
|
@Request() request: RequestWithUser,
|
2024-05-08 23:48:19 +07:00
|
|
|
) {
|
|
|
|
|
if (user.trim().toUpperCase() == "USER") {
|
|
|
|
|
const kpiUserEvaluation = await this.kpiUserPlan.findOne({
|
|
|
|
|
where: { id: id },
|
2024-05-13 13:17:23 +07:00
|
|
|
relations: ["kpiUserEvaluation"],
|
2024-05-08 23:48:19 +07:00
|
|
|
});
|
2024-05-14 14:08:24 +07:00
|
|
|
let kpiUserEvaluationReason = Object.assign(new KpiUserEvaluationReasonPlan(), requestBody);
|
2024-05-08 23:48:19 +07:00
|
|
|
kpiUserEvaluationReason.type = type.trim().toUpperCase();
|
2024-06-27 16:58:59 +07:00
|
|
|
if (type.trim().toUpperCase() == "PROBLEM") {
|
2024-05-14 14:08:24 +07:00
|
|
|
const _kpiUserEvaluationReason = await this.kpiUserEvaluationReasonPlan.findOne({
|
|
|
|
|
where: { id: id },
|
2024-05-17 14:17:01 +07:00
|
|
|
relations: ["kpiUserPlanned", "kpiUserPlanned.kpiUserEvaluation"],
|
2024-05-14 14:08:24 +07:00
|
|
|
});
|
2024-05-17 14:17:01 +07:00
|
|
|
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";
|
|
|
|
|
}
|
2024-05-08 23:48:19 +07:00
|
|
|
} else {
|
2024-05-17 14:17:01 +07:00
|
|
|
if (!kpiUserEvaluation) {
|
|
|
|
|
throw new HttpError(
|
|
|
|
|
HttpStatusCode.NOT_FOUND,
|
|
|
|
|
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
|
|
|
|
|
);
|
|
|
|
|
}
|
2024-05-08 23:48:19 +07:00
|
|
|
kpiUserEvaluationReason.status =
|
2024-05-14 09:39:27 +07:00
|
|
|
kpiUserEvaluation.kpiUserEvaluation.evaluatorId == null ||
|
|
|
|
|
kpiUserEvaluation.kpiUserEvaluation.evaluatorId == ""
|
|
|
|
|
? "DONE"
|
|
|
|
|
: "EVALUATOR";
|
2024-05-08 23:48:19 +07:00
|
|
|
}
|
2024-08-22 14:23:50 +07:00
|
|
|
const before = structuredClone(kpiUserEvaluationReason);
|
|
|
|
|
|
2024-05-08 23:48:19 +07:00
|
|
|
kpiUserEvaluationReason.kpiUserPlannedId = id;
|
|
|
|
|
kpiUserEvaluationReason.createdUserId = request.user.sub;
|
|
|
|
|
kpiUserEvaluationReason.createdFullName = request.user.name;
|
|
|
|
|
kpiUserEvaluationReason.lastUpdateUserId = request.user.sub;
|
|
|
|
|
kpiUserEvaluationReason.lastUpdateFullName = request.user.name;
|
2024-08-22 14:23:50 +07:00
|
|
|
await this.kpiUserEvaluationReasonPlan.save(kpiUserEvaluationReason, { data: request });
|
|
|
|
|
setLogDataDiff(request, { before, after: kpiUserEvaluationReason });
|
|
|
|
|
|
2024-05-08 23:48:19 +07:00
|
|
|
return new HttpSuccess(kpiUserEvaluationReason.id);
|
|
|
|
|
} else {
|
|
|
|
|
const kpiReason = await this.kpiUserEvaluationReasonPlan.findOne({
|
|
|
|
|
where: { id: id },
|
2024-05-14 01:45:55 +07:00
|
|
|
relations: ["kpiUserPlanned", "kpiUserPlanned.kpiUserEvaluation"],
|
2024-05-08 23:48:19 +07:00
|
|
|
});
|
|
|
|
|
if (!kpiReason) {
|
|
|
|
|
throw new HttpError(
|
|
|
|
|
HttpStatusCode.NOT_FOUND,
|
|
|
|
|
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (user.trim().toUpperCase() == "EVALUATOR") {
|
2024-06-19 10:17:15 +07:00
|
|
|
kpiReason.reasonEvaluator = requestBody.reason == null ? "" : requestBody.reason;
|
2024-05-08 23:48:19 +07:00
|
|
|
kpiReason.status =
|
2024-05-14 09:39:27 +07:00
|
|
|
kpiReason.kpiUserPlanned.kpiUserEvaluation.commanderId == null ||
|
|
|
|
|
kpiReason.kpiUserPlanned.kpiUserEvaluation.commanderId == ""
|
|
|
|
|
? "DONE"
|
|
|
|
|
: "COMMANDER";
|
2024-05-08 23:48:19 +07:00
|
|
|
} else if (user.trim().toUpperCase() == "COMMANDER") {
|
2024-06-19 10:17:15 +07:00
|
|
|
kpiReason.reasonCommander = requestBody.reason == null ? "" : requestBody.reason;
|
2024-05-08 23:48:19 +07:00
|
|
|
kpiReason.status =
|
2024-05-14 09:39:27 +07:00
|
|
|
kpiReason.kpiUserPlanned.kpiUserEvaluation.commanderHighId == null ||
|
|
|
|
|
kpiReason.kpiUserPlanned.kpiUserEvaluation.commanderHighId == ""
|
2024-05-08 23:48:19 +07:00
|
|
|
? "DONE"
|
|
|
|
|
: "COMMANDERHIGH";
|
|
|
|
|
} else if (user.trim().toUpperCase() == "COMMANDERHIGH") {
|
2024-06-19 10:17:15 +07:00
|
|
|
kpiReason.reasonCommanderHigh = requestBody.reason == null ? "" : requestBody.reason;
|
2024-05-08 23:48:19 +07:00
|
|
|
kpiReason.status = "DONE";
|
|
|
|
|
}
|
2024-08-22 14:23:50 +07:00
|
|
|
const before = structuredClone(kpiReason);
|
|
|
|
|
|
2024-05-08 23:48:19 +07:00
|
|
|
kpiReason.lastUpdateUserId = request.user.sub;
|
|
|
|
|
kpiReason.lastUpdateFullName = request.user.name;
|
2024-08-22 14:23:50 +07:00
|
|
|
await this.kpiUserEvaluationReasonPlan.save(kpiReason, { data: request });
|
|
|
|
|
setLogDataDiff(request, { before, after: kpiReason });
|
|
|
|
|
|
2024-05-08 23:48:19 +07:00
|
|
|
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,
|
2024-08-22 14:23:50 +07:00
|
|
|
@Request() request: RequestWithUser,
|
2024-05-08 23:48:19 +07:00
|
|
|
) {
|
|
|
|
|
const kpiReason = await this.kpiUserEvaluationReasonPlan.findOne({
|
|
|
|
|
where: { id: id },
|
2024-05-14 01:45:55 +07:00
|
|
|
relations: ["kpiUserPlanned", "kpiUserPlanned.kpiUserEvaluation"],
|
2024-05-08 23:48:19 +07:00
|
|
|
});
|
|
|
|
|
if (!kpiReason) {
|
|
|
|
|
throw new HttpError(
|
|
|
|
|
HttpStatusCode.NOT_FOUND,
|
|
|
|
|
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
|
|
|
|
|
);
|
|
|
|
|
}
|
2024-08-22 14:23:50 +07:00
|
|
|
const before = structuredClone(kpiReason);
|
2024-05-08 23:48:19 +07:00
|
|
|
|
|
|
|
|
kpiReason.status =
|
2024-05-14 14:08:24 +07:00
|
|
|
kpiReason.kpiUserPlanned.kpiUserEvaluation.evaluatorId == null ||
|
|
|
|
|
kpiReason.kpiUserPlanned.kpiUserEvaluation.evaluatorId == ""
|
2024-05-14 09:39:27 +07:00
|
|
|
? "DONE"
|
2024-05-14 14:08:24 +07:00
|
|
|
: "EVALUATOR";
|
2024-06-19 10:17:15 +07:00
|
|
|
kpiReason.reason = requestBody.reason == null ? "" : requestBody.reason;
|
2024-05-08 23:48:19 +07:00
|
|
|
kpiReason.lastUpdateUserId = request.user.sub;
|
|
|
|
|
kpiReason.lastUpdateFullName = request.user.name;
|
2024-08-22 14:23:50 +07:00
|
|
|
await this.kpiUserEvaluationReasonPlan.save(kpiReason, { data: request });
|
|
|
|
|
setLogDataDiff(request, { before, after: kpiReason });
|
|
|
|
|
|
2024-05-08 23:48:19 +07:00
|
|
|
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) {
|
2024-06-27 16:58:59 +07:00
|
|
|
if (type.trim().toUpperCase() == "PROBLEM") {
|
2024-06-30 20:51:04 +07:00
|
|
|
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);
|
|
|
|
|
}
|
2024-05-08 23:48:19 +07:00
|
|
|
} else {
|
|
|
|
|
if (user.trim().toUpperCase() == "USER") {
|
|
|
|
|
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonPlan.find({
|
2024-05-14 01:45:55 +07:00
|
|
|
where: { kpiUserPlannedId: id, type: type.trim().toUpperCase() },
|
2024-05-08 23:48:19 +07:00
|
|
|
});
|
|
|
|
|
return new HttpSuccess(kpiUserEvaluationReason);
|
|
|
|
|
} else if (user.trim().toUpperCase() == "EVALUATOR") {
|
|
|
|
|
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonPlan.find({
|
|
|
|
|
where: {
|
|
|
|
|
kpiUserPlannedId: id,
|
2024-05-14 01:45:55 +07:00
|
|
|
type: type.trim().toUpperCase(),
|
2024-05-08 23:48:19 +07:00
|
|
|
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,
|
2024-05-14 01:45:55 +07:00
|
|
|
type: type.trim().toUpperCase(),
|
2024-05-08 23:48:19 +07:00
|
|
|
status: In(["COMMANDER", "COMMANDERHIGH", "DONE"]),
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
return new HttpSuccess(kpiUserEvaluationReason);
|
|
|
|
|
} else if (user.trim().toUpperCase() == "COMMANDERHIGH") {
|
|
|
|
|
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonPlan.find({
|
|
|
|
|
where: {
|
|
|
|
|
kpiUserPlannedId: id,
|
2024-05-14 01:45:55 +07:00
|
|
|
type: type.trim().toUpperCase(),
|
2024-05-08 23:48:19 +07:00
|
|
|
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,
|
2024-08-22 14:23:50 +07:00
|
|
|
@Request() request: RequestWithUser,
|
2024-05-08 23:48:19 +07:00
|
|
|
) {
|
|
|
|
|
if (user.trim().toUpperCase() == "USER") {
|
|
|
|
|
const kpiUserEvaluation = await this.kpiUserRole.findOne({
|
|
|
|
|
where: { id: id },
|
2024-05-13 14:29:48 +07:00
|
|
|
relations: ["kpiUserEvaluation"],
|
2024-05-08 23:48:19 +07:00
|
|
|
});
|
2024-05-14 14:08:24 +07:00
|
|
|
let kpiUserEvaluationReason = Object.assign(new KpiUserEvaluationReasonRole(), requestBody);
|
2024-05-08 23:48:19 +07:00
|
|
|
kpiUserEvaluationReason.type = type.trim().toUpperCase();
|
2024-06-27 16:58:59 +07:00
|
|
|
if (type.trim().toUpperCase() == "PROBLEM") {
|
2024-05-14 14:08:24 +07:00
|
|
|
const _kpiUserEvaluationReason = await this.kpiUserEvaluationReasonRole.findOne({
|
|
|
|
|
where: { id: id },
|
2024-05-17 14:17:01 +07:00
|
|
|
relations: ["kpiUserRole", "kpiUserRole.kpiUserEvaluation"],
|
2024-05-14 14:08:24 +07:00
|
|
|
});
|
2024-05-17 14:17:01 +07:00
|
|
|
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";
|
|
|
|
|
}
|
2024-05-14 14:08:24 +07:00
|
|
|
} else {
|
2024-05-17 14:17:01 +07:00
|
|
|
if (!kpiUserEvaluation) {
|
|
|
|
|
throw new HttpError(
|
|
|
|
|
HttpStatusCode.NOT_FOUND,
|
|
|
|
|
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
|
|
|
|
|
);
|
|
|
|
|
}
|
2024-05-14 14:08:24 +07:00
|
|
|
kpiUserEvaluationReason.status =
|
|
|
|
|
kpiUserEvaluation.kpiUserEvaluation.evaluatorId == null ||
|
|
|
|
|
kpiUserEvaluation.kpiUserEvaluation.evaluatorId == ""
|
|
|
|
|
? "DONE"
|
|
|
|
|
: "EVALUATOR";
|
|
|
|
|
}
|
2024-08-22 14:23:50 +07:00
|
|
|
const before = structuredClone(kpiUserEvaluationReason);
|
2024-05-14 14:08:24 +07:00
|
|
|
|
2024-05-08 23:48:19 +07:00
|
|
|
kpiUserEvaluationReason.kpiUserRoleId = id;
|
|
|
|
|
kpiUserEvaluationReason.createdUserId = request.user.sub;
|
|
|
|
|
kpiUserEvaluationReason.createdFullName = request.user.name;
|
|
|
|
|
kpiUserEvaluationReason.lastUpdateUserId = request.user.sub;
|
|
|
|
|
kpiUserEvaluationReason.lastUpdateFullName = request.user.name;
|
2024-08-22 14:23:50 +07:00
|
|
|
await this.kpiUserEvaluationReasonRole.save(kpiUserEvaluationReason, { data: request });
|
|
|
|
|
setLogDataDiff(request, { before, after: kpiUserEvaluationReason });
|
|
|
|
|
|
2024-05-08 23:48:19 +07:00
|
|
|
return new HttpSuccess(kpiUserEvaluationReason.id);
|
|
|
|
|
} else {
|
|
|
|
|
const kpiReason = await this.kpiUserEvaluationReasonRole.findOne({
|
|
|
|
|
where: { id: id },
|
2024-05-14 01:45:55 +07:00
|
|
|
relations: ["kpiUserRole", "kpiUserRole.kpiUserEvaluation"],
|
2024-05-08 23:48:19 +07:00
|
|
|
});
|
|
|
|
|
if (!kpiReason) {
|
|
|
|
|
throw new HttpError(
|
|
|
|
|
HttpStatusCode.NOT_FOUND,
|
|
|
|
|
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (user.trim().toUpperCase() == "EVALUATOR") {
|
2024-06-19 10:17:15 +07:00
|
|
|
kpiReason.reasonEvaluator = requestBody.reason == null ? "" : requestBody.reason;
|
2024-05-08 23:48:19 +07:00
|
|
|
kpiReason.status =
|
2024-05-14 09:39:27 +07:00
|
|
|
kpiReason.kpiUserRole.kpiUserEvaluation.commanderId == null ||
|
|
|
|
|
kpiReason.kpiUserRole.kpiUserEvaluation.commanderId == ""
|
|
|
|
|
? "DONE"
|
|
|
|
|
: "COMMANDER";
|
2024-05-08 23:48:19 +07:00
|
|
|
} else if (user.trim().toUpperCase() == "COMMANDER") {
|
2024-06-19 10:17:15 +07:00
|
|
|
kpiReason.reasonCommander = requestBody.reason == null ? "" : requestBody.reason;
|
2024-05-08 23:48:19 +07:00
|
|
|
kpiReason.status =
|
2024-05-14 09:39:27 +07:00
|
|
|
kpiReason.kpiUserRole.kpiUserEvaluation.commanderHighId == null ||
|
|
|
|
|
kpiReason.kpiUserRole.kpiUserEvaluation.commanderHighId == ""
|
2024-05-08 23:48:19 +07:00
|
|
|
? "DONE"
|
|
|
|
|
: "COMMANDERHIGH";
|
|
|
|
|
} else if (user.trim().toUpperCase() == "COMMANDERHIGH") {
|
2024-06-19 10:17:15 +07:00
|
|
|
kpiReason.reasonCommanderHigh = requestBody.reason == null ? "" : requestBody.reason;
|
2024-05-08 23:48:19 +07:00
|
|
|
kpiReason.status = "DONE";
|
|
|
|
|
}
|
2024-08-22 14:23:50 +07:00
|
|
|
const before = structuredClone(kpiReason);
|
|
|
|
|
|
2024-05-08 23:48:19 +07:00
|
|
|
kpiReason.lastUpdateUserId = request.user.sub;
|
|
|
|
|
kpiReason.lastUpdateFullName = request.user.name;
|
2024-08-22 14:23:50 +07:00
|
|
|
await this.kpiUserEvaluationReasonRole.save(kpiReason, { data: request });
|
|
|
|
|
setLogDataDiff(request, { before, after: kpiReason });
|
|
|
|
|
|
2024-05-08 23:48:19 +07:00
|
|
|
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,
|
2024-08-22 14:23:50 +07:00
|
|
|
@Request() request: RequestWithUser,
|
2024-05-08 23:48:19 +07:00
|
|
|
) {
|
|
|
|
|
const kpiReason = await this.kpiUserEvaluationReasonRole.findOne({
|
|
|
|
|
where: { id: id },
|
2024-05-14 01:45:55 +07:00
|
|
|
relations: ["kpiUserRole", "kpiUserRole.kpiUserEvaluation"],
|
2024-05-08 23:48:19 +07:00
|
|
|
});
|
|
|
|
|
if (!kpiReason) {
|
|
|
|
|
throw new HttpError(
|
|
|
|
|
HttpStatusCode.NOT_FOUND,
|
|
|
|
|
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
|
|
|
|
|
);
|
|
|
|
|
}
|
2024-08-22 14:23:50 +07:00
|
|
|
const before = structuredClone(kpiReason);
|
2024-05-08 23:48:19 +07:00
|
|
|
|
|
|
|
|
kpiReason.status =
|
2024-05-14 14:08:24 +07:00
|
|
|
kpiReason.kpiUserRole.kpiUserEvaluation.evaluatorId == null ||
|
|
|
|
|
kpiReason.kpiUserRole.kpiUserEvaluation.evaluatorId == ""
|
2024-05-14 09:39:27 +07:00
|
|
|
? "DONE"
|
2024-05-14 14:08:24 +07:00
|
|
|
: "EVALUATOR";
|
2024-06-19 10:17:15 +07:00
|
|
|
kpiReason.reason = requestBody.reason == null ? "" : requestBody.reason;
|
2024-05-08 23:48:19 +07:00
|
|
|
kpiReason.lastUpdateUserId = request.user.sub;
|
|
|
|
|
kpiReason.lastUpdateFullName = request.user.name;
|
2024-08-22 14:23:50 +07:00
|
|
|
await this.kpiUserEvaluationReasonRole.save(kpiReason, { data: request });
|
|
|
|
|
setLogDataDiff(request, { before, after: kpiReason });
|
|
|
|
|
|
2024-05-08 23:48:19 +07:00
|
|
|
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) {
|
2024-06-27 16:58:59 +07:00
|
|
|
if (type.trim().toUpperCase() == "PROBLEM") {
|
2024-06-30 20:51:04 +07:00
|
|
|
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);
|
|
|
|
|
}
|
2024-05-08 23:48:19 +07:00
|
|
|
} else {
|
|
|
|
|
if (user.trim().toUpperCase() == "USER") {
|
|
|
|
|
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonRole.find({
|
2024-05-14 01:45:55 +07:00
|
|
|
where: { kpiUserRoleId: id, type: type.trim().toUpperCase() },
|
2024-05-08 23:48:19 +07:00
|
|
|
});
|
|
|
|
|
return new HttpSuccess(kpiUserEvaluationReason);
|
|
|
|
|
} else if (user.trim().toUpperCase() == "EVALUATOR") {
|
|
|
|
|
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonRole.find({
|
|
|
|
|
where: {
|
|
|
|
|
kpiUserRoleId: id,
|
2024-05-14 01:45:55 +07:00
|
|
|
type: type.trim().toUpperCase(),
|
2024-05-08 23:48:19 +07:00
|
|
|
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,
|
2024-05-14 01:45:55 +07:00
|
|
|
type: type.trim().toUpperCase(),
|
2024-05-08 23:48:19 +07:00
|
|
|
status: In(["COMMANDER", "COMMANDERHIGH", "DONE"]),
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
return new HttpSuccess(kpiUserEvaluationReason);
|
|
|
|
|
} else if (user.trim().toUpperCase() == "COMMANDERHIGH") {
|
|
|
|
|
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonRole.find({
|
|
|
|
|
where: {
|
|
|
|
|
kpiUserRoleId: id,
|
2024-05-14 01:45:55 +07:00
|
|
|
type: type.trim().toUpperCase(),
|
2024-05-08 23:48:19 +07:00
|
|
|
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,
|
2024-08-22 14:23:50 +07:00
|
|
|
@Request() request: RequestWithUser,
|
2024-05-08 23:48:19 +07:00
|
|
|
) {
|
|
|
|
|
if (user.trim().toUpperCase() == "USER") {
|
|
|
|
|
const kpiUserEvaluation = await this.kpiUserSpecial.findOne({
|
|
|
|
|
where: { id: id },
|
2024-05-13 14:29:48 +07:00
|
|
|
relations: ["kpiUserEvaluation"],
|
2024-05-08 23:48:19 +07:00
|
|
|
});
|
2024-05-14 14:08:24 +07:00
|
|
|
let kpiUserEvaluationReason = Object.assign(
|
2024-05-08 23:48:19 +07:00
|
|
|
new KpiUserEvaluationReasonSpecial(),
|
|
|
|
|
requestBody,
|
|
|
|
|
);
|
|
|
|
|
kpiUserEvaluationReason.type = type.trim().toUpperCase();
|
2024-06-27 16:58:59 +07:00
|
|
|
if (type.trim().toUpperCase() == "PROBLEM") {
|
2024-05-14 14:08:24 +07:00
|
|
|
const _kpiUserEvaluationReason = await this.kpiUserEvaluationReasonSpecial.findOne({
|
|
|
|
|
where: { id: id },
|
2024-05-17 14:17:01 +07:00
|
|
|
relations: ["kpiUserSpecial", "kpiUserSpecial.kpiUserEvaluation"],
|
2024-05-14 14:08:24 +07:00
|
|
|
});
|
2024-05-17 14:17:01 +07:00
|
|
|
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";
|
|
|
|
|
}
|
2024-05-14 14:08:24 +07:00
|
|
|
} else {
|
2024-05-17 14:17:01 +07:00
|
|
|
if (!kpiUserEvaluation) {
|
|
|
|
|
throw new HttpError(
|
|
|
|
|
HttpStatusCode.NOT_FOUND,
|
|
|
|
|
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
|
|
|
|
|
);
|
|
|
|
|
}
|
2024-05-14 14:08:24 +07:00
|
|
|
kpiUserEvaluationReason.status =
|
|
|
|
|
kpiUserEvaluation.kpiUserEvaluation.evaluatorId == null ||
|
|
|
|
|
kpiUserEvaluation.kpiUserEvaluation.evaluatorId == ""
|
|
|
|
|
? "DONE"
|
|
|
|
|
: "EVALUATOR";
|
|
|
|
|
}
|
2024-08-22 14:23:50 +07:00
|
|
|
const before = structuredClone(kpiUserEvaluationReason);
|
|
|
|
|
|
2024-05-08 23:48:19 +07:00
|
|
|
kpiUserEvaluationReason.kpiUserSpecialId = id;
|
|
|
|
|
kpiUserEvaluationReason.createdUserId = request.user.sub;
|
|
|
|
|
kpiUserEvaluationReason.createdFullName = request.user.name;
|
|
|
|
|
kpiUserEvaluationReason.lastUpdateUserId = request.user.sub;
|
|
|
|
|
kpiUserEvaluationReason.lastUpdateFullName = request.user.name;
|
2024-08-22 14:23:50 +07:00
|
|
|
await this.kpiUserEvaluationReasonSpecial.save(kpiUserEvaluationReason, { data: request });
|
|
|
|
|
setLogDataDiff(request, { before, after: kpiUserEvaluationReason });
|
|
|
|
|
|
2024-05-08 23:48:19 +07:00
|
|
|
return new HttpSuccess(kpiUserEvaluationReason.id);
|
|
|
|
|
} else {
|
|
|
|
|
const kpiReason = await this.kpiUserEvaluationReasonSpecial.findOne({
|
|
|
|
|
where: { id: id },
|
2024-05-14 01:45:55 +07:00
|
|
|
relations: ["kpiUserSpecial", "kpiUserSpecial.kpiUserEvaluation"],
|
2024-05-08 23:48:19 +07:00
|
|
|
});
|
|
|
|
|
if (!kpiReason) {
|
|
|
|
|
throw new HttpError(
|
|
|
|
|
HttpStatusCode.NOT_FOUND,
|
|
|
|
|
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (user.trim().toUpperCase() == "EVALUATOR") {
|
2024-06-19 10:17:15 +07:00
|
|
|
kpiReason.reasonEvaluator = requestBody.reason == null ? "" : requestBody.reason;
|
2024-05-08 23:48:19 +07:00
|
|
|
kpiReason.status =
|
2024-05-14 09:39:27 +07:00
|
|
|
kpiReason.kpiUserSpecial.kpiUserEvaluation.commanderId == null ||
|
|
|
|
|
kpiReason.kpiUserSpecial.kpiUserEvaluation.commanderId == ""
|
|
|
|
|
? "DONE"
|
|
|
|
|
: "COMMANDER";
|
2024-05-08 23:48:19 +07:00
|
|
|
} else if (user.trim().toUpperCase() == "COMMANDER") {
|
2024-06-19 10:17:15 +07:00
|
|
|
kpiReason.reasonCommander = requestBody.reason == null ? "" : requestBody.reason;
|
2024-05-08 23:48:19 +07:00
|
|
|
kpiReason.status =
|
2024-05-14 09:39:27 +07:00
|
|
|
kpiReason.kpiUserSpecial.kpiUserEvaluation.commanderHighId == null ||
|
|
|
|
|
kpiReason.kpiUserSpecial.kpiUserEvaluation.commanderHighId == ""
|
2024-05-08 23:48:19 +07:00
|
|
|
? "DONE"
|
|
|
|
|
: "COMMANDERHIGH";
|
|
|
|
|
} else if (user.trim().toUpperCase() == "COMMANDERHIGH") {
|
2024-06-19 10:17:15 +07:00
|
|
|
kpiReason.reasonCommanderHigh = requestBody.reason == null ? "" : requestBody.reason;
|
2024-05-08 23:48:19 +07:00
|
|
|
kpiReason.status = "DONE";
|
|
|
|
|
}
|
2024-08-22 14:23:50 +07:00
|
|
|
const before = structuredClone(kpiReason);
|
|
|
|
|
|
2024-05-08 23:48:19 +07:00
|
|
|
kpiReason.lastUpdateUserId = request.user.sub;
|
|
|
|
|
kpiReason.lastUpdateFullName = request.user.name;
|
2024-08-22 14:23:50 +07:00
|
|
|
await this.kpiUserEvaluationReasonSpecial.save(kpiReason, { data: request });
|
|
|
|
|
setLogDataDiff(request, { before, after: kpiReason });
|
|
|
|
|
|
2024-05-08 23:48:19 +07:00
|
|
|
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,
|
2024-08-22 14:23:50 +07:00
|
|
|
@Request() request: RequestWithUser,
|
2024-05-08 23:48:19 +07:00
|
|
|
) {
|
|
|
|
|
const kpiReason = await this.kpiUserEvaluationReasonSpecial.findOne({
|
|
|
|
|
where: { id: id },
|
2024-05-14 01:45:55 +07:00
|
|
|
relations: ["kpiUserSpecial", "kpiUserSpecial.kpiUserEvaluation"],
|
2024-05-08 23:48:19 +07:00
|
|
|
});
|
|
|
|
|
if (!kpiReason) {
|
|
|
|
|
throw new HttpError(
|
|
|
|
|
HttpStatusCode.NOT_FOUND,
|
|
|
|
|
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
|
|
|
|
|
);
|
|
|
|
|
}
|
2024-08-22 14:23:50 +07:00
|
|
|
const before = structuredClone(kpiReason);
|
2024-05-08 23:48:19 +07:00
|
|
|
|
|
|
|
|
kpiReason.status =
|
2024-05-14 14:08:24 +07:00
|
|
|
kpiReason.kpiUserSpecial.kpiUserEvaluation.evaluatorId == null ||
|
|
|
|
|
kpiReason.kpiUserSpecial.kpiUserEvaluation.evaluatorId == ""
|
2024-05-14 09:39:27 +07:00
|
|
|
? "DONE"
|
2024-05-14 14:08:24 +07:00
|
|
|
: "EVALUATOR";
|
2024-06-19 10:17:15 +07:00
|
|
|
kpiReason.reason = requestBody.reason == null ? "" : requestBody.reason;
|
2024-05-08 23:48:19 +07:00
|
|
|
kpiReason.lastUpdateUserId = request.user.sub;
|
|
|
|
|
kpiReason.lastUpdateFullName = request.user.name;
|
2024-08-22 14:23:50 +07:00
|
|
|
await this.kpiUserEvaluationReasonSpecial.save(kpiReason, { data: request });
|
|
|
|
|
setLogDataDiff(request, { before, after: kpiReason });
|
|
|
|
|
|
2024-05-08 23:48:19 +07:00
|
|
|
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) {
|
2024-06-27 16:58:59 +07:00
|
|
|
if (type.trim().toUpperCase() == "PROBLEM") {
|
2024-06-30 20:51:04 +07:00
|
|
|
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);
|
|
|
|
|
}
|
2024-05-08 23:48:19 +07:00
|
|
|
} else {
|
|
|
|
|
if (user.trim().toUpperCase() == "USER") {
|
|
|
|
|
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonSpecial.find({
|
2024-05-14 01:45:55 +07:00
|
|
|
where: { kpiUserSpecialId: id, type: type.trim().toUpperCase() },
|
2024-05-08 23:48:19 +07:00
|
|
|
});
|
|
|
|
|
return new HttpSuccess(kpiUserEvaluationReason);
|
|
|
|
|
} else if (user.trim().toUpperCase() == "EVALUATOR") {
|
|
|
|
|
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonSpecial.find({
|
|
|
|
|
where: {
|
|
|
|
|
kpiUserSpecialId: id,
|
2024-05-14 01:45:55 +07:00
|
|
|
type: type.trim().toUpperCase(),
|
2024-05-08 23:48:19 +07:00
|
|
|
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,
|
2024-05-14 01:45:55 +07:00
|
|
|
type: type.trim().toUpperCase(),
|
2024-05-08 23:48:19 +07:00
|
|
|
status: In(["COMMANDER", "COMMANDERHIGH", "DONE"]),
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
return new HttpSuccess(kpiUserEvaluationReason);
|
|
|
|
|
} else if (user.trim().toUpperCase() == "COMMANDERHIGH") {
|
|
|
|
|
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonSpecial.find({
|
|
|
|
|
where: {
|
|
|
|
|
kpiUserSpecialId: id,
|
2024-05-14 01:45:55 +07:00
|
|
|
type: type.trim().toUpperCase(),
|
2024-05-08 23:48:19 +07:00
|
|
|
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,
|
2024-08-22 14:23:50 +07:00
|
|
|
@Request() request: RequestWithUser,
|
2024-05-08 23:48:19 +07:00
|
|
|
) {
|
|
|
|
|
if (user.trim().toUpperCase() == "USER") {
|
|
|
|
|
const kpiUserEvaluation = await this.kpiUserDevelopment.findOne({
|
|
|
|
|
where: { id: id },
|
2024-05-13 14:29:48 +07:00
|
|
|
relations: ["kpiUserEvaluation"],
|
2024-05-08 23:48:19 +07:00
|
|
|
});
|
2024-05-14 14:08:24 +07:00
|
|
|
let kpiUserEvaluationReason = Object.assign(
|
2024-05-08 23:48:19 +07:00
|
|
|
new KpiUserEvaluationReasonDevelopment(),
|
|
|
|
|
requestBody,
|
|
|
|
|
);
|
|
|
|
|
kpiUserEvaluationReason.type = type.trim().toUpperCase();
|
2024-06-27 16:58:59 +07:00
|
|
|
if (type.trim().toUpperCase() == "PROBLEM") {
|
2024-05-14 14:08:24 +07:00
|
|
|
const _kpiUserEvaluationReason = await this.kpiUserEvaluationReasonDevelopment.findOne({
|
|
|
|
|
where: { id: id },
|
2024-05-17 14:17:01 +07:00
|
|
|
relations: ["kpiUserDevelopment", "kpiUserDevelopment.kpiUserEvaluation"],
|
2024-05-14 14:08:24 +07:00
|
|
|
});
|
2024-05-17 14:17:01 +07:00
|
|
|
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";
|
|
|
|
|
}
|
2024-05-14 14:08:24 +07:00
|
|
|
} else {
|
2024-05-17 14:17:01 +07:00
|
|
|
if (!kpiUserEvaluation) {
|
|
|
|
|
throw new HttpError(
|
|
|
|
|
HttpStatusCode.NOT_FOUND,
|
|
|
|
|
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
|
|
|
|
|
);
|
|
|
|
|
}
|
2024-06-27 16:58:59 +07:00
|
|
|
kpiUserEvaluationReason.status = "DONE";
|
2024-05-14 14:08:24 +07:00
|
|
|
}
|
2024-08-22 14:23:50 +07:00
|
|
|
const before = structuredClone(kpiUserEvaluationReason);
|
|
|
|
|
|
2024-05-08 23:48:19 +07:00
|
|
|
kpiUserEvaluationReason.kpiUserDevelopmentId = id;
|
|
|
|
|
kpiUserEvaluationReason.createdUserId = request.user.sub;
|
|
|
|
|
kpiUserEvaluationReason.createdFullName = request.user.name;
|
|
|
|
|
kpiUserEvaluationReason.lastUpdateUserId = request.user.sub;
|
|
|
|
|
kpiUserEvaluationReason.lastUpdateFullName = request.user.name;
|
2024-08-22 14:23:50 +07:00
|
|
|
await this.kpiUserEvaluationReasonDevelopment.save(kpiUserEvaluationReason, {
|
|
|
|
|
data: request,
|
|
|
|
|
});
|
|
|
|
|
setLogDataDiff(request, { before, after: kpiUserEvaluationReason });
|
|
|
|
|
|
2024-05-08 23:48:19 +07:00
|
|
|
return new HttpSuccess(kpiUserEvaluationReason.id);
|
|
|
|
|
} else {
|
|
|
|
|
const kpiReason = await this.kpiUserEvaluationReasonDevelopment.findOne({
|
|
|
|
|
where: { id: id },
|
2024-05-14 01:45:55 +07:00
|
|
|
relations: ["kpiUserDevelopment", "kpiUserDevelopment.kpiUserEvaluation"],
|
2024-05-08 23:48:19 +07:00
|
|
|
});
|
|
|
|
|
if (!kpiReason) {
|
|
|
|
|
throw new HttpError(
|
|
|
|
|
HttpStatusCode.NOT_FOUND,
|
|
|
|
|
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (user.trim().toUpperCase() == "EVALUATOR") {
|
2024-06-19 10:17:15 +07:00
|
|
|
kpiReason.reasonEvaluator = requestBody.reason == null ? "" : requestBody.reason;
|
2024-05-08 23:48:19 +07:00
|
|
|
kpiReason.status =
|
2024-05-14 09:39:27 +07:00
|
|
|
kpiReason.kpiUserDevelopment.kpiUserEvaluation.commanderId == null ||
|
|
|
|
|
kpiReason.kpiUserDevelopment.kpiUserEvaluation.commanderId == ""
|
|
|
|
|
? "DONE"
|
|
|
|
|
: "COMMANDER";
|
2024-05-08 23:48:19 +07:00
|
|
|
} else if (user.trim().toUpperCase() == "COMMANDER") {
|
2024-06-19 10:17:15 +07:00
|
|
|
kpiReason.reasonCommander = requestBody.reason == null ? "" : requestBody.reason;
|
2024-05-08 23:48:19 +07:00
|
|
|
kpiReason.status =
|
2024-05-14 09:39:27 +07:00
|
|
|
kpiReason.kpiUserDevelopment.kpiUserEvaluation.commanderHighId == null ||
|
|
|
|
|
kpiReason.kpiUserDevelopment.kpiUserEvaluation.commanderHighId == ""
|
2024-05-08 23:48:19 +07:00
|
|
|
? "DONE"
|
|
|
|
|
: "COMMANDERHIGH";
|
|
|
|
|
} else if (user.trim().toUpperCase() == "COMMANDERHIGH") {
|
2024-06-19 10:17:15 +07:00
|
|
|
kpiReason.reasonCommanderHigh = requestBody.reason == null ? "" : requestBody.reason;
|
2024-05-08 23:48:19 +07:00
|
|
|
kpiReason.status = "DONE";
|
|
|
|
|
}
|
2024-08-22 14:23:50 +07:00
|
|
|
const before = structuredClone(kpiReason);
|
|
|
|
|
|
2024-05-08 23:48:19 +07:00
|
|
|
kpiReason.lastUpdateUserId = request.user.sub;
|
|
|
|
|
kpiReason.lastUpdateFullName = request.user.name;
|
2024-08-22 14:23:50 +07:00
|
|
|
await this.kpiUserEvaluationReasonDevelopment.save(kpiReason, { data: request });
|
|
|
|
|
setLogDataDiff(request, { before, after: kpiReason });
|
|
|
|
|
|
2024-05-08 23:48:19 +07:00
|
|
|
return new HttpSuccess(kpiReason.id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* API แก้ไขหมายเหตุ (USER)
|
|
|
|
|
*
|
|
|
|
|
* @summary แก้ไขหมายเหตุ (USER)
|
|
|
|
|
*
|
|
|
|
|
* @param {string} id Guid, *Id คนประเมิน (USER)
|
|
|
|
|
*/
|
2024-05-14 14:08:24 +07:00
|
|
|
@Put("problem/developmentsend/user/{id}")
|
2024-05-08 23:48:19 +07:00
|
|
|
async sendKpiDevelopmentReason(
|
|
|
|
|
@Path() id: string,
|
|
|
|
|
@Body() requestBody: updateKpiUserReasonEvaluation,
|
2024-08-22 14:23:50 +07:00
|
|
|
@Request() request: RequestWithUser,
|
2024-05-08 23:48:19 +07:00
|
|
|
) {
|
|
|
|
|
const kpiReason = await this.kpiUserEvaluationReasonDevelopment.findOne({
|
|
|
|
|
where: { id: id },
|
2024-05-14 01:45:55 +07:00
|
|
|
relations: ["kpiUserDevelopment", "kpiUserDevelopment.kpiUserEvaluation"],
|
2024-05-08 23:48:19 +07:00
|
|
|
});
|
|
|
|
|
if (!kpiReason) {
|
|
|
|
|
throw new HttpError(
|
|
|
|
|
HttpStatusCode.NOT_FOUND,
|
|
|
|
|
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
|
|
|
|
|
);
|
|
|
|
|
}
|
2024-08-22 14:23:50 +07:00
|
|
|
const before = structuredClone(kpiReason);
|
2024-05-08 23:48:19 +07:00
|
|
|
|
|
|
|
|
kpiReason.status =
|
2024-05-14 14:08:24 +07:00
|
|
|
kpiReason.kpiUserDevelopment.kpiUserEvaluation.evaluatorId == null ||
|
|
|
|
|
kpiReason.kpiUserDevelopment.kpiUserEvaluation.evaluatorId == ""
|
2024-05-14 09:39:27 +07:00
|
|
|
? "DONE"
|
2024-05-14 14:08:24 +07:00
|
|
|
: "EVALUATOR";
|
2024-06-19 10:17:15 +07:00
|
|
|
kpiReason.reason = requestBody.reason == null ? "" : requestBody.reason;
|
2024-05-08 23:48:19 +07:00
|
|
|
kpiReason.lastUpdateUserId = request.user.sub;
|
|
|
|
|
kpiReason.lastUpdateFullName = request.user.name;
|
2024-08-22 14:23:50 +07:00
|
|
|
await this.kpiUserEvaluationReasonDevelopment.save(kpiReason, { data: request });
|
|
|
|
|
setLogDataDiff(request, { before, after: kpiReason });
|
|
|
|
|
|
2024-05-08 23:48:19 +07:00
|
|
|
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,
|
|
|
|
|
) {
|
2024-06-27 16:58:59 +07:00
|
|
|
if (type.trim().toUpperCase() == "PROBLEM") {
|
2024-06-30 20:51:04 +07:00
|
|
|
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);
|
|
|
|
|
}
|
2024-05-08 23:48:19 +07:00
|
|
|
} else {
|
|
|
|
|
if (user.trim().toUpperCase() == "USER") {
|
|
|
|
|
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonDevelopment.find({
|
2024-05-14 01:45:55 +07:00
|
|
|
where: { kpiUserDevelopmentId: id, type: type.trim().toUpperCase() },
|
2024-05-08 23:48:19 +07:00
|
|
|
});
|
|
|
|
|
return new HttpSuccess(kpiUserEvaluationReason);
|
|
|
|
|
} else if (user.trim().toUpperCase() == "EVALUATOR") {
|
|
|
|
|
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonDevelopment.find({
|
|
|
|
|
where: {
|
|
|
|
|
kpiUserDevelopmentId: id,
|
2024-05-14 01:45:55 +07:00
|
|
|
type: type.trim().toUpperCase(),
|
2024-05-08 23:48:19 +07:00
|
|
|
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,
|
2024-05-14 01:45:55 +07:00
|
|
|
type: type.trim().toUpperCase(),
|
2024-05-08 23:48:19 +07:00
|
|
|
status: In(["COMMANDER", "COMMANDERHIGH", "DONE"]),
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
return new HttpSuccess(kpiUserEvaluationReason);
|
|
|
|
|
} else if (user.trim().toUpperCase() == "COMMANDERHIGH") {
|
|
|
|
|
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonDevelopment.find({
|
|
|
|
|
where: {
|
|
|
|
|
kpiUserDevelopmentId: id,
|
2024-05-14 01:45:55 +07:00
|
|
|
type: type.trim().toUpperCase(),
|
2024-05-08 23:48:19 +07:00
|
|
|
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,
|
2024-08-22 14:23:50 +07:00
|
|
|
@Request() request: RequestWithUser,
|
2024-05-08 23:48:19 +07:00
|
|
|
) {
|
|
|
|
|
if (user.trim().toUpperCase() == "USER") {
|
|
|
|
|
const kpiUserEvaluation = await this.kpiUserCapacity.findOne({
|
|
|
|
|
where: { id: id },
|
2024-05-13 14:29:48 +07:00
|
|
|
relations: ["kpiUserEvaluation"],
|
2024-05-08 23:48:19 +07:00
|
|
|
});
|
2024-05-14 14:08:24 +07:00
|
|
|
let kpiUserEvaluationReason = Object.assign(
|
2024-05-08 23:48:19 +07:00
|
|
|
new KpiUserEvaluationReasonCapacity(),
|
|
|
|
|
requestBody,
|
|
|
|
|
);
|
|
|
|
|
kpiUserEvaluationReason.type = type.trim().toUpperCase();
|
2024-06-27 16:58:59 +07:00
|
|
|
if (type.trim().toUpperCase() == "PROBLEM") {
|
2024-05-14 14:08:24 +07:00
|
|
|
const _kpiUserEvaluationReason = await this.kpiUserEvaluationReasonCapacity.findOne({
|
|
|
|
|
where: { id: id },
|
2024-05-17 14:17:01 +07:00
|
|
|
relations: ["kpiUserCapacity", "kpiUserCapacity.kpiUserEvaluation"],
|
2024-05-14 14:08:24 +07:00
|
|
|
});
|
2024-05-17 14:17:01 +07:00
|
|
|
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";
|
|
|
|
|
}
|
2024-05-14 14:08:24 +07:00
|
|
|
} else {
|
2024-05-17 14:17:01 +07:00
|
|
|
if (!kpiUserEvaluation) {
|
|
|
|
|
throw new HttpError(
|
|
|
|
|
HttpStatusCode.NOT_FOUND,
|
|
|
|
|
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
|
|
|
|
|
);
|
|
|
|
|
}
|
2024-06-27 16:58:59 +07:00
|
|
|
kpiUserEvaluationReason.status = "DONE";
|
2024-05-14 14:08:24 +07:00
|
|
|
}
|
2024-08-22 14:23:50 +07:00
|
|
|
const before = structuredClone(kpiUserEvaluationReason);
|
|
|
|
|
|
2024-05-08 23:48:19 +07:00
|
|
|
kpiUserEvaluationReason.kpiUserCapacityId = id;
|
|
|
|
|
kpiUserEvaluationReason.createdUserId = request.user.sub;
|
|
|
|
|
kpiUserEvaluationReason.createdFullName = request.user.name;
|
|
|
|
|
kpiUserEvaluationReason.lastUpdateUserId = request.user.sub;
|
|
|
|
|
kpiUserEvaluationReason.lastUpdateFullName = request.user.name;
|
2024-08-22 14:23:50 +07:00
|
|
|
await this.kpiUserEvaluationReasonCapacity.save(kpiUserEvaluationReason, { data: request });
|
|
|
|
|
setLogDataDiff(request, { before, after: kpiUserEvaluationReason });
|
|
|
|
|
|
2024-05-08 23:48:19 +07:00
|
|
|
return new HttpSuccess(kpiUserEvaluationReason.id);
|
|
|
|
|
} else {
|
|
|
|
|
const kpiReason = await this.kpiUserEvaluationReasonCapacity.findOne({
|
|
|
|
|
where: { id: id },
|
2024-05-14 01:45:55 +07:00
|
|
|
relations: ["kpiUserCapacity", "kpiUserCapacity.kpiUserEvaluation"],
|
2024-05-08 23:48:19 +07:00
|
|
|
});
|
|
|
|
|
if (!kpiReason) {
|
|
|
|
|
throw new HttpError(
|
|
|
|
|
HttpStatusCode.NOT_FOUND,
|
|
|
|
|
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (user.trim().toUpperCase() == "EVALUATOR") {
|
2024-06-19 10:17:15 +07:00
|
|
|
kpiReason.reasonEvaluator = requestBody.reason == null ? "" : requestBody.reason;
|
2024-05-08 23:48:19 +07:00
|
|
|
kpiReason.status =
|
2024-05-14 09:39:27 +07:00
|
|
|
kpiReason.kpiUserCapacity.kpiUserEvaluation.commanderId == null ||
|
|
|
|
|
kpiReason.kpiUserCapacity.kpiUserEvaluation.commanderId == ""
|
|
|
|
|
? "DONE"
|
|
|
|
|
: "COMMANDER";
|
2024-05-08 23:48:19 +07:00
|
|
|
} else if (user.trim().toUpperCase() == "COMMANDER") {
|
2024-06-19 10:17:15 +07:00
|
|
|
kpiReason.reasonCommander = requestBody.reason == null ? "" : requestBody.reason;
|
2024-05-08 23:48:19 +07:00
|
|
|
kpiReason.status =
|
2024-05-14 09:39:27 +07:00
|
|
|
kpiReason.kpiUserCapacity.kpiUserEvaluation.commanderHighId == null ||
|
|
|
|
|
kpiReason.kpiUserCapacity.kpiUserEvaluation.commanderHighId == ""
|
2024-05-08 23:48:19 +07:00
|
|
|
? "DONE"
|
|
|
|
|
: "COMMANDERHIGH";
|
|
|
|
|
} else if (user.trim().toUpperCase() == "COMMANDERHIGH") {
|
2024-06-19 10:17:15 +07:00
|
|
|
kpiReason.reasonCommanderHigh = requestBody.reason == null ? "" : requestBody.reason;
|
2024-05-08 23:48:19 +07:00
|
|
|
kpiReason.status = "DONE";
|
|
|
|
|
}
|
2024-08-22 14:23:50 +07:00
|
|
|
const before = structuredClone(kpiReason);
|
|
|
|
|
|
2024-05-08 23:48:19 +07:00
|
|
|
kpiReason.lastUpdateUserId = request.user.sub;
|
|
|
|
|
kpiReason.lastUpdateFullName = request.user.name;
|
2024-08-22 14:23:50 +07:00
|
|
|
await this.kpiUserEvaluationReasonCapacity.save(kpiReason, { data: request });
|
|
|
|
|
setLogDataDiff(request, { before, after: kpiReason });
|
|
|
|
|
|
2024-05-08 23:48:19 +07:00
|
|
|
return new HttpSuccess(kpiReason.id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* API แก้ไขหมายเหตุ (USER)
|
|
|
|
|
*
|
|
|
|
|
* @summary แก้ไขหมายเหตุ (USER)
|
|
|
|
|
*
|
|
|
|
|
* @param {string} id Guid, *Id คนประเมิน (USER)
|
|
|
|
|
*/
|
2024-05-14 14:08:24 +07:00
|
|
|
@Put("problem/capacitysend/user/{id}")
|
2024-05-08 23:48:19 +07:00
|
|
|
async sendKpiCapacityReason(
|
|
|
|
|
@Path() id: string,
|
|
|
|
|
@Body() requestBody: updateKpiUserReasonEvaluation,
|
2024-08-22 14:23:50 +07:00
|
|
|
@Request() request: RequestWithUser,
|
2024-05-08 23:48:19 +07:00
|
|
|
) {
|
|
|
|
|
const kpiReason = await this.kpiUserEvaluationReasonCapacity.findOne({
|
|
|
|
|
where: { id: id },
|
2024-05-14 01:45:55 +07:00
|
|
|
relations: ["kpiUserCapacity", "kpiUserCapacity.kpiUserEvaluation"],
|
2024-05-08 23:48:19 +07:00
|
|
|
});
|
|
|
|
|
if (!kpiReason) {
|
|
|
|
|
throw new HttpError(
|
|
|
|
|
HttpStatusCode.NOT_FOUND,
|
|
|
|
|
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
|
|
|
|
|
);
|
|
|
|
|
}
|
2024-08-22 14:23:50 +07:00
|
|
|
const before = structuredClone(kpiReason);
|
2024-05-08 23:48:19 +07:00
|
|
|
|
|
|
|
|
kpiReason.status =
|
2024-05-14 14:08:24 +07:00
|
|
|
kpiReason.kpiUserCapacity.kpiUserEvaluation.evaluatorId == null ||
|
|
|
|
|
kpiReason.kpiUserCapacity.kpiUserEvaluation.evaluatorId == ""
|
2024-05-14 09:39:27 +07:00
|
|
|
? "DONE"
|
2024-05-14 14:08:24 +07:00
|
|
|
: "EVALUATOR";
|
2024-06-19 10:17:15 +07:00
|
|
|
kpiReason.reason = requestBody.reason == null ? "" : requestBody.reason;
|
2024-05-08 23:48:19 +07:00
|
|
|
kpiReason.lastUpdateUserId = request.user.sub;
|
|
|
|
|
kpiReason.lastUpdateFullName = request.user.name;
|
2024-08-22 14:23:50 +07:00
|
|
|
await this.kpiUserEvaluationReasonCapacity.save(kpiReason, { data: request });
|
|
|
|
|
setLogDataDiff(request, { before, after: kpiReason });
|
|
|
|
|
|
2024-05-08 23:48:19 +07:00
|
|
|
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) {
|
2024-06-27 16:58:59 +07:00
|
|
|
if (type.trim().toUpperCase() == "PROBLEM") {
|
2024-06-30 20:51:04 +07:00
|
|
|
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);
|
|
|
|
|
}
|
2024-05-08 23:48:19 +07:00
|
|
|
} else {
|
|
|
|
|
if (user.trim().toUpperCase() == "USER") {
|
|
|
|
|
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonCapacity.find({
|
2024-05-14 01:45:55 +07:00
|
|
|
where: { kpiUserCapacityId: id, type: type.trim().toUpperCase() },
|
2024-05-08 23:48:19 +07:00
|
|
|
});
|
|
|
|
|
return new HttpSuccess(kpiUserEvaluationReason);
|
|
|
|
|
} else if (user.trim().toUpperCase() == "EVALUATOR") {
|
|
|
|
|
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonCapacity.find({
|
|
|
|
|
where: {
|
|
|
|
|
kpiUserCapacityId: id,
|
2024-05-14 01:45:55 +07:00
|
|
|
type: type.trim().toUpperCase(),
|
2024-05-08 23:48:19 +07:00
|
|
|
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,
|
2024-05-14 01:45:55 +07:00
|
|
|
type: type.trim().toUpperCase(),
|
2024-05-08 23:48:19 +07:00
|
|
|
status: In(["COMMANDER", "COMMANDERHIGH", "DONE"]),
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
return new HttpSuccess(kpiUserEvaluationReason);
|
|
|
|
|
} else if (user.trim().toUpperCase() == "COMMANDERHIGH") {
|
|
|
|
|
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonCapacity.find({
|
|
|
|
|
where: {
|
|
|
|
|
kpiUserCapacityId: id,
|
2024-05-14 01:45:55 +07:00
|
|
|
type: type.trim().toUpperCase(),
|
2024-05-08 23:48:19 +07:00
|
|
|
status: In(["COMMANDERHIGH", "DONE"]),
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
return new HttpSuccess(kpiUserEvaluationReason);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|