kpi plan
This commit is contained in:
parent
c4a975b503
commit
a9dd103ff8
16 changed files with 1484 additions and 15 deletions
|
|
@ -20,7 +20,7 @@ import HttpSuccess from "../interfaces/http-success";
|
|||
import HttpError from "../interfaces/http-error";
|
||||
import { Like, Not } from "typeorm";
|
||||
import HttpStatusCode from "../interfaces/http-status";
|
||||
import { KpiGroup, creatKpiGroup, updateKpiGroup } from "../entities/kpiGroup";
|
||||
import { KpiGroup, createKpiGroup, updateKpiGroup } from "../entities/kpiGroup";
|
||||
@Route("api/v1/kpi/group")
|
||||
@Tags("kpiGroup")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -42,7 +42,7 @@ export class kpiGroupController extends Controller {
|
|||
nameGroupKPI: "string", //ชื่อกลุ่มงาน
|
||||
})
|
||||
async createKpiGroup(
|
||||
@Body() requestBody: creatKpiGroup,
|
||||
@Body() requestBody: createKpiGroup,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
const kpiGroup = Object.assign(new KpiGroup(), requestBody);
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ import { Like } from "typeorm/browser";
|
|||
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
|
||||
)
|
||||
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||
export class kpiController extends Controller {
|
||||
export class kpiPeriodController extends Controller {
|
||||
private kpiPeriodRepository = AppDataSource.getRepository(KpiPeriod);
|
||||
/**
|
||||
* สร้างรอบการประเมินผลการปฏิบัติหน้าที่ราชการ
|
||||
|
|
@ -152,7 +152,7 @@ export class kpiController extends Controller {
|
|||
async GetKpiPeriodById(@Path() id: string) {
|
||||
const kpiPeriod = await this.kpiPeriodRepository.findOne({
|
||||
where: { id: id },
|
||||
select: ["durationKPI", "startDate", "endDate", "isActive"],
|
||||
select: ["year", "durationKPI", "startDate", "endDate", "isActive"],
|
||||
});
|
||||
if (!kpiPeriod) {
|
||||
throw new HttpError(
|
||||
|
|
@ -173,15 +173,19 @@ export class kpiController extends Controller {
|
|||
async listKpiPeriod(
|
||||
@Query("page") page: number = 1,
|
||||
@Query("pageSize") pageSize: number = 10,
|
||||
@Query("year") year?: string,
|
||||
@Query("year") year?: number,
|
||||
@Query("keyword") keyword?: string,
|
||||
) {
|
||||
const [kpiPeriod, total] = await this.kpiPeriodRepository.findAndCount({
|
||||
// where: {
|
||||
// durationKPI: Like(`%${keyword}%`),
|
||||
// },
|
||||
...(keyword ? {} : { skip: (page - 1) * pageSize, take: pageSize }),
|
||||
});
|
||||
const [kpiPeriod, total] = await AppDataSource.getRepository(KpiPeriod)
|
||||
.createQueryBuilder("kpiPeriod")
|
||||
.andWhere(
|
||||
year !== 0 && year != null && year != undefined ? "kpiPeriod.year = :year" : "1=1",
|
||||
{ year: year },
|
||||
)
|
||||
.orderBy("kpiPeriod.createdAt", "DESC")
|
||||
.skip((page - 1) * pageSize)
|
||||
.take(pageSize)
|
||||
.getManyAndCount();
|
||||
|
||||
return new HttpSuccess({ data: kpiPeriod, total });
|
||||
}
|
||||
|
|
@ -191,7 +195,7 @@ export class kpiController extends Controller {
|
|||
* @param id
|
||||
*/
|
||||
@Delete("{id}")
|
||||
async deleteKpiPerriod(@Path() id: string) {
|
||||
async deleteKpiPeriod(@Path() id: string) {
|
||||
const kpiPeriod = await this.kpiPeriodRepository.findOne({
|
||||
where: { id: id },
|
||||
});
|
||||
|
|
|
|||
311
src/controllers/KpiPlanController.ts
Normal file
311
src/controllers/KpiPlanController.ts
Normal file
|
|
@ -0,0 +1,311 @@
|
|||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Put,
|
||||
Delete,
|
||||
Route,
|
||||
Security,
|
||||
Tags,
|
||||
Body,
|
||||
Path,
|
||||
Request,
|
||||
Example,
|
||||
SuccessResponse,
|
||||
Response,
|
||||
Query,
|
||||
} from "tsoa";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import HttpStatusCode from "../interfaces/http-status";
|
||||
import { KpiPlan, createKpiPlan, updateKpiPlan } from "../entities/kpiPlan";
|
||||
import CallAPI from "../interfaces/call-api";
|
||||
|
||||
@Route("api/v1/kpi/plan")
|
||||
@Tags("kpiPlan")
|
||||
@Security("bearerAuth")
|
||||
@Response(
|
||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
|
||||
)
|
||||
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||
export class kpiPlanController extends Controller {
|
||||
private kpiPlanRepository = AppDataSource.getRepository(KpiPlan);
|
||||
/**
|
||||
* สร้างตัวชี้วัดตามแผนฯ
|
||||
* @param requestBody
|
||||
* @param request
|
||||
*/
|
||||
@Post()
|
||||
async createKpiPlan(
|
||||
@Body() requestBody: createKpiPlan,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
const kpiPlan = Object.assign(new KpiPlan(), requestBody);
|
||||
await new CallAPI()
|
||||
.PostData(request, "org/find/all", {
|
||||
node: requestBody.node,
|
||||
nodeId: requestBody.nodeId,
|
||||
})
|
||||
.then((x) => {
|
||||
kpiPlan.root = x.root;
|
||||
kpiPlan.rootId = x.rootId;
|
||||
kpiPlan.rootShortName = x.rootShortName;
|
||||
kpiPlan.child1 = requestBody.node <= 0 ? null : x.child1;
|
||||
kpiPlan.child1Id = requestBody.node <= 0 ? null : x.child1Id;
|
||||
kpiPlan.child1ShortName = requestBody.node <= 0 ? null : x.child1ShortName;
|
||||
kpiPlan.child2 = requestBody.node <= 1 ? null : x.child2;
|
||||
kpiPlan.child2Id = requestBody.node <= 1 ? null : x.child2Id;
|
||||
kpiPlan.child2ShortName = requestBody.node <= 1 ? null : x.child2ShortName;
|
||||
kpiPlan.child3 = requestBody.node <= 2 ? null : x.child3;
|
||||
kpiPlan.child3Id = requestBody.node <= 2 ? null : x.child3Id;
|
||||
kpiPlan.child3ShortName = requestBody.node <= 2 ? null : x.child3ShortName;
|
||||
kpiPlan.child4 = requestBody.node <= 3 ? null : x.child4;
|
||||
kpiPlan.child4Id = requestBody.node <= 3 ? null : x.child4Id;
|
||||
kpiPlan.child4ShortName = requestBody.node <= 3 ? null : x.child4ShortName;
|
||||
})
|
||||
.catch((x) => {});
|
||||
await new CallAPI()
|
||||
.PostData(request, "development/strategy/find/all", {
|
||||
strategy: requestBody.strategy,
|
||||
strategyId: requestBody.strategyId,
|
||||
})
|
||||
.then((x) => {
|
||||
kpiPlan.strategyChild1 = x.strategyChild1;
|
||||
kpiPlan.strategyChild1Id = x.strategyChild1Id;
|
||||
kpiPlan.strategyChild2 = requestBody.strategy <= 1 ? null : x.strategyChild2;
|
||||
kpiPlan.strategyChild2Id = requestBody.strategy <= 1 ? null : x.strategyChild2Id;
|
||||
kpiPlan.strategyChild3 = requestBody.strategy <= 2 ? null : x.strategyChild3;
|
||||
kpiPlan.strategyChild3Id = requestBody.strategy <= 2 ? null : x.strategyChild3Id;
|
||||
kpiPlan.strategyChild4 = requestBody.strategy <= 3 ? null : x.strategyChild4;
|
||||
kpiPlan.strategyChild4Id = requestBody.strategy <= 3 ? null : x.strategyChild4Id;
|
||||
kpiPlan.strategyChild5 = requestBody.strategy <= 4 ? null : x.strategyChild5;
|
||||
kpiPlan.strategyChild5Id = requestBody.strategy <= 4 ? null : x.strategyChild5Id;
|
||||
})
|
||||
.catch((x) => {});
|
||||
kpiPlan.round = requestBody.round.trim().toUpperCase();
|
||||
kpiPlan.createdUserId = request.user.sub;
|
||||
kpiPlan.createdFullName = request.user.name;
|
||||
kpiPlan.lastUpdateUserId = request.user.sub;
|
||||
kpiPlan.lastUpdateFullName = request.user.name;
|
||||
await this.kpiPlanRepository.save(kpiPlan);
|
||||
return new HttpSuccess(kpiPlan.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* API แก้ไขตัวชี้วัดตามแผนฯ
|
||||
* @param id
|
||||
* @param requestBody
|
||||
* @param request
|
||||
*/
|
||||
@Put("{id}")
|
||||
async updateKpiPlan(
|
||||
@Path() id: string,
|
||||
@Body() requestBody: updateKpiPlan,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
const kpiPlan = await this.kpiPlanRepository.findOne({
|
||||
where: { id: id },
|
||||
});
|
||||
if (!kpiPlan) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตัวชี้วัดตามแผนฯนี้");
|
||||
}
|
||||
|
||||
kpiPlan.round = requestBody.round.trim().toUpperCase();
|
||||
Object.assign(kpiPlan, requestBody);
|
||||
await new CallAPI()
|
||||
.PostData(request, "org/find/all", {
|
||||
node: requestBody.node,
|
||||
nodeId: requestBody.nodeId,
|
||||
})
|
||||
.then((x) => {
|
||||
kpiPlan.root = x.root;
|
||||
kpiPlan.rootId = x.rootId;
|
||||
kpiPlan.rootShortName = x.rootShortName;
|
||||
kpiPlan.child1 = requestBody.node <= 0 ? null : x.child1;
|
||||
kpiPlan.child1Id = requestBody.node <= 0 ? null : x.child1Id;
|
||||
kpiPlan.child1ShortName = requestBody.node <= 0 ? null : x.child1ShortName;
|
||||
kpiPlan.child2 = requestBody.node <= 1 ? null : x.child2;
|
||||
kpiPlan.child2Id = requestBody.node <= 1 ? null : x.child2Id;
|
||||
kpiPlan.child2ShortName = requestBody.node <= 1 ? null : x.child2ShortName;
|
||||
kpiPlan.child3 = requestBody.node <= 2 ? null : x.child3;
|
||||
kpiPlan.child3Id = requestBody.node <= 2 ? null : x.child3Id;
|
||||
kpiPlan.child3ShortName = requestBody.node <= 2 ? null : x.child3ShortName;
|
||||
kpiPlan.child4 = requestBody.node <= 3 ? null : x.child4;
|
||||
kpiPlan.child4Id = requestBody.node <= 3 ? null : x.child4Id;
|
||||
kpiPlan.child4ShortName = requestBody.node <= 3 ? null : x.child4ShortName;
|
||||
})
|
||||
.catch((x) => {});
|
||||
await new CallAPI()
|
||||
.PostData(request, "development/strategy/find/all", {
|
||||
strategy: requestBody.strategy,
|
||||
strategyId: requestBody.strategyId,
|
||||
})
|
||||
.then((x) => {
|
||||
kpiPlan.strategyChild1 = x.strategyChild1;
|
||||
kpiPlan.strategyChild1Id = x.strategyChild1Id;
|
||||
kpiPlan.strategyChild2 = requestBody.strategy <= 1 ? null : x.strategyChild2;
|
||||
kpiPlan.strategyChild2Id = requestBody.strategy <= 1 ? null : x.strategyChild2Id;
|
||||
kpiPlan.strategyChild3 = requestBody.strategy <= 2 ? null : x.strategyChild3;
|
||||
kpiPlan.strategyChild3Id = requestBody.strategy <= 2 ? null : x.strategyChild3Id;
|
||||
kpiPlan.strategyChild4 = requestBody.strategy <= 3 ? null : x.strategyChild4;
|
||||
kpiPlan.strategyChild4Id = requestBody.strategy <= 3 ? null : x.strategyChild4Id;
|
||||
kpiPlan.strategyChild5 = requestBody.strategy <= 4 ? null : x.strategyChild5;
|
||||
kpiPlan.strategyChild5Id = requestBody.strategy <= 4 ? null : x.strategyChild5Id;
|
||||
})
|
||||
.catch((x) => {});
|
||||
kpiPlan.createdUserId = request.user.sub;
|
||||
kpiPlan.createdFullName = request.user.name;
|
||||
kpiPlan.lastUpdateUserId = request.user.sub;
|
||||
kpiPlan.lastUpdateFullName = request.user.name;
|
||||
await this.kpiPlanRepository.save(kpiPlan);
|
||||
return new HttpSuccess(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* API ตัวชี้วัดตามแผนฯ
|
||||
* @param id Guid, *Id ตัวชี้วัดตามแผนฯ
|
||||
*/
|
||||
@Get("{id}")
|
||||
async GetKpiPlanById(@Path() id: string) {
|
||||
const kpiPlan = await this.kpiPlanRepository.findOne({
|
||||
where: { id: id },
|
||||
});
|
||||
if (!kpiPlan) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตัวชี้วัดตามแผนฯนี้");
|
||||
}
|
||||
let node = null;
|
||||
let nodeId = null;
|
||||
if (kpiPlan.child4Id != null) {
|
||||
node = 4;
|
||||
nodeId = kpiPlan.child4Id;
|
||||
} else if (kpiPlan.child3Id != null) {
|
||||
node = 3;
|
||||
nodeId = kpiPlan.child3Id;
|
||||
} else if (kpiPlan.child2Id != null) {
|
||||
node = 2;
|
||||
nodeId = kpiPlan.child2Id;
|
||||
} else if (kpiPlan.child1Id != null) {
|
||||
node = 1;
|
||||
nodeId = kpiPlan.child1Id;
|
||||
} else if (kpiPlan.rootId != null) {
|
||||
node = 0;
|
||||
nodeId = kpiPlan.rootId;
|
||||
}
|
||||
let strategy = null;
|
||||
let strategyId = null;
|
||||
if (kpiPlan.strategyChild5Id != null) {
|
||||
strategy = 5;
|
||||
strategyId = kpiPlan.strategyChild5Id;
|
||||
} else if (kpiPlan.strategyChild4Id != null) {
|
||||
strategy = 4;
|
||||
strategyId = kpiPlan.strategyChild4Id;
|
||||
} else if (kpiPlan.strategyChild3Id != null) {
|
||||
strategy = 3;
|
||||
strategyId = kpiPlan.strategyChild3Id;
|
||||
} else if (kpiPlan.strategyChild2Id != null) {
|
||||
strategy = 2;
|
||||
strategyId = kpiPlan.strategyChild2Id;
|
||||
} else if (kpiPlan.strategyChild1Id != null) {
|
||||
strategy = 1;
|
||||
strategyId = kpiPlan.strategyChild1Id;
|
||||
}
|
||||
const formattedData = {
|
||||
id: kpiPlan.id,
|
||||
year: kpiPlan.year,
|
||||
round: kpiPlan.round,
|
||||
including: kpiPlan.including,
|
||||
includingName: kpiPlan.includingName,
|
||||
target: kpiPlan.target,
|
||||
unit: kpiPlan.unit,
|
||||
weight: kpiPlan.weight,
|
||||
achievement1: kpiPlan.achievement1,
|
||||
achievement2: kpiPlan.achievement2,
|
||||
achievement3: kpiPlan.achievement3,
|
||||
achievement4: kpiPlan.achievement4,
|
||||
achievement5: kpiPlan.achievement5,
|
||||
meaning: kpiPlan.meaning,
|
||||
formula: kpiPlan.formula,
|
||||
node: node,
|
||||
nodeId: nodeId,
|
||||
orgRevisionId: kpiPlan.orgRevisionId,
|
||||
strategy: strategy,
|
||||
strategyId: strategyId,
|
||||
};
|
||||
return new HttpSuccess(formattedData);
|
||||
}
|
||||
|
||||
/**
|
||||
* API list ตัวชี้วัดตามแผนฯ
|
||||
* @param page
|
||||
* @param pageSize
|
||||
* @param keyword
|
||||
*/
|
||||
@Get()
|
||||
async listKpiPlan(
|
||||
@Query("page") page: number = 1,
|
||||
@Query("pageSize") pageSize: number = 10,
|
||||
@Query("round") round?: string,
|
||||
@Query("nodeId") nodeId?: string | null,
|
||||
@Query("node") node?: number | null,
|
||||
@Query("keyword") keyword?: string,
|
||||
) {
|
||||
const [kpiPlan, total] = await AppDataSource.getRepository(KpiPlan)
|
||||
.createQueryBuilder("kpiPlan")
|
||||
.andWhere(
|
||||
node != undefined && node != null
|
||||
? node == 4
|
||||
? "kpiPlan.child4Id LIKE :nodeId"
|
||||
: node == 3
|
||||
? "kpiPlan.child3Id LIKE :nodeId"
|
||||
: node == 2
|
||||
? "kpiPlan.child2Id LIKE :nodeId"
|
||||
: node == 1
|
||||
? "kpiPlan.child1Id LIKE :nodeId"
|
||||
: "kpiPlan.rootId LIKE :nodeId"
|
||||
: "1=1",
|
||||
{
|
||||
nodeId: `${nodeId}`,
|
||||
},
|
||||
)
|
||||
.andWhere(
|
||||
round != undefined && round != null && round != "" ? "kpiPlan.round LIKE :round" : "1=1",
|
||||
{
|
||||
round: `${round?.trim().toUpperCase()}`,
|
||||
},
|
||||
)
|
||||
.andWhere(keyword != undefined ? "kpiPlan.projectName LIKE :keyword" : "1=1", {
|
||||
keyword: `%${keyword}%`,
|
||||
})
|
||||
.select([
|
||||
"kpiPlan.id",
|
||||
"kpiPlan.year",
|
||||
"kpiPlan.round",
|
||||
"kpiPlan.including",
|
||||
"kpiPlan.includingName",
|
||||
])
|
||||
.orderBy("kpiPlan.createdAt", "DESC")
|
||||
.skip((page - 1) * pageSize)
|
||||
.take(pageSize)
|
||||
.getManyAndCount();
|
||||
|
||||
return new HttpSuccess({ data: kpiPlan, total });
|
||||
}
|
||||
|
||||
/**
|
||||
* API ลบตัวชี้วัดตามแผนฯ
|
||||
* @param id
|
||||
*/
|
||||
@Delete("{id}")
|
||||
async deleteKpiPlan(@Path() id: string) {
|
||||
const kpiPlan = await this.kpiPlanRepository.findOne({
|
||||
where: { id: id },
|
||||
});
|
||||
if (!kpiPlan) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตัวชี้วัดตามแผนฯนี้");
|
||||
}
|
||||
await this.kpiPlanRepository.remove(kpiPlan);
|
||||
return new HttpSuccess();
|
||||
}
|
||||
}
|
||||
255
src/controllers/KpiRoleController.ts
Normal file
255
src/controllers/KpiRoleController.ts
Normal file
|
|
@ -0,0 +1,255 @@
|
|||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Put,
|
||||
Delete,
|
||||
Route,
|
||||
Security,
|
||||
Tags,
|
||||
Body,
|
||||
Path,
|
||||
Request,
|
||||
Example,
|
||||
SuccessResponse,
|
||||
Response,
|
||||
Query,
|
||||
} from "tsoa";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import HttpStatusCode from "../interfaces/http-status";
|
||||
import { KpiRole, createKpiRole, updateKpiRole } from "../entities/kpiRole";
|
||||
import CallAPI from "../interfaces/call-api";
|
||||
|
||||
@Route("api/v1/kpi/role")
|
||||
@Tags("kpiRole")
|
||||
@Security("bearerAuth")
|
||||
@Response(
|
||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
|
||||
)
|
||||
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||
export class kpiRoleController extends Controller {
|
||||
private kpiRoleRepository = AppDataSource.getRepository(KpiRole);
|
||||
/**
|
||||
* สร้างตัวชี้วัดตามตำแหน่ง
|
||||
* @param requestBody
|
||||
* @param request
|
||||
*/
|
||||
@Post()
|
||||
async createKpiRole(
|
||||
@Body() requestBody: createKpiRole,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
const kpiRole = Object.assign(new KpiRole(), requestBody);
|
||||
await new CallAPI()
|
||||
.PostData(request, "org/find/all", {
|
||||
node: requestBody.node,
|
||||
nodeId: requestBody.nodeId,
|
||||
})
|
||||
.then((x) => {
|
||||
kpiRole.root = x.root;
|
||||
kpiRole.rootId = x.rootId;
|
||||
kpiRole.rootShortName = x.rootShortName;
|
||||
kpiRole.child1 = requestBody.node <= 0 ? null : x.child1;
|
||||
kpiRole.child1Id = requestBody.node <= 0 ? null : x.child1Id;
|
||||
kpiRole.child1ShortName = requestBody.node <= 0 ? null : x.child1ShortName;
|
||||
kpiRole.child2 = requestBody.node <= 1 ? null : x.child2;
|
||||
kpiRole.child2Id = requestBody.node <= 1 ? null : x.child2Id;
|
||||
kpiRole.child2ShortName = requestBody.node <= 1 ? null : x.child2ShortName;
|
||||
kpiRole.child3 = requestBody.node <= 2 ? null : x.child3;
|
||||
kpiRole.child3Id = requestBody.node <= 2 ? null : x.child3Id;
|
||||
kpiRole.child3ShortName = requestBody.node <= 2 ? null : x.child3ShortName;
|
||||
kpiRole.child4 = requestBody.node <= 3 ? null : x.child4;
|
||||
kpiRole.child4Id = requestBody.node <= 3 ? null : x.child4Id;
|
||||
kpiRole.child4ShortName = requestBody.node <= 3 ? null : x.child4ShortName;
|
||||
})
|
||||
.catch((x) => {});
|
||||
kpiRole.round = requestBody.round.trim().toUpperCase();
|
||||
kpiRole.createdUserId = request.user.sub;
|
||||
kpiRole.createdFullName = request.user.name;
|
||||
kpiRole.lastUpdateUserId = request.user.sub;
|
||||
kpiRole.lastUpdateFullName = request.user.name;
|
||||
await this.kpiRoleRepository.save(kpiRole);
|
||||
return new HttpSuccess(kpiRole.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* API แก้ไขตัวชี้วัดตามตำแหน่ง
|
||||
* @param id
|
||||
* @param requestBody
|
||||
* @param request
|
||||
*/
|
||||
@Put("{id}")
|
||||
async updateKpiRole(
|
||||
@Path() id: string,
|
||||
@Body() requestBody: updateKpiRole,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
const kpiRole = await this.kpiRoleRepository.findOne({
|
||||
where: { id: id },
|
||||
});
|
||||
if (!kpiRole) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตัวชี้วัดตามตำแหน่งนี้");
|
||||
}
|
||||
|
||||
kpiRole.round = requestBody.round.trim().toUpperCase();
|
||||
Object.assign(kpiRole, requestBody);
|
||||
await new CallAPI()
|
||||
.PostData(request, "org/find/all", {
|
||||
node: requestBody.node,
|
||||
nodeId: requestBody.nodeId,
|
||||
})
|
||||
.then((x) => {
|
||||
kpiRole.root = x.root;
|
||||
kpiRole.rootId = x.rootId;
|
||||
kpiRole.rootShortName = x.rootShortName;
|
||||
kpiRole.child1 = requestBody.node <= 0 ? null : x.child1;
|
||||
kpiRole.child1Id = requestBody.node <= 0 ? null : x.child1Id;
|
||||
kpiRole.child1ShortName = requestBody.node <= 0 ? null : x.child1ShortName;
|
||||
kpiRole.child2 = requestBody.node <= 1 ? null : x.child2;
|
||||
kpiRole.child2Id = requestBody.node <= 1 ? null : x.child2Id;
|
||||
kpiRole.child2ShortName = requestBody.node <= 1 ? null : x.child2ShortName;
|
||||
kpiRole.child3 = requestBody.node <= 2 ? null : x.child3;
|
||||
kpiRole.child3Id = requestBody.node <= 2 ? null : x.child3Id;
|
||||
kpiRole.child3ShortName = requestBody.node <= 2 ? null : x.child3ShortName;
|
||||
kpiRole.child4 = requestBody.node <= 3 ? null : x.child4;
|
||||
kpiRole.child4Id = requestBody.node <= 3 ? null : x.child4Id;
|
||||
kpiRole.child4ShortName = requestBody.node <= 3 ? null : x.child4ShortName;
|
||||
})
|
||||
.catch((x) => {});
|
||||
kpiRole.createdUserId = request.user.sub;
|
||||
kpiRole.createdFullName = request.user.name;
|
||||
kpiRole.lastUpdateUserId = request.user.sub;
|
||||
kpiRole.lastUpdateFullName = request.user.name;
|
||||
await this.kpiRoleRepository.save(kpiRole);
|
||||
return new HttpSuccess(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* API ตัวชี้วัดตามตำแหน่ง
|
||||
* @param id Guid, *Id ตัวชี้วัดตามตำแหน่ง
|
||||
*/
|
||||
@Get("{id}")
|
||||
async GetKpiRoleById(@Path() id: string) {
|
||||
const kpiRole = await this.kpiRoleRepository.findOne({
|
||||
where: { id: id },
|
||||
});
|
||||
if (!kpiRole) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตัวชี้วัดตามตำแหน่งนี้");
|
||||
}
|
||||
let node = null;
|
||||
let nodeId = null;
|
||||
if (kpiRole.child4Id != null) {
|
||||
node = 4;
|
||||
nodeId = kpiRole.child4Id;
|
||||
} else if (kpiRole.child3Id != null) {
|
||||
node = 3;
|
||||
nodeId = kpiRole.child3Id;
|
||||
} else if (kpiRole.child2Id != null) {
|
||||
node = 2;
|
||||
nodeId = kpiRole.child2Id;
|
||||
} else if (kpiRole.child1Id != null) {
|
||||
node = 1;
|
||||
nodeId = kpiRole.child1Id;
|
||||
} else if (kpiRole.rootId != null) {
|
||||
node = 0;
|
||||
nodeId = kpiRole.rootId;
|
||||
}
|
||||
const formattedData = {
|
||||
id: kpiRole.id,
|
||||
year: kpiRole.year,
|
||||
round: kpiRole.round,
|
||||
including: kpiRole.including,
|
||||
includingName: kpiRole.includingName,
|
||||
target: kpiRole.target,
|
||||
unit: kpiRole.unit,
|
||||
weight: kpiRole.weight,
|
||||
achievement1: kpiRole.achievement1,
|
||||
achievement2: kpiRole.achievement2,
|
||||
achievement3: kpiRole.achievement3,
|
||||
achievement4: kpiRole.achievement4,
|
||||
achievement5: kpiRole.achievement5,
|
||||
meaning: kpiRole.meaning,
|
||||
formula: kpiRole.formula,
|
||||
node: node,
|
||||
nodeId: nodeId,
|
||||
orgRevisionId: kpiRole.orgRevisionId,
|
||||
};
|
||||
return new HttpSuccess(formattedData);
|
||||
}
|
||||
|
||||
/**
|
||||
* API list ตัวชี้วัดตามตำแหน่ง
|
||||
* @param page
|
||||
* @param pageSize
|
||||
* @param keyword
|
||||
*/
|
||||
@Get()
|
||||
async listKpiRole(
|
||||
@Query("page") page: number = 1,
|
||||
@Query("pageSize") pageSize: number = 10,
|
||||
@Query("round") round?: string,
|
||||
@Query("nodeId") nodeId?: string | null,
|
||||
@Query("node") node?: number | null,
|
||||
@Query("keyword") keyword?: string,
|
||||
) {
|
||||
const [kpiRole, total] = await AppDataSource.getRepository(KpiRole)
|
||||
.createQueryBuilder("kpiRole")
|
||||
.andWhere(
|
||||
node != undefined && node != null
|
||||
? node == 4
|
||||
? "kpiRole.child4Id LIKE :nodeId"
|
||||
: node == 3
|
||||
? "kpiRole.child3Id LIKE :nodeId"
|
||||
: node == 2
|
||||
? "kpiRole.child2Id LIKE :nodeId"
|
||||
: node == 1
|
||||
? "kpiRole.child1Id LIKE :nodeId"
|
||||
: "kpiRole.rootId LIKE :nodeId"
|
||||
: "1=1",
|
||||
{
|
||||
nodeId: `${nodeId}`,
|
||||
},
|
||||
)
|
||||
.andWhere(
|
||||
round != undefined && round != null && round != "" ? "kpiRole.round LIKE :round" : "1=1",
|
||||
{
|
||||
round: `${round?.trim().toUpperCase()}`,
|
||||
},
|
||||
)
|
||||
.andWhere(keyword != undefined ? "kpiRole.projectName LIKE :keyword" : "1=1", {
|
||||
keyword: `%${keyword}%`,
|
||||
})
|
||||
.select([
|
||||
"kpiRole.id",
|
||||
"kpiRole.year",
|
||||
"kpiRole.round",
|
||||
"kpiRole.including",
|
||||
"kpiRole.includingName",
|
||||
])
|
||||
.orderBy("kpiRole.createdAt", "DESC")
|
||||
.skip((page - 1) * pageSize)
|
||||
.take(pageSize)
|
||||
.getManyAndCount();
|
||||
|
||||
return new HttpSuccess({ data: kpiRole, total });
|
||||
}
|
||||
|
||||
/**
|
||||
* API ลบตัวชี้วัดตามตำแหน่ง
|
||||
* @param id
|
||||
*/
|
||||
@Delete("{id}")
|
||||
async deleteKpiRole(@Path() id: string) {
|
||||
const kpiRole = await this.kpiRoleRepository.findOne({
|
||||
where: { id: id },
|
||||
});
|
||||
if (!kpiRole) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตัวชี้วัดตามตำแหน่งนี้");
|
||||
}
|
||||
await this.kpiRoleRepository.remove(kpiRole);
|
||||
return new HttpSuccess();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue