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 { KpiPlan, createKpiPlan, updateKpiPlan } from "../entities/kpiPlan";
|
||||
import CallAPI from "../interfaces/call-api";
|
||||
import { KpiPeriod } from "../entities/kpiPeriod";
|
||||
|
||||
@Route("api/v1/kpi/plan")
|
||||
@Tags("kpiPlan")
|
||||
|
|
@ -32,6 +33,7 @@ import CallAPI from "../interfaces/call-api";
|
|||
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||
export class kpiPlanController extends Controller {
|
||||
private kpiPlanRepository = AppDataSource.getRepository(KpiPlan);
|
||||
private kpiPeriodRepository = AppDataSource.getRepository(KpiPeriod);
|
||||
/**
|
||||
* สร้างตัวชี้วัดตามแผนฯ
|
||||
* @param requestBody
|
||||
|
|
@ -43,6 +45,14 @@ export class kpiPlanController extends Controller {
|
|||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
const kpiPlan = Object.assign(new KpiPlan(), 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,
|
||||
|
|
@ -112,6 +122,14 @@ export class kpiPlanController 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(kpiPlan, requestBody);
|
||||
await new CallAPI()
|
||||
.PostData(request, "org/find/all", {
|
||||
|
|
@ -170,6 +188,7 @@ export class kpiPlanController extends Controller {
|
|||
async GetKpiPlanById(@Path() id: string) {
|
||||
const kpiPlan = await this.kpiPlanRepository.findOne({
|
||||
where: { id: id },
|
||||
relations: { kpiPeriod: true },
|
||||
});
|
||||
if (!kpiPlan) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตัวชี้วัดตามแผนฯนี้");
|
||||
|
|
@ -212,8 +231,9 @@ export class kpiPlanController extends Controller {
|
|||
}
|
||||
const formattedData = {
|
||||
id: kpiPlan.id,
|
||||
year: kpiPlan.year,
|
||||
// round: kpiPlan.round,
|
||||
year: kpiPlan.kpiPeriod == null ? null : kpiPlan.kpiPeriod.year,
|
||||
round: kpiPlan.kpiPeriod == null ? null : kpiPlan.kpiPeriod.durationKPI,
|
||||
kpiPeriodId: kpiPlan.kpiPeriodId,
|
||||
including: kpiPlan.including,
|
||||
includingName: kpiPlan.includingName,
|
||||
target: kpiPlan.target,
|
||||
|
|
@ -269,9 +289,11 @@ export class kpiPlanController extends Controller {
|
|||
},
|
||||
)
|
||||
.andWhere(
|
||||
round != undefined && round != null && round != "" ? "kpiPlan.round LIKE :round" : "1=1",
|
||||
round != undefined && round != null && round != ""
|
||||
? "kpiPlan.kpiPeriodId LIKE :round"
|
||||
: "1=1",
|
||||
{
|
||||
round: `${round?.trim().toUpperCase()}`,
|
||||
round: `${round}`,
|
||||
},
|
||||
)
|
||||
.select([
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue