234 lines
8.2 KiB
TypeScript
234 lines
8.2 KiB
TypeScript
// import {
|
|
// Controller,
|
|
// Get,
|
|
// Post,
|
|
// Put,
|
|
// Delete,
|
|
// Patch,
|
|
// 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 HttpStatusCode from "../interfaces/http-status";
|
|
// import { KpiUserPlanned, CreateKpiUserPlanned, UpdateKpiUserPlanned } from "../entities/KpiUserPlanned";
|
|
// import HttpError from "../interfaces/http-error";
|
|
// import { Not } from "typeorm";
|
|
|
|
// @Route("api/v1/kpi/user/achievement/planned")
|
|
// @Tags("KpiUserPlanned")
|
|
// @Security("bearerAuth")
|
|
// @Response(
|
|
// HttpStatusCode.INTERNAL_SERVER_ERROR,
|
|
// "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
|
|
// )
|
|
// @SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
|
// export class KpiUserPlannedController extends Controller {
|
|
// private posTypeRepository = AppDataSource.getRepository(KpiUserPlanned);
|
|
// private posLevelRepository = AppDataSource.getRepository(PosLevel);
|
|
|
|
// /**
|
|
// * API เพิ่มประเภทตำแหน่ง
|
|
// *
|
|
// * @summary ORG_045 - เพิ่มประเภทตำแหน่ง (ADMIN) #48
|
|
// *
|
|
// */
|
|
// @Post()
|
|
// @Example({
|
|
// positionName: "นักบริหาร",
|
|
// posTypeRank: 1,
|
|
// })
|
|
// async createType(
|
|
// @Body()
|
|
// requestBody: CreateKpiUserPlanned,
|
|
// @Request() request: { user: Record<string, any> },
|
|
// ) {
|
|
// const posType = Object.assign(new KpiUserPlanned(), requestBody);
|
|
// if (!posType) {
|
|
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
|
// }
|
|
// const chkKpiUserPlannedName = await this.posTypeRepository.findOne({
|
|
// where: {
|
|
// posTypeName: requestBody.posTypeName,
|
|
// },
|
|
// });
|
|
// if (chkKpiUserPlannedName) {
|
|
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อประเภทตำแหน่งนี้มีอยู่ในระบบแล้ว");
|
|
// }
|
|
// posType.createdUserId = request.user.sub;
|
|
// posType.createdFullName = request.user.name;
|
|
// posType.lastUpdateUserId = request.user.sub;
|
|
// posType.lastUpdateFullName = request.user.name;
|
|
// await this.posTypeRepository.save(posType);
|
|
// return new HttpSuccess(posType);
|
|
// }
|
|
|
|
// /**
|
|
// * API แก้ไขประเภทตำแหน่ง
|
|
// *
|
|
// * @summary ORG_046 - แก้ไขประเภทตำแหน่ง (ADMIN) #49
|
|
// *
|
|
// * @param {string} id Id ประเภทตำแหน่ง
|
|
// */
|
|
// @Put("{id}")
|
|
// @Example({
|
|
// positionName: "นักบริหาร",
|
|
// posTypeRank: 1,
|
|
// })
|
|
// async editType(
|
|
// @Path() id: string,
|
|
// @Body() requestBody: UpdateKpiUserPlanned,
|
|
// @Request() request: { user: Record<string, any> },
|
|
// ) {
|
|
// const posType = await this.posTypeRepository.findOne({ where: { id } });
|
|
// if (!posType) {
|
|
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้");
|
|
// }
|
|
// const chkKpiUserPlannedName = await this.posTypeRepository.findOne({
|
|
// where: {
|
|
// id: Not(id),
|
|
// posTypeName: requestBody.posTypeName,
|
|
// },
|
|
// });
|
|
// if (chkKpiUserPlannedName) {
|
|
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อประเภทตำแหน่งนี้มีอยู่ในระบบแล้ว");
|
|
// }
|
|
// posType.lastUpdateUserId = request.user.sub;
|
|
// posType.lastUpdateFullName = request.user.name;
|
|
// this.posTypeRepository.merge(posType, requestBody);
|
|
// await this.posTypeRepository.save(posType);
|
|
// return new HttpSuccess(posType.id);
|
|
// }
|
|
|
|
// /**
|
|
// * API ลบประเภทตำแหน่ง
|
|
// *
|
|
// * @summary ORG_047 - ลบประเภทตำแหน่ง (ADMIN) #50
|
|
// *
|
|
// * @param {string} id Id ตำแหน่ง
|
|
// */
|
|
// @Delete("{id}")
|
|
// async deleteType(@Path() id: string) {
|
|
// const delKpiUserPlanned = await this.posTypeRepository.findOne({ where: { id } });
|
|
// if (!delKpiUserPlanned) {
|
|
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้");
|
|
// }
|
|
// const IdExitsInLevel = await this.posLevelRepository.find({
|
|
// where: { posTypeId: id },
|
|
// });
|
|
// if (IdExitsInLevel.length > 0) {
|
|
// throw new HttpError(
|
|
// HttpStatusCode.NOT_FOUND,
|
|
// "ไม่สามารถลบได้เนื่องจากพบข้อมูลที่ตารางระดับตำแหน่ง",
|
|
// );
|
|
// }
|
|
|
|
// await this.posTypeRepository.remove(delKpiUserPlanned);
|
|
// return new HttpSuccess();
|
|
// }
|
|
|
|
// /**
|
|
// * API รายละเอียดประเภทตำแหน่ง
|
|
// *
|
|
// * @summary ORG_048 - รายละเอียดประเภทตำแหน่ง (ADMIN) #51
|
|
// *
|
|
// * @param {string} id Id ประเภทตำแหน่ง
|
|
// */
|
|
// @Get("{id}")
|
|
// @Example([
|
|
// {
|
|
// id: "00000000-0000-0000-0000-000000000000",
|
|
// posTypeName: "นักบริหาร",
|
|
// posLevelposTypeRanks: 1,
|
|
// posLevels: [
|
|
// {
|
|
// id: "00000000-0000-0000-0000-000000000000",
|
|
// posLevelName: "นักบริหาร",
|
|
// posLevelRank: 1,
|
|
// posLevelAuthority: "HEAD",
|
|
// },
|
|
// ],
|
|
// },
|
|
// ])
|
|
// async GetTypeDetail(@Path() id: string) {
|
|
// const getKpiUserPlanned = await this.posTypeRepository.findOne({
|
|
// select: ["id", "posTypeName", "posTypeRank"],
|
|
// relations: ["posLevels"],
|
|
// where: { id: id },
|
|
// });
|
|
// if (!getKpiUserPlanned) {
|
|
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้");
|
|
// }
|
|
|
|
// const mapGetKpiUserPlanned = {
|
|
// id: getKpiUserPlanned.id,
|
|
// posTypeName: getKpiUserPlanned.posTypeName,
|
|
// posTypeRank: getKpiUserPlanned.posTypeRank,
|
|
// posLevels: getKpiUserPlanned.posLevels
|
|
// .sort((a, b) => a.posLevelRank - b.posLevelRank)
|
|
// .map((posLevel) => ({
|
|
// id: posLevel.id,
|
|
// posLevelName: posLevel.posLevelName,
|
|
// posLevelRank: posLevel.posLevelRank,
|
|
// posLevelAuthority: posLevel.posLevelAuthority,
|
|
// })),
|
|
// };
|
|
|
|
// return new HttpSuccess(mapGetKpiUserPlanned);
|
|
// }
|
|
|
|
// /**
|
|
// * API รายการประเภทตำแหน่ง
|
|
// *
|
|
// * @summary ORG_027 - รายการประเภทตำแหน่ง (ADMIN) #29
|
|
// *
|
|
// */
|
|
// @Get()
|
|
// @Example([
|
|
// {
|
|
// id: "00000000-0000-0000-0000-000000000000",
|
|
// posTypeName: "นักบริหาร",
|
|
// posTypeRank: 1,
|
|
// posLevels: [
|
|
// {
|
|
// id: "00000000-0000-0000-0000-000000000000",
|
|
// posLevelName: "นักบริหาร",
|
|
// posLevelRank: 1,
|
|
// posLevelAuthority: "HEAD",
|
|
// },
|
|
// ],
|
|
// },
|
|
// ])
|
|
// async GetKpiUserPlanned() {
|
|
// const posType = await this.posTypeRepository.find({
|
|
// select: ["id", "posTypeName", "posTypeRank"],
|
|
// relations: ["posLevels"],
|
|
// order: { posTypeRank: "ASC" },
|
|
// });
|
|
// // if (!posType) {
|
|
// // return new HttpSuccess([]);
|
|
// // }
|
|
// const mapKpiUserPlanned = posType.map((item) => ({
|
|
// id: item.id,
|
|
// posTypeName: item.posTypeName,
|
|
// posTypeRank: item.posTypeRank,
|
|
// posLevels: item.posLevels
|
|
// .sort((a, b) => a.posLevelRank - b.posLevelRank)
|
|
// .map((posLevel) => ({
|
|
// id: posLevel.id,
|
|
// posLevelName: posLevel.posLevelName,
|
|
// posLevelRank: posLevel.posLevelRank,
|
|
// posLevelAuthority: posLevel.posLevelAuthority,
|
|
// })),
|
|
// }));
|
|
// return new HttpSuccess(mapKpiUserPlanned);
|
|
// }
|
|
// }
|