From 60cb5b747973b773b13c4aac1c3c48020f3c7f7e Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Fri, 19 Apr 2024 10:31:18 +0700 Subject: [PATCH] checkpoint --- src/controllers/KpiLinkController.ts | 159 +++++++++++++++++++++++++++ 1 file changed, 159 insertions(+) create mode 100644 src/controllers/KpiLinkController.ts diff --git a/src/controllers/KpiLinkController.ts b/src/controllers/KpiLinkController.ts new file mode 100644 index 0000000..39c0d57 --- /dev/null +++ b/src/controllers/KpiLinkController.ts @@ -0,0 +1,159 @@ +// 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 { KpiLink, createKpiLink, updateKpiLink } from "../entities/kpiLink"; +// @Route("api/v1/kpi/link") +// @Tags("kpiLink") +// @Security("bearerAuth") +// @Response( +// HttpStatusCode.INTERNAL_SERVER_ERROR, +// "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง", +// ) +// @SuccessResponse(HttpStatusCode.OK, "สำเร็จ") +// export class kpiLinkController extends Controller { +// private kpiLinkRepository = AppDataSource.getRepository(KpiLink); + +// /** +// * API สร้างเชื่อมโยง +// * @param requestBody +// * @returns +// */ +// @Post() +// @Example({ +// nameLinkKPI: "string", //ชื่อเชื่อมโยง +// }) +// async createKpiLink( +// @Body() requestBody: createKpiLink, +// @Request() request: { user: Record }, +// ) { +// const kpiLink = Object.assign(new KpiLink(), requestBody); +// const chkkpinameLink = await this.kpiLinkRepository.findOne({ +// where: { +// nameLinkKPI: requestBody.nameLinkKPI, +// }, +// }); +// if (chkkpinameLink) { +// throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อเชื่อมโยงนี้มีอยู่ในระบบแล้ว"); +// } +// kpiLink.createdUserId = request.user.sub; +// kpiLink.createdFullName = request.user.name; +// kpiLink.lastUpdateUserId = request.user.sub; +// kpiLink.lastUpdateFullName = request.user.name; +// await this.kpiLinkRepository.save(kpiLink); +// return new HttpSuccess(kpiLink.id); +// } + +// /** +// * API แก้ไขชื่อเชื่อมโยง +// * @param id ไอดีของเชื่อมโยง +// */ +// @Put("{id}") +// async updateKpiLink( +// @Path() id: string, +// @Body() requestBody: updateKpiLink, +// @Request() request: { user: Record }, +// ) { +// const kpiLink = await this.kpiLinkRepository.findOne({ +// where: { id: id }, +// }); +// if (!kpiLink) { +// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลเชื่อมโยงนี้"); +// } + +// const chkkpinameLink = await this.kpiLinkRepository.findOne({ +// where: { +// nameLinkKPI: requestBody.nameLinkKPI, +// }, +// }); +// if (chkkpinameLink) { +// throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อเชื่อมโยงนี้มีอยู่ในระบบแล้ว"); +// } +// this.kpiLinkRepository.merge(kpiLink, requestBody); +// kpiLink.lastUpdateUserId = request.user.sub; +// kpiLink.lastUpdateFullName = request.user.name; +// await this.kpiLinkRepository.save(kpiLink); +// return new HttpSuccess(id); +// } + +// /** +// * API ชื่อเชื่อมโยง +// * @param id +// */ +// @Get("{id}") +// @Example({ +// nameLinkKPI: "string", //ชื่อเชื่อมโยง +// }) +// async KpiLinkById(@Path() id: string) { +// const kpiLink = await this.kpiLinkRepository.findOne({ +// where: { id: id }, +// select: ["nameLinkKPI"], +// }); +// if (!kpiLink) { +// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลเชื่อมโยงนี้"); +// } +// return new HttpSuccess(kpiLink); +// } + +// /** +// * API ลบเชื่อมโยง +// * @param id +// */ +// @Delete("{id}") +// async deleteKpiLink(@Path() id: string) { +// const kpiLink = await this.kpiLinkRepository.findOne({ +// where: { id: id }, +// }); +// if (!kpiLink) { +// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลเชื่อมโยงนี้"); +// } + +// await this.kpiLinkRepository.remove(kpiLink); +// return new HttpSuccess(); +// } + +// /** +// * API list เชื่อมโยง +// * @param page +// * @param pageSize +// */ +// @Get() +// async listKpiLink( +// @Query("page") page: number = 1, +// @Query("pageSize") pageSize: number = 10, +// @Query("keyword") keyword?: string, +// ) { +// let whereClause: any = {}; + +// if (keyword !== undefined && keyword !== "") { +// whereClause = { +// where: [{ nameLinkKPI: Like(`%${keyword}%`) }], +// }; +// } + +// const [kpiLink, total] = await this.kpiLinkRepository.findAndCount({ +// ...whereClause, +// ...(keyword ? {} : { skip: (page - 1) * pageSize, take: pageSize }), +// }); + +// return new HttpSuccess({ data: kpiLink, total }); +// } +// }