95 lines
3 KiB
TypeScript
95 lines
3 KiB
TypeScript
|
|
import {
|
||
|
|
Controller,
|
||
|
|
Get,
|
||
|
|
Post,
|
||
|
|
Put,
|
||
|
|
Delete,
|
||
|
|
Route,
|
||
|
|
Security,
|
||
|
|
Tags,
|
||
|
|
Body,
|
||
|
|
Path,
|
||
|
|
Request,
|
||
|
|
Example,
|
||
|
|
SuccessResponse,
|
||
|
|
Response,
|
||
|
|
Query,
|
||
|
|
} from "tsoa";
|
||
|
|
import { AppDataSource } from "../database/data-source";
|
||
|
|
import HttpSuccess from "../interfaces/http-success";
|
||
|
|
import HttpError from "../interfaces/http-error";
|
||
|
|
import { Like, Not } from "typeorm";
|
||
|
|
import HttpStatusCode from "../interfaces/http-status";
|
||
|
|
import { KpiEvaluation, updateKpiEvaluation } from "../entities/kpiEvaluation";
|
||
|
|
@Route("api/v1/kpi/evaluation")
|
||
|
|
@Tags("kpiEvaluation")
|
||
|
|
@Security("bearerAuth")
|
||
|
|
@Response(
|
||
|
|
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||
|
|
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
|
||
|
|
)
|
||
|
|
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||
|
|
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, "ไม่พบข้อมูลเกณฑ์การประเมินนี้");
|
||
|
|
// }
|
||
|
|
|
||
|
|
// // const chkkpinameGroup = await this.kpiGroupRepository.findOne({
|
||
|
|
// // where: {
|
||
|
|
// // nameGroupKPI: requestBody.nameGroupKPI,
|
||
|
|
// // },
|
||
|
|
// // });
|
||
|
|
// // if (chkkpinameGroup) {
|
||
|
|
// // throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อกลุ่มงานนี้มีอยู่ในระบบแล้ว");
|
||
|
|
// // }
|
||
|
|
|
||
|
|
// 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 กลุ่มงาน
|
||
|
|
* @param page
|
||
|
|
* @param pageSize
|
||
|
|
*/
|
||
|
|
@Get()
|
||
|
|
async listKpiEvaluation(
|
||
|
|
@Query("page") page: number = 1,
|
||
|
|
@Query("pageSize") pageSize: number = 10,
|
||
|
|
@Query("keyword") keyword?: string,
|
||
|
|
) {
|
||
|
|
let whereClause: any = {};
|
||
|
|
|
||
|
|
if (keyword !== undefined && keyword !== "") {
|
||
|
|
whereClause = {
|
||
|
|
where: [{ nameGroupKPI: Like(`%${keyword}%`) }],
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
const [kpiEvaluation, total] = await this.kpiEvaluationRepository.findAndCount({
|
||
|
|
...whereClause,
|
||
|
|
...(keyword ? {} : { skip: (page - 1) * pageSize, take: pageSize }),
|
||
|
|
});
|
||
|
|
|
||
|
|
return new HttpSuccess({ data: kpiEvaluation, total });
|
||
|
|
}
|
||
|
|
}
|