no message
This commit is contained in:
parent
e29c7c127f
commit
ee77d0c51c
5 changed files with 80 additions and 28 deletions
|
|
@ -21,6 +21,7 @@ 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";
|
||||
import { KpiPeriod } from "../entities/kpiPeriod";
|
||||
|
||||
@Route("api/v1/kpi/role")
|
||||
@Tags("kpiRole")
|
||||
|
|
@ -32,6 +33,7 @@ import CallAPI from "../interfaces/call-api";
|
|||
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||
export class kpiRoleController extends Controller {
|
||||
private kpiRoleRepository = AppDataSource.getRepository(KpiRole);
|
||||
private kpiPeriodRepository = AppDataSource.getRepository(KpiPeriod);
|
||||
/**
|
||||
* สร้างตัวชี้วัดตามตำแหน่ง
|
||||
* @param requestBody
|
||||
|
|
@ -43,6 +45,14 @@ export class kpiRoleController extends Controller {
|
|||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
const kpiRole = Object.assign(new KpiRole(), requestBody);
|
||||
if (requestBody.kpiPeriodId != null) {
|
||||
const kpiPeriod = await this.kpiPeriodRepository.findOne({
|
||||
where: { id: requestBody.kpiPeriodId },
|
||||
});
|
||||
if (!kpiPeriod) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตัวชี้วัดตามตำแหน่งนี้");
|
||||
}
|
||||
}
|
||||
await new CallAPI()
|
||||
.PostData(request, "org/find/all", {
|
||||
node: requestBody.node,
|
||||
|
|
@ -93,6 +103,14 @@ export class kpiRoleController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตัวชี้วัดตามตำแหน่งนี้");
|
||||
}
|
||||
|
||||
if (requestBody.kpiPeriodId != null) {
|
||||
const kpiPeriod = await this.kpiPeriodRepository.findOne({
|
||||
where: { id: requestBody.kpiPeriodId },
|
||||
});
|
||||
if (!kpiPeriod) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตัวชี้วัดตามตำแหน่งนี้");
|
||||
}
|
||||
}
|
||||
Object.assign(kpiRole, requestBody);
|
||||
await new CallAPI()
|
||||
.PostData(request, "org/find/all", {
|
||||
|
|
@ -133,6 +151,7 @@ export class kpiRoleController extends Controller {
|
|||
async GetKpiRoleById(@Path() id: string) {
|
||||
const kpiRole = await this.kpiRoleRepository.findOne({
|
||||
where: { id: id },
|
||||
relations: { kpiPeriod: true },
|
||||
});
|
||||
if (!kpiRole) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตัวชี้วัดตามตำแหน่งนี้");
|
||||
|
|
@ -157,8 +176,9 @@ export class kpiRoleController extends Controller {
|
|||
}
|
||||
const formattedData = {
|
||||
id: kpiRole.id,
|
||||
year: kpiRole.year,
|
||||
// round: kpiRole.round,
|
||||
year: kpiRole.kpiPeriod == null ? null : kpiRole.kpiPeriod.year,
|
||||
round: kpiRole.kpiPeriod == null ? null : kpiRole.kpiPeriod.durationKPI,
|
||||
kpiPeriodId: kpiRole.kpiPeriodId,
|
||||
including: kpiRole.including,
|
||||
includingName: kpiRole.includingName,
|
||||
target: kpiRole.target,
|
||||
|
|
@ -214,9 +234,11 @@ export class kpiRoleController extends Controller {
|
|||
},
|
||||
)
|
||||
.andWhere(
|
||||
round != undefined && round != null && round != "" ? "kpiRole.round LIKE :round" : "1=1",
|
||||
round != undefined && round != null && round != ""
|
||||
? "kpiRole.kpiPeriod LIKE :round"
|
||||
: "1=1",
|
||||
{
|
||||
round: `${round?.trim().toUpperCase()}`,
|
||||
round: `${round}`,
|
||||
},
|
||||
)
|
||||
.andWhere(position != undefined ? "kpiRole.position LIKE :position" : "1=1", {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue