เกณฑ์การประเมิน

This commit is contained in:
AdisakKanthawilang 2024-04-18 17:20:46 +07:00
parent a009da25b7
commit ad00638b11
2 changed files with 38 additions and 36 deletions

View file

@ -32,41 +32,39 @@ import { KpiEvaluation, updateKpiEvaluation } from "../entities/kpiEvaluation";
export class kpiEvaluationController extends Controller {
private kpiEvaluationRepository = AppDataSource.getRepository(KpiEvaluation);
// /**
// * API แก้ไขเกณฑ์การประเมิน
// * @param id ไอดีของเกณฑ์การประเมิน
// */
// @Put("{id}")
// async updateKpiEvaluation(
// @Path() id: string,
// @Body() requestBody: updateKpiEvaluation,
// @Request() request: { user: Record<string, any> },
// ) {
// const kpiEvaluation = await this.kpiEvaluationRepository.findOne({
// where: { id: id },
// });
// if (!kpiEvaluation) {
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลเกณฑ์การประเมินนี้");
// }
/**
* API
* @param id
*/
@Put()
async updateKpiEvaluations(
@Body() requestBody: updateKpiEvaluation[],
@Request() request: { user: Record<string, any> },
) {
const updatedIds: string[] = [];
// // const chkkpinameGroup = await this.kpiGroupRepository.findOne({
// // where: {
// // nameGroupKPI: requestBody.nameGroupKPI,
// // },
// // });
// // if (chkkpinameGroup) {
// // throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อกลุ่มงานนี้มีอยู่ในระบบแล้ว");
// // }
for (const item of requestBody) {
const kpiEvaluation = await this.kpiEvaluationRepository.findOne({
where: { id: item.id },
});
if (!kpiEvaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, `ไม่พบข้อมูลเกณฑ์การประเมินนี้: ${item.id}`);
}
this.kpiEvaluationRepository.merge(kpiEvaluation, item);
kpiEvaluation.lastUpdateUserId = request.user.sub;
kpiEvaluation.lastUpdateFullName = request.user.name;
await this.kpiEvaluationRepository.save(kpiEvaluation);
updatedIds.push(item.id);
}
return new HttpSuccess();
}
// this.kpiEvaluationRepository.merge(kpiEvaluation, requestBody);
// kpiEvaluation.lastUpdateUserId = request.user.sub;
// kpiEvaluation.lastUpdateFullName = request.user.name;
// await this.kpiEvaluationRepository.save(kpiEvaluation);
// return new HttpSuccess(id);
// }
/**
* API list
* API list
* @param page
* @param pageSize
*/
@ -80,13 +78,17 @@ export class kpiEvaluationController extends Controller {
if (keyword !== undefined && keyword !== "") {
whereClause = {
where: [{ nameGroupKPI: Like(`%${keyword}%`) }],
where: [{ description: Like(`%${keyword}%`) }],
};
}
whereClause.where.push({ level: Like(`%${keyword}%`) });
}
const [kpiEvaluation, total] = await this.kpiEvaluationRepository.findAndCount({
...whereClause,
...(keyword ? {} : { skip: (page - 1) * pageSize, take: pageSize }),
order:{
level: "DESC"}
});
return new HttpSuccess({ data: kpiEvaluation, total });