checkpoint crud Achievement
This commit is contained in:
parent
245e7f9df5
commit
f16fff075f
4 changed files with 425 additions and 225 deletions
|
|
@ -1,234 +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 { KpiUserPlanned, CreateKpiUserPlanned, UpdateKpiUserPlanned } from "../entities/KpiUserPlanned";
|
||||
// import HttpError from "../interfaces/http-error";
|
||||
// import { Not } from "typeorm";
|
||||
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";
|
||||
import { KpiUserEvaluation } from "../entities/kpiUserEvaluation";
|
||||
import { KpiPlan } from "../entities/kpiPlan";
|
||||
|
||||
// @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);
|
||||
@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 kpiUserPlannedRepository = AppDataSource.getRepository(KpiUserPlanned);
|
||||
private kpiUserEvaluationRepository = AppDataSource.getRepository(KpiUserEvaluation);
|
||||
private kpiPlanRepository = AppDataSource.getRepository(KpiPlan);
|
||||
|
||||
// /**
|
||||
// * 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 - เพิ่มงานตามแผนปฏิบัติราชการประจำปี #48
|
||||
*
|
||||
*/
|
||||
@Post()
|
||||
async createKpiUserPlanned(
|
||||
@Body()
|
||||
requestBody: CreateKpiUserPlanned,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
const chkUserEvaluation = await this.kpiUserEvaluationRepository.findOne({
|
||||
where:{id:requestBody.kpiUserEvaluationId},
|
||||
})
|
||||
if (!chkUserEvaluation) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบประเมินผู้ใช้งาน");
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 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);
|
||||
// }
|
||||
const chkKpiPlan = await this.kpiPlanRepository.findOne({
|
||||
where:{id:requestBody.kpiPlanId},
|
||||
})
|
||||
if (!chkKpiPlan) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบประเมินตามแผน");
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 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,
|
||||
// "ไม่สามารถลบได้เนื่องจากพบข้อมูลที่ตารางระดับตำแหน่ง",
|
||||
// );
|
||||
// }
|
||||
const kpiUserPlanned = Object.assign(new KpiUserPlanned(), requestBody);
|
||||
if (!kpiUserPlanned) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
// await this.posTypeRepository.remove(delKpiUserPlanned);
|
||||
// return new HttpSuccess();
|
||||
// }
|
||||
kpiUserPlanned.createdUserId = request.user.sub;
|
||||
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 รายละเอียดประเภทตำแหน่ง
|
||||
// *
|
||||
// * @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, "ไม่พบข้อมูลประเภทตำแหน่งนี้");
|
||||
// }
|
||||
/**
|
||||
* API แก้ไขงานตามแผนปฏิบัติราชการประจำปี
|
||||
*
|
||||
* @summary - แก้ไขงานตามแผนปฏิบัติราชการประจำปี #49
|
||||
*
|
||||
* @param {string} id Id งานตามแผนปฏิบัติราชการประจำปี
|
||||
*/
|
||||
@Put("{id}")
|
||||
async editKpiUserPlanned(
|
||||
@Path() id: string,
|
||||
@Body() requestBody: UpdateKpiUserPlanned,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
const kpiUserPlanned = await this.kpiUserPlannedRepository.findOne({ where: { id } });
|
||||
if (!kpiUserPlanned) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลงานตามแผนปฏิบัติราชการประจำปีนี้");
|
||||
}
|
||||
|
||||
kpiUserPlanned.lastUpdateUserId = request.user.sub;
|
||||
kpiUserPlanned.lastUpdateFullName = request.user.name;
|
||||
this.kpiUserPlannedRepository.merge(kpiUserPlanned, requestBody);
|
||||
await this.kpiUserPlannedRepository.save(kpiUserPlanned);
|
||||
return new HttpSuccess(kpiUserPlanned.id);
|
||||
}
|
||||
|
||||
// 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,
|
||||
// })),
|
||||
// };
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
// return new HttpSuccess(mapGetKpiUserPlanned);
|
||||
// }
|
||||
// /**
|
||||
// * API รายละเอียดงานตามแผนปฏิบัติราชการประจำปี
|
||||
// *
|
||||
// * @summary - รายละเอียดงานตามแผนปฏิบัติราชการประจำปี #51
|
||||
// *
|
||||
// * @param {string} id Id งานตามแผนปฏิบัติราชการประจำปี
|
||||
// */
|
||||
// @Get("{id}")
|
||||
// async GetKpiUserPlannedDetail(@Path() id: string) {
|
||||
// const getKpiUserPlanned = await this.kpiUserPlannedRepository.findOne({
|
||||
// select: ["id", "kpiUserPlannedName", "kpiUserPlannedRank"],
|
||||
// relations: ["posLevels"],
|
||||
// where: { id: id },
|
||||
// });
|
||||
// if (!getKpiUserPlanned) {
|
||||
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลงานตามแผนปฏิบัติราชการประจำปีนี้");
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * 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);
|
||||
// }
|
||||
// }
|
||||
// const mapGetKpiUserPlanned = {
|
||||
// id: getKpiUserPlanned.id,
|
||||
// kpiUserPlannedName: getKpiUserPlanned.kpiUserPlannedName,
|
||||
// kpiUserPlannedRank: getKpiUserPlanned.kpiUserPlannedRank,
|
||||
// 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 - รายการงานตามแผนปฏิบัติราชการประจำปี #29
|
||||
*
|
||||
*/
|
||||
@Get()
|
||||
async GetKpiUserPlanned() {
|
||||
const kpiUserPlanned = await this.kpiUserPlannedRepository.find({
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
183
src/controllers/KpiUserRoleController.ts
Normal file
183
src/controllers/KpiUserRoleController.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
|
|
@ -64,3 +64,37 @@ export class KpiUserPlanned extends EntityBase {
|
|||
@JoinColumn({ name: "kpiPlanId" })
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,3 +64,37 @@ export class KpiUserRole extends EntityBase {
|
|||
@JoinColumn({ name: "kpiRoleId" })
|
||||
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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue