checkpoint crud Achievement

This commit is contained in:
AdisakKanthawilang 2024-04-22 18:13:30 +07:00
parent 245e7f9df5
commit f16fff075f
4 changed files with 425 additions and 225 deletions

View file

@ -1,234 +1,183 @@
// import { import {
// Controller, Controller,
// Get, Get,
// Post, Post,
// Put, Put,
// Delete, Delete,
// Patch, Patch,
// Route, Route,
// Security, Security,
// Tags, Tags,
// Body, Body,
// Path, Path,
// Request, Request,
// Example, Example,
// SuccessResponse, SuccessResponse,
// Response, Response,
// Query, Query,
// } from "tsoa"; } from "tsoa";
// import { AppDataSource } from "../database/data-source"; import { AppDataSource } from "../database/data-source";
// import HttpSuccess from "../interfaces/http-success"; import HttpSuccess from "../interfaces/http-success";
// import HttpStatusCode from "../interfaces/http-status"; import HttpStatusCode from "../interfaces/http-status";
// import { KpiUserPlanned, CreateKpiUserPlanned, UpdateKpiUserPlanned } from "../entities/KpiUserPlanned"; import { KpiUserPlanned, CreateKpiUserPlanned, UpdateKpiUserPlanned } from "../entities/kpiUserPlanned";
// import HttpError from "../interfaces/http-error"; import HttpError from "../interfaces/http-error";
// import { Not } from "typeorm"; import { Not } from "typeorm";
import { KpiUserEvaluation } from "../entities/kpiUserEvaluation";
import { KpiPlan } from "../entities/kpiPlan";
// @Route("api/v1/kpi/user/achievement/planned") @Route("api/v1/kpi/user/achievement/planned")
// @Tags("KpiUserPlanned") @Tags("KpiUserPlanned")
// @Security("bearerAuth") @Security("bearerAuth")
// @Response( @Response(
// HttpStatusCode.INTERNAL_SERVER_ERROR, HttpStatusCode.INTERNAL_SERVER_ERROR,
// "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง", "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
// ) )
// @SuccessResponse(HttpStatusCode.OK, "สำเร็จ") @SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
// export class KpiUserPlannedController extends Controller { export class KpiUserPlannedController extends Controller {
// private posTypeRepository = AppDataSource.getRepository(KpiUserPlanned); private kpiUserPlannedRepository = AppDataSource.getRepository(KpiUserPlanned);
// private posLevelRepository = AppDataSource.getRepository(PosLevel); private kpiUserEvaluationRepository = AppDataSource.getRepository(KpiUserEvaluation);
private kpiPlanRepository = AppDataSource.getRepository(KpiPlan);
// /** /**
// * API เพิ่มประเภทตำแหน่ง * API
// * *
// * @summary ORG_045 - เพิ่มประเภทตำแหน่ง (ADMIN) #48 * @summary - #48
// * *
// */ */
// @Post() @Post()
// @Example({ async createKpiUserPlanned(
// positionName: "นักบริหาร", @Body()
// posTypeRank: 1, requestBody: CreateKpiUserPlanned,
// }) @Request() request: { user: Record<string, any> },
// async createType( ) {
// @Body() const chkUserEvaluation = await this.kpiUserEvaluationRepository.findOne({
// requestBody: CreateKpiUserPlanned, where:{id:requestBody.kpiUserEvaluationId},
// @Request() request: { user: Record<string, any> }, })
// ) { if (!chkUserEvaluation) {
// const posType = Object.assign(new KpiUserPlanned(), requestBody); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบประเมินผู้ใช้งาน");
// 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);
// }
// /** const chkKpiPlan = await this.kpiPlanRepository.findOne({
// * API แก้ไขประเภทตำแหน่ง where:{id:requestBody.kpiPlanId},
// * })
// * @summary ORG_046 - แก้ไขประเภทตำแหน่ง (ADMIN) #49 if (!chkKpiPlan) {
// * throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบประเมินตามแผน");
// * @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);
// }
// /** const kpiUserPlanned = Object.assign(new KpiUserPlanned(), requestBody);
// * API ลบประเภทตำแหน่ง if (!kpiUserPlanned) {
// * throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
// * @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); kpiUserPlanned.createdUserId = request.user.sub;
// return new HttpSuccess(); kpiUserPlanned.createdFullName = request.user.name;
// } kpiUserPlanned.lastUpdateUserId = request.user.sub;
kpiUserPlanned.lastUpdateFullName = request.user.name;
await this.kpiUserPlannedRepository.save(kpiUserPlanned);
return new HttpSuccess(kpiUserPlanned.id);
}
// /** /**
// * API รายละเอียดประเภทตำแหน่ง * API
// * *
// * @summary ORG_048 - รายละเอียดประเภทตำแหน่ง (ADMIN) #51 * @summary - #49
// * *
// * @param {string} id Id ประเภทตำแหน่ง * @param {string} id Id
// */ */
// @Get("{id}") @Put("{id}")
// @Example([ async editKpiUserPlanned(
// { @Path() id: string,
// id: "00000000-0000-0000-0000-000000000000", @Body() requestBody: UpdateKpiUserPlanned,
// posTypeName: "นักบริหาร", @Request() request: { user: Record<string, any> },
// posLevelposTypeRanks: 1, ) {
// posLevels: [ const kpiUserPlanned = await this.kpiUserPlannedRepository.findOne({ where: { id } });
// { if (!kpiUserPlanned) {
// id: "00000000-0000-0000-0000-000000000000", throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลงานตามแผนปฏิบัติราชการประจำปีนี้");
// 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 = { kpiUserPlanned.lastUpdateUserId = request.user.sub;
// id: getKpiUserPlanned.id, kpiUserPlanned.lastUpdateFullName = request.user.name;
// posTypeName: getKpiUserPlanned.posTypeName, this.kpiUserPlannedRepository.merge(kpiUserPlanned, requestBody);
// posTypeRank: getKpiUserPlanned.posTypeRank, await this.kpiUserPlannedRepository.save(kpiUserPlanned);
// posLevels: getKpiUserPlanned.posLevels return new HttpSuccess(kpiUserPlanned.id);
// .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 - #50
*
* @param {string} id Id
*/
@Delete("{id}")
async deleteKpiUserPlanned(@Path() id: string) {
const delKpiUserPlanned = await this.kpiUserPlannedRepository.findOne({ where: { id } });
if (!delKpiUserPlanned) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลงานตามแผนปฏิบัติราชการประจำปีนี้");
}
await this.kpiUserPlannedRepository.remove(delKpiUserPlanned);
return new HttpSuccess();
}
// /** // /**
// * API รายการประเภทตำแหน่ง // * API รายละเอียดงานตามแผนปฏิบัติราชการประจำปี
// * // *
// * @summary ORG_027 - รายการประเภทตำแหน่ง (ADMIN) #29 // * @summary - รายละเอียดงานตามแผนปฏิบัติราชการประจำปี #51
// * // *
// */ // * @param {string} id Id งานตามแผนปฏิบัติราชการประจำปี
// @Get() // */
// @Example([ // @Get("{id}")
// { // async GetKpiUserPlannedDetail(@Path() id: string) {
// id: "00000000-0000-0000-0000-000000000000", // const getKpiUserPlanned = await this.kpiUserPlannedRepository.findOne({
// posTypeName: "นักบริหาร", // select: ["id", "kpiUserPlannedName", "kpiUserPlannedRank"],
// posTypeRank: 1, // relations: ["posLevels"],
// posLevels: [ // where: { id: id },
// { // });
// id: "00000000-0000-0000-0000-000000000000", // if (!getKpiUserPlanned) {
// posLevelName: "นักบริหาร", // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลงานตามแผนปฏิบัติราชการประจำปีนี้");
// posLevelRank: 1, // }
// posLevelAuthority: "HEAD",
// }, // const mapGetKpiUserPlanned = {
// ], // id: getKpiUserPlanned.id,
// }, // kpiUserPlannedName: getKpiUserPlanned.kpiUserPlannedName,
// ]) // kpiUserPlannedRank: getKpiUserPlanned.kpiUserPlannedRank,
// async GetKpiUserPlanned() { // posLevels: getKpiUserPlanned.posLevels
// const posType = await this.posTypeRepository.find({ // .sort((a, b) => a.posLevelRank - b.posLevelRank)
// select: ["id", "posTypeName", "posTypeRank"], // .map((posLevel) => ({
// relations: ["posLevels"], // id: posLevel.id,
// order: { posTypeRank: "ASC" }, // posLevelName: posLevel.posLevelName,
// }); // posLevelRank: posLevel.posLevelRank,
// // if (!posType) { // posLevelAuthority: posLevel.posLevelAuthority,
// // return new HttpSuccess([]); // })),
// // } // };
// const mapKpiUserPlanned = posType.map((item) => ({
// id: item.id, // return new HttpSuccess(mapGetKpiUserPlanned);
// posTypeName: item.posTypeName, // }
// posTypeRank: item.posTypeRank,
// posLevels: item.posLevels /**
// .sort((a, b) => a.posLevelRank - b.posLevelRank) * API
// .map((posLevel) => ({ *
// id: posLevel.id, * @summary - #29
// posLevelName: posLevel.posLevelName, *
// posLevelRank: posLevel.posLevelRank, */
// posLevelAuthority: posLevel.posLevelAuthority, @Get()
// })), async GetKpiUserPlanned() {
// })); const kpiUserPlanned = await this.kpiUserPlannedRepository.find({
// return new HttpSuccess(mapKpiUserPlanned); relations: ["kpiPlan","kpiUserEvaluation"],
// } order: { createdAt: "ASC" },
// } });
// if (!kpiUserPlanned) {
// return new HttpSuccess([]);
// }
const mapKpiUserPlanned = kpiUserPlanned.map((item) => ({
id: item.id,
indicatorId: item.kpiPlan.id,
target: item.target,
unit: item.unit,
weight: item.weight,
meaning: item.meaning,
formula: item.formula,
}));
return new HttpSuccess(mapKpiUserPlanned);
}
}

View file

@ -0,0 +1,183 @@
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 { KpiUserRole, CreateKpiUserRole, UpdateKpiUserRole } from "../entities/kpiUserRole";
import HttpError from "../interfaces/http-error";
import { Not } from "typeorm";
import { KpiUserEvaluation } from "../entities/kpiUserEvaluation";
import { KpiRole } from "../entities/kpiRole";
@Route("api/v1/kpi/user/achievement/role")
@Tags("KpiUserRole")
@Security("bearerAuth")
@Response(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
)
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
export class KpiUserRoleController extends Controller {
private kpiUserRoleRepository = AppDataSource.getRepository(KpiUserRole);
private kpiUserEvaluationRepository = AppDataSource.getRepository(KpiUserEvaluation);
private kpiRoleRepository = AppDataSource.getRepository(KpiRole);
/**
* API
*
* @summary - #48
*
*/
@Post()
async createKpiUserRole(
@Body()
requestBody: CreateKpiUserRole,
@Request() request: { user: Record<string, any> },
) {
const chkUserEvaluation = await this.kpiUserEvaluationRepository.findOne({
where:{id:requestBody.kpiUserEvaluationId},
})
if (!chkUserEvaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบประเมินผู้ใช้งาน");
}
const chkKpiRole = await this.kpiRoleRepository.findOne({
where:{id:requestBody.kpiRoleId},
})
if (!chkKpiRole) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบประเมินตามหน้าที่ความรับผิดชอบหลัก");
}
const kpiUserRole = Object.assign(new KpiUserRole(), requestBody);
if (!kpiUserRole) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
kpiUserRole.createdUserId = request.user.sub;
kpiUserRole.createdFullName = request.user.name;
kpiUserRole.lastUpdateUserId = request.user.sub;
kpiUserRole.lastUpdateFullName = request.user.name;
await this.kpiUserRoleRepository.save(kpiUserRole);
return new HttpSuccess(kpiUserRole.id);
}
/**
* API
*
* @summary - #49
*
* @param {string} id Id
*/
@Put("{id}")
async editKpiUserRole(
@Path() id: string,
@Body() requestBody: UpdateKpiUserRole,
@Request() request: { user: Record<string, any> },
) {
const kpiUserRole = await this.kpiUserRoleRepository.findOne({ where: { id } });
if (!kpiUserRole) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลงานตามหน้าที่ความรับผิดชอบหลักนี้");
}
kpiUserRole.lastUpdateUserId = request.user.sub;
kpiUserRole.lastUpdateFullName = request.user.name;
this.kpiUserRoleRepository.merge(kpiUserRole, requestBody);
await this.kpiUserRoleRepository.save(kpiUserRole);
return new HttpSuccess(kpiUserRole.id);
}
/**
* API
*
* @summary - #50
*
* @param {string} id Id
*/
@Delete("{id}")
async deleteKpiUserRole(@Path() id: string) {
const delKpiUserRole = await this.kpiUserRoleRepository.findOne({ where: { id } });
if (!delKpiUserRole) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลงานตามหน้าที่ความรับผิดชอบหลักนี้");
}
await this.kpiUserRoleRepository.remove(delKpiUserRole);
return new HttpSuccess();
}
// /**
// * API รายละเอียดงานตามหน้าที่ความรับผิดชอบหลัก
// *
// * @summary - รายละเอียดงานตามหน้าที่ความรับผิดชอบหลัก #51
// *
// * @param {string} id Id งานตามหน้าที่ความรับผิดชอบหลัก
// */
// @Get("{id}")
// async GetKpiUserRoleDetail(@Path() id: string) {
// const getKpiUserRole = await this.kpiUserRoleRepository.findOne({
// select: ["id", "kpiUserRoleName", "kpiUserRoleRank"],
// relations: ["posLevels"],
// where: { id: id },
// });
// if (!getKpiUserRole) {
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลงานตามหน้าที่ความรับผิดชอบหลักนี้");
// }
// const mapGetKpiUserRole = {
// id: getKpiUserRole.id,
// kpiUserRoleName: getKpiUserRole.kpiUserRoleName,
// kpiUserRoleRank: getKpiUserRole.kpiUserRoleRank,
// posLevels: getKpiUserRole.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(mapGetKpiUserRole);
// }
/**
* API
*
* @summary - #29
*
*/
@Get()
async GetKpiUserRole() {
const kpiUserRole = await this.kpiUserRoleRepository.find({
relations: ["kpiRole","kpiUserEvaluation"],
order: { createdAt: "ASC" },
});
// if (!kpiUserRole) {
// return new HttpSuccess([]);
// }
const mapKpiUserRole = kpiUserRole.map((item) => ({
id: item.id,
indicatorId: item.kpiRole.id,
target: item.target,
unit: item.unit,
weight: item.weight,
meaning: item.meaning,
formula: item.formula,
}));
return new HttpSuccess(mapKpiUserRole);
}
}

View file

@ -64,3 +64,37 @@ export class KpiUserPlanned extends EntityBase {
@JoinColumn({ name: "kpiPlanId" }) @JoinColumn({ name: "kpiPlanId" })
kpiPlan: KpiPlan; kpiPlan: KpiPlan;
} }
export class CreateKpiUserPlanned {
@Column()
target: string;
@Column()
unit: number;
@Column()
weight: number;
@Column()
meaning: string;
@Column()
formula: string;
@Column("uuid")
kpiUserEvaluationId: string;
@Column("uuid")
kpiPlanId: string;
}
export class UpdateKpiUserPlanned {
@Column()
target: string;
@Column()
unit: number;
@Column()
weight: number;
@Column()
meaning: string;
@Column()
formula: string;
// @Column("uuid")
// kpiUserEvaluationId: string;
// @Column("uuid")
// kpiPlanId: string;
}

View file

@ -64,3 +64,37 @@ export class KpiUserRole extends EntityBase {
@JoinColumn({ name: "kpiRoleId" }) @JoinColumn({ name: "kpiRoleId" })
kpiRole: KpiRole; kpiRole: KpiRole;
} }
export class CreateKpiUserRole {
@Column()
target: string;
@Column()
unit: number;
@Column()
weight: number;
@Column()
meaning: string;
@Column()
formula: string;
@Column("uuid")
kpiUserEvaluationId: string;
@Column("uuid")
kpiRoleId: string;
}
export class UpdateKpiUserRole {
@Column()
target: string;
@Column()
unit: number;
@Column()
weight: number;
@Column()
meaning: string;
@Column()
formula: string;
// @Column("uuid")
// kpiUserEvaluationId: string;
// @Column("uuid")
// kpiPlanId: string;
}