diff --git a/src/controllers/KpiReasonController.ts b/src/controllers/KpiReasonController.ts new file mode 100644 index 0000000..0c34e40 --- /dev/null +++ b/src/controllers/KpiReasonController.ts @@ -0,0 +1,877 @@ +import { + Controller, + Get, + Put, + Route, + Security, + Tags, + Body, + Path, + Request, + SuccessResponse, + Response, +} 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 { In } from "typeorm"; +import { KpiUserEvaluationReasonPlan } from "../entities/kpiUserEvaluationReasonPlan"; +import { KpiUserEvaluationReasonRole } from "../entities/kpiUserEvaluationReasonRole"; +import { KpiUserEvaluationReasonSpecial } from "../entities/kpiUserEvaluationReasonSpecial"; +import { + KpiUserEvaluationReasonCapacity, + updateKpiUserReasonEvaluation, +} from "../entities/kpiUserEvaluationReasonCapacity"; +import { KpiUserEvaluationReasonDevelopment } from "../entities/kpiUserEvaluationReasonDevelopment"; +import { KpiUserEvaluation } from "../entities/kpiUserEvaluation"; +import { KpiUserRole } from "../entities/kpiUserRole"; +import { KpiUserSpecial } from "../entities/kpiUserSpecial"; +import { KpiUserCapacity } from "../entities/kpiUserCapacity"; +import { KpiUserDevelopment } from "../entities/kpiUserDevelopment"; +import { KpiUserPlanned } from "../entities/kpiUserPlanned"; + +@Route("api/v1/kpi/reason") +@Tags("kpiReason") +@Security("bearerAuth") +@Response( + HttpStatusCode.INTERNAL_SERVER_ERROR, + "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง", +) +@SuccessResponse(HttpStatusCode.OK, "สำเร็จ") +export class kpiReasonController extends Controller { + private kpiUserEvaluationReasonPlan = AppDataSource.getRepository(KpiUserEvaluationReasonPlan); + private kpiUserEvaluationReasonRole = AppDataSource.getRepository(KpiUserEvaluationReasonRole); + private kpiUserEvaluationReasonSpecial = AppDataSource.getRepository( + KpiUserEvaluationReasonSpecial, + ); + private kpiUserEvaluationReasonCapacity = AppDataSource.getRepository( + KpiUserEvaluationReasonCapacity, + ); + private kpiUserEvaluationReasonDevelopment = AppDataSource.getRepository( + KpiUserEvaluationReasonDevelopment, + ); + private kpiUserPlan = AppDataSource.getRepository(KpiUserPlanned); + private kpiUserRole = AppDataSource.getRepository(KpiUserRole); + private kpiUserSpecial = AppDataSource.getRepository(KpiUserSpecial); + private kpiUserCapacity = AppDataSource.getRepository(KpiUserCapacity); + private kpiUserDevelopment = AppDataSource.getRepository(KpiUserDevelopment); + + /** + * API แก้ไขหมายเหตุ (USER) + * + * @summary แก้ไขหมายเหตุ (USER) + * + * @param {string} id Guid, *Id คนประเมิน (USER) + */ + @Put("{type}/plan/{user}/{id}") + async updateKpiPlanReason( + @Path() type: string, + @Path() user: string, + @Path() id: string, + @Body() requestBody: updateKpiUserReasonEvaluation, + @Request() request: { user: Record }, + ) { + if (user.trim().toUpperCase() == "USER") { + const kpiUserEvaluation = await this.kpiUserPlan.findOne({ + where: { id: id }, + relations: ["kpiUserEvaluation", "kpiUserEvaluation.evaluatorId"], + }); + if (!kpiUserEvaluation) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้", + ); + } + const kpiUserEvaluationReason = Object.assign(new KpiUserEvaluationReasonPlan(), requestBody); + kpiUserEvaluationReason.type = type.trim().toUpperCase(); + if (type.trim().toUpperCase() == "PROBLEM") { + kpiUserEvaluationReason.status = + kpiUserEvaluation.kpiUserEvaluation.evaluatorId == null ? "DONE" : "DAFT"; + } else { + kpiUserEvaluationReason.status = + kpiUserEvaluation.kpiUserEvaluation.evaluatorId == null ? "DONE" : "EVALUATOR"; + } + kpiUserEvaluationReason.kpiUserPlannedId = id; + kpiUserEvaluationReason.createdUserId = request.user.sub; + kpiUserEvaluationReason.createdFullName = request.user.name; + kpiUserEvaluationReason.lastUpdateUserId = request.user.sub; + kpiUserEvaluationReason.lastUpdateFullName = request.user.name; + await this.kpiUserEvaluationReasonPlan.save(kpiUserEvaluationReason); + return new HttpSuccess(kpiUserEvaluationReason.id); + } else { + const kpiReason = await this.kpiUserEvaluationReasonPlan.findOne({ + where: { id: id }, + relations: [ + "kpiUserPlanned", + "kpiUserPlanned.kpiUserEvaluation", + "kpiUserPlanned.kpiUserEvaluation.evaluatorId", + ], + }); + if (!kpiReason) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้", + ); + } + + if (user.trim().toUpperCase() == "EVALUATOR") { + kpiReason.reasonEvaluator = requestBody.reason; + kpiReason.status = + kpiReason.kpiUserPlanned.kpiUserEvaluation.commanderId == null ? "DONE" : "COMMANDER"; + } else if (user.trim().toUpperCase() == "COMMANDER") { + kpiReason.reasonCommander = requestBody.reason; + kpiReason.status = + kpiReason.kpiUserPlanned.kpiUserEvaluation.commanderHighId == null + ? "DONE" + : "COMMANDERHIGH"; + } else if (user.trim().toUpperCase() == "COMMANDERHIGH") { + kpiReason.reasonCommanderHigh = requestBody.reason; + kpiReason.status = "DONE"; + } + kpiReason.reasonCommanderHigh = requestBody.reason; + kpiReason.lastUpdateUserId = request.user.sub; + kpiReason.lastUpdateFullName = request.user.name; + await this.kpiUserEvaluationReasonPlan.save(kpiReason); + return new HttpSuccess(kpiReason.id); + } + } + + /** + * API แก้ไขหมายเหตุ (USER) + * + * @summary แก้ไขหมายเหตุ (USER) + * + * @param {string} id Guid, *Id คนประเมิน (USER) + */ + @Put("problem/plansend/user/{id}") + async sendKpiPlanReason( + @Path() id: string, + @Body() requestBody: updateKpiUserReasonEvaluation, + @Request() request: { user: Record }, + ) { + const kpiReason = await this.kpiUserEvaluationReasonPlan.findOne({ + where: { id: id }, + relations: [ + "kpiUserPlanned", + "kpiUserPlanned.kpiUserEvaluation", + "kpiUserPlanned.kpiUserEvaluation.evaluatorId", + ], + }); + if (!kpiReason) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้", + ); + } + + kpiReason.status = + kpiReason.kpiUserPlanned.kpiUserEvaluation.commanderId == null ? "DONE" : "COMMANDER"; + kpiReason.reasonCommanderHigh = requestBody.reason; + kpiReason.lastUpdateUserId = request.user.sub; + kpiReason.lastUpdateFullName = request.user.name; + await this.kpiUserEvaluationReasonPlan.save(kpiReason); + return new HttpSuccess(kpiReason.id); + } + + /** + * API list หมายเหตุ (USER) + * + * @summary list หมายเหตุ (USER) + * + * @param {string} id Guid, *Id คนประเมิน (USER) + */ + @Get("{type}/plan/{user}/{id}") + async listKpiUserPlanReason(@Path() id: string, @Path() type: string, @Path() user: string) { + if (type.trim().toUpperCase() == "PROGRESS") { + const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonPlan.find({ + where: { kpiUserPlannedId: id }, + }); + return new HttpSuccess(kpiUserEvaluationReason); + } else { + if (user.trim().toUpperCase() == "USER") { + const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonPlan.find({ + where: { kpiUserPlannedId: id }, + }); + return new HttpSuccess(kpiUserEvaluationReason); + } else if (user.trim().toUpperCase() == "EVALUATOR") { + const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonPlan.find({ + where: { + kpiUserPlannedId: id, + status: In(["EVALUATOR", "COMMANDER", "COMMANDERHIGH", "DONE"]), + }, + }); + return new HttpSuccess(kpiUserEvaluationReason); + } else if (user.trim().toUpperCase() == "COMMANDER") { + const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonPlan.find({ + where: { + kpiUserPlannedId: id, + status: In(["COMMANDER", "COMMANDERHIGH", "DONE"]), + }, + }); + return new HttpSuccess(kpiUserEvaluationReason); + } else if (user.trim().toUpperCase() == "COMMANDERHIGH") { + const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonPlan.find({ + where: { + kpiUserPlannedId: id, + status: In(["COMMANDERHIGH", "DONE"]), + }, + }); + return new HttpSuccess(kpiUserEvaluationReason); + } + } + } + + /** + * API แก้ไขหมายเหตุ (USER) + * + * @summary แก้ไขหมายเหตุ (USER) + * + * @param {string} id Guid, *Id คนประเมิน (USER) + */ + @Put("{type}/role/{user}/{id}") + async updateKpiRoleReason( + @Path() type: string, + @Path() user: string, + @Path() id: string, + @Body() requestBody: updateKpiUserReasonEvaluation, + @Request() request: { user: Record }, + ) { + if (user.trim().toUpperCase() == "USER") { + const kpiUserEvaluation = await this.kpiUserRole.findOne({ + where: { id: id }, + relations: ["kpiUserEvaluation", "kpiUserEvaluation.evaluatorId"], + }); + if (!kpiUserEvaluation) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้", + ); + } + const kpiUserEvaluationReason = Object.assign(new KpiUserEvaluationReasonRole(), requestBody); + kpiUserEvaluationReason.type = type.trim().toUpperCase(); + kpiUserEvaluationReason.status = + kpiUserEvaluation.kpiUserEvaluation.evaluatorId == null ? "DONE" : "EVALUATOR"; + kpiUserEvaluationReason.kpiUserRoleId = id; + kpiUserEvaluationReason.createdUserId = request.user.sub; + kpiUserEvaluationReason.createdFullName = request.user.name; + kpiUserEvaluationReason.lastUpdateUserId = request.user.sub; + kpiUserEvaluationReason.lastUpdateFullName = request.user.name; + await this.kpiUserEvaluationReasonRole.save(kpiUserEvaluationReason); + return new HttpSuccess(kpiUserEvaluationReason.id); + } else { + const kpiReason = await this.kpiUserEvaluationReasonRole.findOne({ + where: { id: id }, + relations: [ + "kpiUserRole", + "kpiUserRole.kpiUserEvaluation", + "kpiUserRole.kpiUserEvaluation.evaluatorId", + ], + }); + if (!kpiReason) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้", + ); + } + + if (user.trim().toUpperCase() == "EVALUATOR") { + kpiReason.reasonEvaluator = requestBody.reason; + kpiReason.status = + kpiReason.kpiUserRole.kpiUserEvaluation.commanderId == null ? "DONE" : "COMMANDER"; + } else if (user.trim().toUpperCase() == "COMMANDER") { + kpiReason.reasonCommander = requestBody.reason; + kpiReason.status = + kpiReason.kpiUserRole.kpiUserEvaluation.commanderHighId == null + ? "DONE" + : "COMMANDERHIGH"; + } else if (user.trim().toUpperCase() == "COMMANDERHIGH") { + kpiReason.reasonCommanderHigh = requestBody.reason; + kpiReason.status = "DONE"; + } + kpiReason.reasonCommanderHigh = requestBody.reason; + kpiReason.lastUpdateUserId = request.user.sub; + kpiReason.lastUpdateFullName = request.user.name; + await this.kpiUserEvaluationReasonRole.save(kpiReason); + return new HttpSuccess(kpiReason.id); + } + } + + /** + * API แก้ไขหมายเหตุ (USER) + * + * @summary แก้ไขหมายเหตุ (USER) + * + * @param {string} id Guid, *Id คนประเมิน (USER) + */ + @Put("problem/rolesend/user/{id}") + async sendKpiRoleReason( + @Path() id: string, + @Body() requestBody: updateKpiUserReasonEvaluation, + @Request() request: { user: Record }, + ) { + const kpiReason = await this.kpiUserEvaluationReasonRole.findOne({ + where: { id: id }, + relations: [ + "kpiUserRole", + "kpiUserRole.kpiUserEvaluation", + "kpiUserRole.kpiUserEvaluation.evaluatorId", + ], + }); + if (!kpiReason) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้", + ); + } + + kpiReason.status = + kpiReason.kpiUserRole.kpiUserEvaluation.commanderId == null ? "DONE" : "COMMANDER"; + kpiReason.reasonCommanderHigh = requestBody.reason; + kpiReason.lastUpdateUserId = request.user.sub; + kpiReason.lastUpdateFullName = request.user.name; + await this.kpiUserEvaluationReasonRole.save(kpiReason); + return new HttpSuccess(kpiReason.id); + } + + /** + * API list หมายเหตุ (USER) + * + * @summary list หมายเหตุ (USER) + * + * @param {string} id Guid, *Id คนประเมิน (USER) + */ + @Get("{type}/role/{user}/{id}") + async listKpiUserRoleReason(@Path() id: string, @Path() type: string, @Path() user: string) { + if (type.trim().toUpperCase() == "PROGRESS") { + const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonRole.find({ + where: { kpiUserRoleId: id }, + }); + return new HttpSuccess(kpiUserEvaluationReason); + } else { + if (user.trim().toUpperCase() == "USER") { + const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonRole.find({ + where: { kpiUserRoleId: id }, + }); + return new HttpSuccess(kpiUserEvaluationReason); + } else if (user.trim().toUpperCase() == "EVALUATOR") { + const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonRole.find({ + where: { + kpiUserRoleId: id, + status: In(["EVALUATOR", "COMMANDER", "COMMANDERHIGH", "DONE"]), + }, + }); + return new HttpSuccess(kpiUserEvaluationReason); + } else if (user.trim().toUpperCase() == "COMMANDER") { + const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonRole.find({ + where: { + kpiUserRoleId: id, + status: In(["COMMANDER", "COMMANDERHIGH", "DONE"]), + }, + }); + return new HttpSuccess(kpiUserEvaluationReason); + } else if (user.trim().toUpperCase() == "COMMANDERHIGH") { + const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonRole.find({ + where: { + kpiUserRoleId: id, + status: In(["COMMANDERHIGH", "DONE"]), + }, + }); + return new HttpSuccess(kpiUserEvaluationReason); + } + } + } + + /** + * API แก้ไขหมายเหตุ (USER) + * + * @summary แก้ไขหมายเหตุ (USER) + * + * @param {string} id Guid, *Id คนประเมิน (USER) + */ + @Put("{type}/special/{user}/{id}") + async updateKpiSpecialReason( + @Path() type: string, + @Path() user: string, + @Path() id: string, + @Body() requestBody: updateKpiUserReasonEvaluation, + @Request() request: { user: Record }, + ) { + if (user.trim().toUpperCase() == "USER") { + const kpiUserEvaluation = await this.kpiUserSpecial.findOne({ + where: { id: id }, + relations: ["kpiUserEvaluation", "kpiUserEvaluation.evaluatorId"], + }); + if (!kpiUserEvaluation) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้", + ); + } + const kpiUserEvaluationReason = Object.assign( + new KpiUserEvaluationReasonSpecial(), + requestBody, + ); + kpiUserEvaluationReason.type = type.trim().toUpperCase(); + kpiUserEvaluationReason.status = + kpiUserEvaluation.kpiUserEvaluation.evaluatorId == null ? "DONE" : "EVALUATOR"; + kpiUserEvaluationReason.kpiUserSpecialId = id; + kpiUserEvaluationReason.createdUserId = request.user.sub; + kpiUserEvaluationReason.createdFullName = request.user.name; + kpiUserEvaluationReason.lastUpdateUserId = request.user.sub; + kpiUserEvaluationReason.lastUpdateFullName = request.user.name; + await this.kpiUserEvaluationReasonSpecial.save(kpiUserEvaluationReason); + return new HttpSuccess(kpiUserEvaluationReason.id); + } else { + const kpiReason = await this.kpiUserEvaluationReasonSpecial.findOne({ + where: { id: id }, + relations: [ + "kpiUserSpecial", + "kpiUserSpecial.kpiUserEvaluation", + "kpiUserSpecial.kpiUserEvaluation.evaluatorId", + ], + }); + if (!kpiReason) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้", + ); + } + + if (user.trim().toUpperCase() == "EVALUATOR") { + kpiReason.reasonEvaluator = requestBody.reason; + kpiReason.status = + kpiReason.kpiUserSpecial.kpiUserEvaluation.commanderId == null ? "DONE" : "COMMANDER"; + } else if (user.trim().toUpperCase() == "COMMANDER") { + kpiReason.reasonCommander = requestBody.reason; + kpiReason.status = + kpiReason.kpiUserSpecial.kpiUserEvaluation.commanderHighId == null + ? "DONE" + : "COMMANDERHIGH"; + } else if (user.trim().toUpperCase() == "COMMANDERHIGH") { + kpiReason.reasonCommanderHigh = requestBody.reason; + kpiReason.status = "DONE"; + } + kpiReason.reasonCommanderHigh = requestBody.reason; + kpiReason.lastUpdateUserId = request.user.sub; + kpiReason.lastUpdateFullName = request.user.name; + await this.kpiUserEvaluationReasonSpecial.save(kpiReason); + return new HttpSuccess(kpiReason.id); + } + } + + /** + * API แก้ไขหมายเหตุ (USER) + * + * @summary แก้ไขหมายเหตุ (USER) + * + * @param {string} id Guid, *Id คนประเมิน (USER) + */ + @Put("problem/specialsend/user/{id}") + async sendKpiSpecialReason( + @Path() id: string, + @Body() requestBody: updateKpiUserReasonEvaluation, + @Request() request: { user: Record }, + ) { + const kpiReason = await this.kpiUserEvaluationReasonSpecial.findOne({ + where: { id: id }, + relations: [ + "kpiUserSpecial", + "kpiUserSpecial.kpiUserEvaluation", + "kpiUserSpecial.kpiUserEvaluation.evaluatorId", + ], + }); + if (!kpiReason) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้", + ); + } + + kpiReason.status = + kpiReason.kpiUserSpecial.kpiUserEvaluation.commanderId == null ? "DONE" : "COMMANDER"; + kpiReason.reasonCommanderHigh = requestBody.reason; + kpiReason.lastUpdateUserId = request.user.sub; + kpiReason.lastUpdateFullName = request.user.name; + await this.kpiUserEvaluationReasonSpecial.save(kpiReason); + return new HttpSuccess(kpiReason.id); + } + + /** + * API list หมายเหตุ (USER) + * + * @summary list หมายเหตุ (USER) + * + * @param {string} id Guid, *Id คนประเมิน (USER) + */ + @Get("{type}/special/{user}/{id}") + async listKpiUserSpecialReason(@Path() id: string, @Path() type: string, @Path() user: string) { + if (type.trim().toUpperCase() == "PROGRESS") { + const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonSpecial.find({ + where: { kpiUserSpecialId: id }, + }); + return new HttpSuccess(kpiUserEvaluationReason); + } else { + if (user.trim().toUpperCase() == "USER") { + const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonSpecial.find({ + where: { kpiUserSpecialId: id }, + }); + return new HttpSuccess(kpiUserEvaluationReason); + } else if (user.trim().toUpperCase() == "EVALUATOR") { + const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonSpecial.find({ + where: { + kpiUserSpecialId: id, + status: In(["EVALUATOR", "COMMANDER", "COMMANDERHIGH", "DONE"]), + }, + }); + return new HttpSuccess(kpiUserEvaluationReason); + } else if (user.trim().toUpperCase() == "COMMANDER") { + const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonSpecial.find({ + where: { + kpiUserSpecialId: id, + status: In(["COMMANDER", "COMMANDERHIGH", "DONE"]), + }, + }); + return new HttpSuccess(kpiUserEvaluationReason); + } else if (user.trim().toUpperCase() == "COMMANDERHIGH") { + const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonSpecial.find({ + where: { + kpiUserSpecialId: id, + status: In(["COMMANDERHIGH", "DONE"]), + }, + }); + return new HttpSuccess(kpiUserEvaluationReason); + } + } + } + + /** + * API แก้ไขหมายเหตุ (USER) + * + * @summary แก้ไขหมายเหตุ (USER) + * + * @param {string} id Guid, *Id คนประเมิน (USER) + */ + @Put("{type}/development/{user}/{id}") + async updateKpiDevelopmentReason( + @Path() type: string, + @Path() user: string, + @Path() id: string, + @Body() requestBody: updateKpiUserReasonEvaluation, + @Request() request: { user: Record }, + ) { + if (user.trim().toUpperCase() == "USER") { + const kpiUserEvaluation = await this.kpiUserDevelopment.findOne({ + where: { id: id }, + relations: ["kpiUserEvaluation", "kpiUserEvaluation.evaluatorId"], + }); + if (!kpiUserEvaluation) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้", + ); + } + const kpiUserEvaluationReason = Object.assign( + new KpiUserEvaluationReasonDevelopment(), + requestBody, + ); + kpiUserEvaluationReason.type = type.trim().toUpperCase(); + kpiUserEvaluationReason.status = + kpiUserEvaluation.kpiUserEvaluation.evaluatorId == null ? "DONE" : "EVALUATOR"; + kpiUserEvaluationReason.kpiUserDevelopmentId = id; + kpiUserEvaluationReason.createdUserId = request.user.sub; + kpiUserEvaluationReason.createdFullName = request.user.name; + kpiUserEvaluationReason.lastUpdateUserId = request.user.sub; + kpiUserEvaluationReason.lastUpdateFullName = request.user.name; + await this.kpiUserEvaluationReasonDevelopment.save(kpiUserEvaluationReason); + return new HttpSuccess(kpiUserEvaluationReason.id); + } else { + const kpiReason = await this.kpiUserEvaluationReasonDevelopment.findOne({ + where: { id: id }, + relations: [ + "kpiUserDevelopment", + "kpiUserDevelopment.kpiUserEvaluation", + "kpiUserDevelopment.kpiUserEvaluation.evaluatorId", + ], + }); + if (!kpiReason) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้", + ); + } + + if (user.trim().toUpperCase() == "EVALUATOR") { + kpiReason.reasonEvaluator = requestBody.reason; + kpiReason.status = + kpiReason.kpiUserDevelopment.kpiUserEvaluation.commanderId == null ? "DONE" : "COMMANDER"; + } else if (user.trim().toUpperCase() == "COMMANDER") { + kpiReason.reasonCommander = requestBody.reason; + kpiReason.status = + kpiReason.kpiUserDevelopment.kpiUserEvaluation.commanderHighId == null + ? "DONE" + : "COMMANDERHIGH"; + } else if (user.trim().toUpperCase() == "COMMANDERHIGH") { + kpiReason.reasonCommanderHigh = requestBody.reason; + kpiReason.status = "DONE"; + } + kpiReason.reasonCommanderHigh = requestBody.reason; + kpiReason.lastUpdateUserId = request.user.sub; + kpiReason.lastUpdateFullName = request.user.name; + await this.kpiUserEvaluationReasonDevelopment.save(kpiReason); + return new HttpSuccess(kpiReason.id); + } + } + + /** + * API แก้ไขหมายเหตุ (USER) + * + * @summary แก้ไขหมายเหตุ (USER) + * + * @param {string} id Guid, *Id คนประเมิน (USER) + */ + @Put("problem/development/user/{id}") + async sendKpiDevelopmentReason( + @Path() id: string, + @Body() requestBody: updateKpiUserReasonEvaluation, + @Request() request: { user: Record }, + ) { + const kpiReason = await this.kpiUserEvaluationReasonDevelopment.findOne({ + where: { id: id }, + relations: [ + "kpiUserDevelopment", + "kpiUserDevelopment.kpiUserEvaluation", + "kpiUserDevelopment.kpiUserEvaluation.evaluatorId", + ], + }); + if (!kpiReason) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้", + ); + } + + kpiReason.status = + kpiReason.kpiUserDevelopment.kpiUserEvaluation.commanderId == null ? "DONE" : "COMMANDER"; + kpiReason.reasonCommanderHigh = requestBody.reason; + kpiReason.lastUpdateUserId = request.user.sub; + kpiReason.lastUpdateFullName = request.user.name; + await this.kpiUserEvaluationReasonDevelopment.save(kpiReason); + return new HttpSuccess(kpiReason.id); + } + + /** + * API list หมายเหตุ (USER) + * + * @summary list หมายเหตุ (USER) + * + * @param {string} id Guid, *Id คนประเมิน (USER) + */ + @Get("{type}/development/{user}/{id}") + async listKpiUserDevelopmentReason( + @Path() id: string, + @Path() type: string, + @Path() user: string, + ) { + if (type.trim().toUpperCase() == "PROGRESS") { + const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonDevelopment.find({ + where: { kpiUserDevelopmentId: id }, + }); + return new HttpSuccess(kpiUserEvaluationReason); + } else { + if (user.trim().toUpperCase() == "USER") { + const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonDevelopment.find({ + where: { kpiUserDevelopmentId: id }, + }); + return new HttpSuccess(kpiUserEvaluationReason); + } else if (user.trim().toUpperCase() == "EVALUATOR") { + const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonDevelopment.find({ + where: { + kpiUserDevelopmentId: id, + status: In(["EVALUATOR", "COMMANDER", "COMMANDERHIGH", "DONE"]), + }, + }); + return new HttpSuccess(kpiUserEvaluationReason); + } else if (user.trim().toUpperCase() == "COMMANDER") { + const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonDevelopment.find({ + where: { + kpiUserDevelopmentId: id, + status: In(["COMMANDER", "COMMANDERHIGH", "DONE"]), + }, + }); + return new HttpSuccess(kpiUserEvaluationReason); + } else if (user.trim().toUpperCase() == "COMMANDERHIGH") { + const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonDevelopment.find({ + where: { + kpiUserDevelopmentId: id, + status: In(["COMMANDERHIGH", "DONE"]), + }, + }); + return new HttpSuccess(kpiUserEvaluationReason); + } + } + } + + /** + * API แก้ไขหมายเหตุ (USER) + * + * @summary แก้ไขหมายเหตุ (USER) + * + * @param {string} id Guid, *Id คนประเมิน (USER) + */ + @Put("{type}/capacity/{user}/{id}") + async updateKpiCapacityReason( + @Path() type: string, + @Path() user: string, + @Path() id: string, + @Body() requestBody: updateKpiUserReasonEvaluation, + @Request() request: { user: Record }, + ) { + if (user.trim().toUpperCase() == "USER") { + const kpiUserEvaluation = await this.kpiUserCapacity.findOne({ + where: { id: id }, + relations: ["kpiUserEvaluation", "kpiUserEvaluation.evaluatorId"], + }); + if (!kpiUserEvaluation) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้", + ); + } + const kpiUserEvaluationReason = Object.assign( + new KpiUserEvaluationReasonCapacity(), + requestBody, + ); + kpiUserEvaluationReason.type = type.trim().toUpperCase(); + kpiUserEvaluationReason.status = + kpiUserEvaluation.kpiUserEvaluation.evaluatorId == null ? "DONE" : "EVALUATOR"; + kpiUserEvaluationReason.kpiUserCapacityId = id; + kpiUserEvaluationReason.createdUserId = request.user.sub; + kpiUserEvaluationReason.createdFullName = request.user.name; + kpiUserEvaluationReason.lastUpdateUserId = request.user.sub; + kpiUserEvaluationReason.lastUpdateFullName = request.user.name; + await this.kpiUserEvaluationReasonCapacity.save(kpiUserEvaluationReason); + return new HttpSuccess(kpiUserEvaluationReason.id); + } else { + const kpiReason = await this.kpiUserEvaluationReasonCapacity.findOne({ + where: { id: id }, + relations: [ + "kpiUserCapacity", + "kpiUserCapacity.kpiUserEvaluation", + "kpiUserCapacity.kpiUserEvaluation.evaluatorId", + ], + }); + if (!kpiReason) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้", + ); + } + + if (user.trim().toUpperCase() == "EVALUATOR") { + kpiReason.reasonEvaluator = requestBody.reason; + kpiReason.status = + kpiReason.kpiUserCapacity.kpiUserEvaluation.commanderId == null ? "DONE" : "COMMANDER"; + } else if (user.trim().toUpperCase() == "COMMANDER") { + kpiReason.reasonCommander = requestBody.reason; + kpiReason.status = + kpiReason.kpiUserCapacity.kpiUserEvaluation.commanderHighId == null + ? "DONE" + : "COMMANDERHIGH"; + } else if (user.trim().toUpperCase() == "COMMANDERHIGH") { + kpiReason.reasonCommanderHigh = requestBody.reason; + kpiReason.status = "DONE"; + } + kpiReason.reasonCommanderHigh = requestBody.reason; + kpiReason.lastUpdateUserId = request.user.sub; + kpiReason.lastUpdateFullName = request.user.name; + await this.kpiUserEvaluationReasonCapacity.save(kpiReason); + return new HttpSuccess(kpiReason.id); + } + } + + /** + * API แก้ไขหมายเหตุ (USER) + * + * @summary แก้ไขหมายเหตุ (USER) + * + * @param {string} id Guid, *Id คนประเมิน (USER) + */ + @Put("problem/capacity/user/{id}") + async sendKpiCapacityReason( + @Path() id: string, + @Body() requestBody: updateKpiUserReasonEvaluation, + @Request() request: { user: Record }, + ) { + const kpiReason = await this.kpiUserEvaluationReasonCapacity.findOne({ + where: { id: id }, + relations: [ + "kpiUserCapacity", + "kpiUserCapacity.kpiUserEvaluation", + "kpiUserCapacity.kpiUserEvaluation.evaluatorId", + ], + }); + if (!kpiReason) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้", + ); + } + + kpiReason.status = + kpiReason.kpiUserCapacity.kpiUserEvaluation.commanderId == null ? "DONE" : "COMMANDER"; + kpiReason.reasonCommanderHigh = requestBody.reason; + kpiReason.lastUpdateUserId = request.user.sub; + kpiReason.lastUpdateFullName = request.user.name; + await this.kpiUserEvaluationReasonCapacity.save(kpiReason); + return new HttpSuccess(kpiReason.id); + } + + /** + * API list หมายเหตุ (USER) + * + * @summary list หมายเหตุ (USER) + * + * @param {string} id Guid, *Id คนประเมิน (USER) + */ + @Get("{type}/capacity/{user}/{id}") + async listKpiUserCapacityReason(@Path() id: string, @Path() type: string, @Path() user: string) { + if (type.trim().toUpperCase() == "PROGRESS") { + const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonCapacity.find({ + where: { kpiUserCapacityId: id }, + }); + return new HttpSuccess(kpiUserEvaluationReason); + } else { + if (user.trim().toUpperCase() == "USER") { + const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonCapacity.find({ + where: { kpiUserCapacityId: id }, + }); + return new HttpSuccess(kpiUserEvaluationReason); + } else if (user.trim().toUpperCase() == "EVALUATOR") { + const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonCapacity.find({ + where: { + kpiUserCapacityId: id, + status: In(["EVALUATOR", "COMMANDER", "COMMANDERHIGH", "DONE"]), + }, + }); + return new HttpSuccess(kpiUserEvaluationReason); + } else if (user.trim().toUpperCase() == "COMMANDER") { + const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonCapacity.find({ + where: { + kpiUserCapacityId: id, + status: In(["COMMANDER", "COMMANDERHIGH", "DONE"]), + }, + }); + return new HttpSuccess(kpiUserEvaluationReason); + } else if (user.trim().toUpperCase() == "COMMANDERHIGH") { + const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonCapacity.find({ + where: { + kpiUserCapacityId: id, + status: In(["COMMANDERHIGH", "DONE"]), + }, + }); + return new HttpSuccess(kpiUserEvaluationReason); + } + } + } +} diff --git a/src/controllers/KpiUserEvaluationController.ts b/src/controllers/KpiUserEvaluationController.ts index 84e03f0..3b2032b 100644 --- a/src/controllers/KpiUserEvaluationController.ts +++ b/src/controllers/KpiUserEvaluationController.ts @@ -190,57 +190,6 @@ export class KpiUserEvaluationController extends Controller { return new HttpSuccess(kpiUserEvaluation.id); } - // /** - // * API แก้ไขหมายเหตุ (USER) - // * - // * @summary แก้ไขหมายเหตุ (USER) - // * - // * @param {string} id Guid, *Id คนประเมิน (USER) - // */ - // @Put("{type}/{id}") - // async updateKpiUserEvaluatorEvaluation( - // @Path() id: string, - // @Path() type: string, - // @Body() requestBody: updateKpiUserReasonEvaluation, - // @Request() request: { user: Record }, - // ) { - // const kpiUserEvaluation = await this.kpiUserEvalutionRepository.findOne({ - // where: { id: id }, - // }); - // if (!kpiUserEvaluation) { - // throw new HttpError( - // HttpStatusCode.NOT_FOUND, - // "ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้", - // ); - // } - - // const kpiUserEvaluationReason = Object.assign(new KpiUserEvaluationReason(), requestBody); - // kpiUserEvaluationReason.type = type.trim().toUpperCase(); - // kpiUserEvaluationReason.kpiUserEvaluationId = id; - // kpiUserEvaluationReason.createdUserId = request.user.sub; - // kpiUserEvaluationReason.createdFullName = request.user.name; - // kpiUserEvaluationReason.lastUpdateUserId = request.user.sub; - // kpiUserEvaluationReason.lastUpdateFullName = request.user.name; - // await this.kpiUserEvaluationReasonRepository.save(kpiUserEvaluationReason); - // return new HttpSuccess(kpiUserEvaluation.id); - // } - - // /** - // * API list หมายเหตุ (USER) - // * - // * @summary list หมายเหตุ (USER) - // * - // * @param {string} id Guid, *Id คนประเมิน (USER) - // */ - // @Get("{type}/{id}") - // async listKpiUserCommanderEvaluation(@Path() id: string, @Path() type: string) { - // const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonRepository.find({ - // where: { kpiUserEvaluationId: id, type: type.trim().toUpperCase() }, - // order: { createdAt: "ASC" }, - // }); - // return new HttpSuccess(kpiUserEvaluationReason); - // } - /** * API แก้ไขรายการประเมินผลการปฏิบัติราชการระดับบุคคล (USER) * diff --git a/src/entities/kpiUserEvaluationReasonCapacity.ts b/src/entities/kpiUserEvaluationReasonCapacity.ts index f46ffa1..cc3bb55 100644 --- a/src/entities/kpiUserEvaluationReasonCapacity.ts +++ b/src/entities/kpiUserEvaluationReasonCapacity.ts @@ -45,7 +45,7 @@ export class KpiUserEvaluationReasonCapacity extends EntityBase { @Column({ nullable: true, - comment: "สถานะ DRAFT EVALUATOR COMMANDER COMMANDERHIGH", + comment: "สถานะ DRAFT EVALUATOR COMMANDER COMMANDERHIGH DONE", length: 255, default: "DRAFT", }) @@ -77,7 +77,7 @@ export class KpiUserEvaluationReasonCapacity extends EntityBase { export class updateKpiUserReasonEvaluation { @Column() - reason: string | null; + reason: string; @Column() - topic: string | null; + topic?: string | null; } diff --git a/src/entities/kpiUserEvaluationReasonDevelopment.ts b/src/entities/kpiUserEvaluationReasonDevelopment.ts index 1272beb..23c00c5 100644 --- a/src/entities/kpiUserEvaluationReasonDevelopment.ts +++ b/src/entities/kpiUserEvaluationReasonDevelopment.ts @@ -74,10 +74,3 @@ export class KpiUserEvaluationReasonDevelopment extends EntityBase { @JoinColumn({ name: "kpiUserDevelopmentId" }) kpiUserDevelopment: KpiUserDevelopment; } - -export class updateKpiUserReasonEvaluation { - @Column() - reason: string | null; - @Column() - topic: string | null; -} diff --git a/src/entities/kpiUserEvaluationReasonPlan.ts b/src/entities/kpiUserEvaluationReasonPlan.ts index e9b9ad7..3d5b9b7 100644 --- a/src/entities/kpiUserEvaluationReasonPlan.ts +++ b/src/entities/kpiUserEvaluationReasonPlan.ts @@ -71,10 +71,3 @@ export class KpiUserEvaluationReasonPlan extends EntityBase { @JoinColumn({ name: "kpiUserPlanId" }) kpiUserPlanned: KpiUserPlanned; } - -export class updateKpiUserReasonEvaluation { - @Column() - reason: string | null; - @Column() - topic: string | null; -} diff --git a/src/entities/kpiUserEvaluationReasonRole.ts b/src/entities/kpiUserEvaluationReasonRole.ts index 1e13c9a..c5c4bce 100644 --- a/src/entities/kpiUserEvaluationReasonRole.ts +++ b/src/entities/kpiUserEvaluationReasonRole.ts @@ -71,10 +71,3 @@ export class KpiUserEvaluationReasonRole extends EntityBase { @JoinColumn({ name: "kpiUserRoleId" }) kpiUserRole: KpiUserRole; } - -export class updateKpiUserReasonEvaluation { - @Column() - reason: string | null; - @Column() - topic: string | null; -} diff --git a/src/entities/kpiUserEvaluationReasonSpecial.ts b/src/entities/kpiUserEvaluationReasonSpecial.ts index 900c46c..4077003 100644 --- a/src/entities/kpiUserEvaluationReasonSpecial.ts +++ b/src/entities/kpiUserEvaluationReasonSpecial.ts @@ -74,10 +74,3 @@ export class KpiUserEvaluationReasonSpecial extends EntityBase { @JoinColumn({ name: "kpiUserSpecialId" }) kpiUserSpecial: KpiUserSpecial; } - -export class updateKpiUserReasonEvaluation { - @Column() - reason: string | null; - @Column() - topic: string | null; -} diff --git a/src/migration/1715186761853-add_table_kpiUserEvaluationreason.ts b/src/migration/1715186761853-add_table_kpiUserEvaluationreason.ts new file mode 100644 index 0000000..bfe65bc --- /dev/null +++ b/src/migration/1715186761853-add_table_kpiUserEvaluationreason.ts @@ -0,0 +1,32 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AddTableKpiUserEvaluationreason1715186761853 implements MigrationInterface { + name = 'AddTableKpiUserEvaluationreason1715186761853' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`CREATE TABLE \`kpiUserEvaluationReasonPlan\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`topic\` varchar(255) NULL COMMENT 'หัวข้อ', \`reason\` varchar(255) NULL COMMENT 'หมายเหตุ', \`reasonEvaluator\` varchar(255) NULL COMMENT 'หมายเหตุ ผู้ประเมิน', \`reasonCommander\` varchar(255) NULL COMMENT 'หมายเหตุ ผู้บังคับบัญชาเหนือขึ้นไป', \`reasonCommanderHigh\` varchar(255) NULL COMMENT 'หมายเหตุ ผู้บังคับบัญชาเหนือขึ้นไปอีกชั้นหนึ่ง', \`status\` varchar(255) NULL COMMENT 'สถานะ DRAFT EVALUATOR COMMANDER COMMANDERHIGH' DEFAULT 'DRAFT', \`type\` varchar(255) NULL COMMENT 'ประเภท PROGRESS PROBLEM', \`kpiUserPlannedId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง kpiUserPlan', \`kpiUserPlanId\` varchar(36) NULL, PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`CREATE TABLE \`kpiUserEvaluationReasonRole\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`topic\` varchar(255) NULL COMMENT 'หัวข้อ', \`reason\` varchar(255) NULL COMMENT 'หมายเหตุ', \`reasonEvaluator\` varchar(255) NULL COMMENT 'หมายเหตุ ผู้ประเมิน', \`reasonCommander\` varchar(255) NULL COMMENT 'หมายเหตุ ผู้บังคับบัญชาเหนือขึ้นไป', \`reasonCommanderHigh\` varchar(255) NULL COMMENT 'หมายเหตุ ผู้บังคับบัญชาเหนือขึ้นไปอีกชั้นหนึ่ง', \`status\` varchar(255) NULL COMMENT 'สถานะ DRAFT EVALUATOR COMMANDER COMMANDERHIGH' DEFAULT 'DRAFT', \`type\` varchar(255) NULL COMMENT 'ประเภท PROGRESS PROBLEM', \`kpiUserRoleId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง kpiUserRole', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`CREATE TABLE \`kpiUserEvaluationReasonSpecial\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`topic\` varchar(255) NULL COMMENT 'หัวข้อ', \`reason\` varchar(255) NULL COMMENT 'หมายเหตุ', \`reasonEvaluator\` varchar(255) NULL COMMENT 'หมายเหตุ ผู้ประเมิน', \`reasonCommander\` varchar(255) NULL COMMENT 'หมายเหตุ ผู้บังคับบัญชาเหนือขึ้นไป', \`reasonCommanderHigh\` varchar(255) NULL COMMENT 'หมายเหตุ ผู้บังคับบัญชาเหนือขึ้นไปอีกชั้นหนึ่ง', \`status\` varchar(255) NULL COMMENT 'สถานะ DRAFT EVALUATOR COMMANDER COMMANDERHIGH' DEFAULT 'DRAFT', \`type\` varchar(255) NULL COMMENT 'ประเภท PROGRESS PROBLEM', \`kpiUserSpecialId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง kpiUserSpecial', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`CREATE TABLE \`kpiUserEvaluationReasonDevelopment\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`topic\` varchar(255) NULL COMMENT 'หัวข้อ', \`reason\` varchar(255) NULL COMMENT 'หมายเหตุ', \`reasonEvaluator\` varchar(255) NULL COMMENT 'หมายเหตุ ผู้ประเมิน', \`reasonCommander\` varchar(255) NULL COMMENT 'หมายเหตุ ผู้บังคับบัญชาเหนือขึ้นไป', \`reasonCommanderHigh\` varchar(255) NULL COMMENT 'หมายเหตุ ผู้บังคับบัญชาเหนือขึ้นไปอีกชั้นหนึ่ง', \`status\` varchar(255) NULL COMMENT 'สถานะ DRAFT EVALUATOR COMMANDER COMMANDERHIGH' DEFAULT 'DRAFT', \`type\` varchar(255) NULL COMMENT 'ประเภท PROGRESS PROBLEM', \`kpiUserDevelopmentId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง kpiUserDevelopment', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`CREATE TABLE \`kpiUserEvaluationReasonCapacity\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`topic\` varchar(255) NULL COMMENT 'หัวข้อ', \`reason\` varchar(255) NULL COMMENT 'หมายเหตุ', \`reasonEvaluator\` varchar(255) NULL COMMENT 'หมายเหตุ ผู้ประเมิน', \`reasonCommander\` varchar(255) NULL COMMENT 'หมายเหตุ ผู้บังคับบัญชาเหนือขึ้นไป', \`reasonCommanderHigh\` varchar(255) NULL COMMENT 'หมายเหตุ ผู้บังคับบัญชาเหนือขึ้นไปอีกชั้นหนึ่ง', \`status\` varchar(255) NULL COMMENT 'สถานะ DRAFT EVALUATOR COMMANDER COMMANDERHIGH DONE' DEFAULT 'DRAFT', \`type\` varchar(255) NULL COMMENT 'ประเภท PROGRESS PROBLEM', \`kpiUserCapacityId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง kpiUserCapacity', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`ALTER TABLE \`kpiUserEvaluationReasonPlan\` ADD CONSTRAINT \`FK_6eda960b0eada6c174ac4a6ffb8\` FOREIGN KEY (\`kpiUserPlanId\`) REFERENCES \`kpiUserPlanned\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`kpiUserEvaluationReasonRole\` ADD CONSTRAINT \`FK_63c490a2629e63d180aae4c2262\` FOREIGN KEY (\`kpiUserRoleId\`) REFERENCES \`kpiUserRole\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`kpiUserEvaluationReasonSpecial\` ADD CONSTRAINT \`FK_cba6dc7922a6aeef4009df4a543\` FOREIGN KEY (\`kpiUserSpecialId\`) REFERENCES \`kpiUserSpecial\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`kpiUserEvaluationReasonDevelopment\` ADD CONSTRAINT \`FK_c323b5d8c6ffaa73a4e45f8bfc9\` FOREIGN KEY (\`kpiUserDevelopmentId\`) REFERENCES \`kpiUserDevelopment\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`kpiUserEvaluationReasonCapacity\` ADD CONSTRAINT \`FK_dea923eb90ab99137a5ebf02b59\` FOREIGN KEY (\`kpiUserCapacityId\`) REFERENCES \`kpiUserCapacity\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`kpiUserEvaluationReasonCapacity\` DROP FOREIGN KEY \`FK_dea923eb90ab99137a5ebf02b59\``); + await queryRunner.query(`ALTER TABLE \`kpiUserEvaluationReasonDevelopment\` DROP FOREIGN KEY \`FK_c323b5d8c6ffaa73a4e45f8bfc9\``); + await queryRunner.query(`ALTER TABLE \`kpiUserEvaluationReasonSpecial\` DROP FOREIGN KEY \`FK_cba6dc7922a6aeef4009df4a543\``); + await queryRunner.query(`ALTER TABLE \`kpiUserEvaluationReasonRole\` DROP FOREIGN KEY \`FK_63c490a2629e63d180aae4c2262\``); + await queryRunner.query(`ALTER TABLE \`kpiUserEvaluationReasonPlan\` DROP FOREIGN KEY \`FK_6eda960b0eada6c174ac4a6ffb8\``); + await queryRunner.query(`DROP TABLE \`kpiUserEvaluationReasonCapacity\``); + await queryRunner.query(`DROP TABLE \`kpiUserEvaluationReasonDevelopment\``); + await queryRunner.query(`DROP TABLE \`kpiUserEvaluationReasonSpecial\``); + await queryRunner.query(`DROP TABLE \`kpiUserEvaluationReasonRole\``); + await queryRunner.query(`DROP TABLE \`kpiUserEvaluationReasonPlan\``); + } + +}