capacity controller
This commit is contained in:
parent
396ef9400e
commit
68accac261
1 changed files with 174 additions and 0 deletions
174
src/controllers/KpiCapacityController.ts
Normal file
174
src/controllers/KpiCapacityController.ts
Normal file
|
|
@ -0,0 +1,174 @@
|
|||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Put,
|
||||
Delete,
|
||||
Route,
|
||||
Security,
|
||||
Tags,
|
||||
Body,
|
||||
Path,
|
||||
Request,
|
||||
Example,
|
||||
SuccessResponse,
|
||||
Response,
|
||||
Query,
|
||||
ArrayValidator
|
||||
} 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 { KpiCapacity, createKpiCapacity, updateKpiCapacity } from "../entities/kpiCapacity";
|
||||
import { KpiCapacityDetail, createKpiCapacityDetail, updateKpiCapacityDetail } from "../entities/kpiCapacityDetail";
|
||||
import { Like } from "typeorm/browser";
|
||||
|
||||
@Route("api/v1/kpi/capacity")
|
||||
@Tags("kpiCapacity")
|
||||
@Security("bearerAuth")
|
||||
@Response(
|
||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
|
||||
)
|
||||
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||
export class kpiCapacityController extends Controller {
|
||||
private kpiCapacityRepository = AppDataSource.getRepository(KpiCapacity);
|
||||
private kpiCapacityDetailRepository = AppDataSource.getRepository(KpiCapacityDetail);
|
||||
|
||||
/**
|
||||
* สร้างรายการสมรรถนะ
|
||||
* @param requestBody
|
||||
* @param request
|
||||
*/
|
||||
@Post()
|
||||
@Example({
|
||||
type: "HEAD", //ประเภทสมรรถนะ
|
||||
name: "รายการสมรรถะ 1", //ชื่อสมรรถนะ
|
||||
description: "รายละเอียดรายการสมรรถะ 1", //คำจำกัดความ
|
||||
kpiCapacityDetails: [{
|
||||
level: 1, //ระดับ
|
||||
description: "คำอธิบายระดับ" //คำอธิบายระดับ
|
||||
}]
|
||||
})
|
||||
async createKpiCapacity(
|
||||
// @Body() requestBody: createKpiCapacity,
|
||||
@Body() requestBody: {
|
||||
type: string
|
||||
name: string
|
||||
description: string
|
||||
kpiCapacityDetails: {
|
||||
level: number;
|
||||
description: string;
|
||||
}[];
|
||||
},
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
const kpiCapacity = Object.assign(new KpiCapacity(), requestBody);
|
||||
kpiCapacity.createdUserId = request.user.sub;
|
||||
kpiCapacity.createdFullName = request.user.name;
|
||||
kpiCapacity.lastUpdateUserId = request.user.sub;
|
||||
kpiCapacity.lastUpdateFullName = request.user.name;
|
||||
await this.kpiCapacityRepository.save(kpiCapacity);
|
||||
return new HttpSuccess(kpiCapacity.id);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * API แก้ไขรอบการประเมินผลการปฏิบัติหน้าที่ราชการ
|
||||
// * @param id
|
||||
// * @param requestBody
|
||||
// * @param request
|
||||
// */
|
||||
// @Put("{id}")
|
||||
// async updateKpiPeriod(
|
||||
// @Path() id: string,
|
||||
// @Body() requestBody: updateKpiPeriod,
|
||||
// @Request() request: { user: Record<string, any> },
|
||||
// ) {
|
||||
// const kpiPeriod = await this.kpiPeriodRepository.findOne({
|
||||
// where: { id: id },
|
||||
// });
|
||||
// if (!kpiPeriod) {
|
||||
// throw new HttpError(
|
||||
// HttpStatusCode.NOT_FOUND,
|
||||
// "ไม่พบข้อมูลรอบการประเมินผลการปฏิบัติหน้าที่ราชการนี้",
|
||||
// );
|
||||
// }
|
||||
|
||||
// requestBody.durationKPI = requestBody.durationKPI.trim().toUpperCase();
|
||||
// this.kpiPeriodRepository.merge(kpiPeriod, requestBody);
|
||||
// kpiPeriod.createdUserId = request.user.sub;
|
||||
// kpiPeriod.createdFullName = request.user.name;
|
||||
// kpiPeriod.lastUpdateUserId = request.user.sub;
|
||||
// kpiPeriod.lastUpdateFullName = request.user.name;
|
||||
// await this.kpiPeriodRepository.save(kpiPeriod);
|
||||
// return new HttpSuccess(id);
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * API รอบการประเมินผลการปฏิบัติหน้าที่ราชการ
|
||||
// * @param id Guid, *Id รอบการประเมินผลการปฏิบัติหน้าที่ราชการ
|
||||
// */
|
||||
// @Get("{id}")
|
||||
// @Example({
|
||||
// durationKPI: "string", //รอบเดือนที่สร้าง
|
||||
// startDate: "datetime", //วันเริ่มต้น
|
||||
// endDate: "datetime", //วันสิ้นสุด
|
||||
// })
|
||||
// async GetKpiPeriodById(@Path() id: string) {
|
||||
// const kpiPeriod = await this.kpiPeriodRepository.findOne({
|
||||
// where: { id: id },
|
||||
// select: ["durationKPI", "startDate", "endDate", "isActive"],
|
||||
// });
|
||||
// if (!kpiPeriod) {
|
||||
// throw new HttpError(
|
||||
// HttpStatusCode.NOT_FOUND,
|
||||
// "ไม่พบข้อมูลรอบการประเมินผลการปฏิบัติหน้าที่ราชการนี้",
|
||||
// );
|
||||
// }
|
||||
// return new HttpSuccess(kpiPeriod);
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * API list รอบการประเมินผลการปฏิบัติหน้าที่ราชการ
|
||||
// * @param page
|
||||
// * @param pageSize
|
||||
// * @param keyword
|
||||
// */
|
||||
// @Get()
|
||||
// async listKpiPeriod(
|
||||
// @Query("page") page: number = 1,
|
||||
// @Query("pageSize") pageSize: number = 10,
|
||||
// @Query("year") year?: string,
|
||||
// @Query("keyword") keyword?: string,
|
||||
// ) {
|
||||
// const [kpiPeriod, total] = await this.kpiPeriodRepository.findAndCount({
|
||||
// // where: {
|
||||
// // durationKPI: Like(`%${keyword}%`),
|
||||
// // },
|
||||
// ...(keyword ? {} : { skip: (page - 1) * pageSize, take: pageSize }),
|
||||
// });
|
||||
|
||||
// return new HttpSuccess({ data: kpiPeriod, total });
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * API ลบรอบการประเมินผลการปฏิบัติหน้าที่ราชการ
|
||||
// * @param id
|
||||
// */
|
||||
// @Delete("{id}")
|
||||
// async deleteKpiPerriod(@Path() id: string) {
|
||||
// const kpiPeriod = await this.kpiPeriodRepository.findOne({
|
||||
// where: { id: id },
|
||||
// });
|
||||
// if (!kpiPeriod) {
|
||||
// throw new HttpError(
|
||||
// HttpStatusCode.NOT_FOUND,
|
||||
// "ไม่พบข้อมูลรอบการประเมินผลการปฏิบัติหน้าที่ราชการนี้",
|
||||
// );
|
||||
// }
|
||||
|
||||
// await this.kpiPeriodRepository.remove(kpiPeriod);
|
||||
// return new HttpSuccess();
|
||||
// }
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue