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 HttpStatusCode from "../interfaces/http-status";
|
||||||
import { KpiPlan, createKpiPlan, updateKpiPlan } from "../entities/kpiPlan";
|
import { KpiPlan, createKpiPlan, updateKpiPlan } from "../entities/kpiPlan";
|
||||||
import CallAPI from "../interfaces/call-api";
|
import CallAPI from "../interfaces/call-api";
|
||||||
|
import { KpiPeriod } from "../entities/kpiPeriod";
|
||||||
|
|
||||||
@Route("api/v1/kpi/plan")
|
@Route("api/v1/kpi/plan")
|
||||||
@Tags("kpiPlan")
|
@Tags("kpiPlan")
|
||||||
|
|
@ -32,6 +33,7 @@ import CallAPI from "../interfaces/call-api";
|
||||||
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||||
export class kpiPlanController extends Controller {
|
export class kpiPlanController extends Controller {
|
||||||
private kpiPlanRepository = AppDataSource.getRepository(KpiPlan);
|
private kpiPlanRepository = AppDataSource.getRepository(KpiPlan);
|
||||||
|
private kpiPeriodRepository = AppDataSource.getRepository(KpiPeriod);
|
||||||
/**
|
/**
|
||||||
* สร้างตัวชี้วัดตามแผนฯ
|
* สร้างตัวชี้วัดตามแผนฯ
|
||||||
* @param requestBody
|
* @param requestBody
|
||||||
|
|
@ -43,6 +45,14 @@ export class kpiPlanController extends Controller {
|
||||||
@Request() request: { user: Record<string, any> },
|
@Request() request: { user: Record<string, any> },
|
||||||
) {
|
) {
|
||||||
const kpiPlan = Object.assign(new KpiPlan(), requestBody);
|
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()
|
await new CallAPI()
|
||||||
.PostData(request, "org/find/all", {
|
.PostData(request, "org/find/all", {
|
||||||
node: requestBody.node,
|
node: requestBody.node,
|
||||||
|
|
@ -112,6 +122,14 @@ export class kpiPlanController extends Controller {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตัวชี้วัดตามแผนฯนี้");
|
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);
|
Object.assign(kpiPlan, requestBody);
|
||||||
await new CallAPI()
|
await new CallAPI()
|
||||||
.PostData(request, "org/find/all", {
|
.PostData(request, "org/find/all", {
|
||||||
|
|
@ -170,6 +188,7 @@ export class kpiPlanController extends Controller {
|
||||||
async GetKpiPlanById(@Path() id: string) {
|
async GetKpiPlanById(@Path() id: string) {
|
||||||
const kpiPlan = await this.kpiPlanRepository.findOne({
|
const kpiPlan = await this.kpiPlanRepository.findOne({
|
||||||
where: { id: id },
|
where: { id: id },
|
||||||
|
relations: { kpiPeriod: true },
|
||||||
});
|
});
|
||||||
if (!kpiPlan) {
|
if (!kpiPlan) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตัวชี้วัดตามแผนฯนี้");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตัวชี้วัดตามแผนฯนี้");
|
||||||
|
|
@ -212,8 +231,9 @@ export class kpiPlanController extends Controller {
|
||||||
}
|
}
|
||||||
const formattedData = {
|
const formattedData = {
|
||||||
id: kpiPlan.id,
|
id: kpiPlan.id,
|
||||||
year: kpiPlan.year,
|
year: kpiPlan.kpiPeriod == null ? null : kpiPlan.kpiPeriod.year,
|
||||||
// round: kpiPlan.round,
|
round: kpiPlan.kpiPeriod == null ? null : kpiPlan.kpiPeriod.durationKPI,
|
||||||
|
kpiPeriodId: kpiPlan.kpiPeriodId,
|
||||||
including: kpiPlan.including,
|
including: kpiPlan.including,
|
||||||
includingName: kpiPlan.includingName,
|
includingName: kpiPlan.includingName,
|
||||||
target: kpiPlan.target,
|
target: kpiPlan.target,
|
||||||
|
|
@ -269,9 +289,11 @@ export class kpiPlanController extends Controller {
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.andWhere(
|
.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([
|
.select([
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ import HttpError from "../interfaces/http-error";
|
||||||
import HttpStatusCode from "../interfaces/http-status";
|
import HttpStatusCode from "../interfaces/http-status";
|
||||||
import { KpiRole, createKpiRole, updateKpiRole } from "../entities/kpiRole";
|
import { KpiRole, createKpiRole, updateKpiRole } from "../entities/kpiRole";
|
||||||
import CallAPI from "../interfaces/call-api";
|
import CallAPI from "../interfaces/call-api";
|
||||||
|
import { KpiPeriod } from "../entities/kpiPeriod";
|
||||||
|
|
||||||
@Route("api/v1/kpi/role")
|
@Route("api/v1/kpi/role")
|
||||||
@Tags("kpiRole")
|
@Tags("kpiRole")
|
||||||
|
|
@ -32,6 +33,7 @@ import CallAPI from "../interfaces/call-api";
|
||||||
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||||
export class kpiRoleController extends Controller {
|
export class kpiRoleController extends Controller {
|
||||||
private kpiRoleRepository = AppDataSource.getRepository(KpiRole);
|
private kpiRoleRepository = AppDataSource.getRepository(KpiRole);
|
||||||
|
private kpiPeriodRepository = AppDataSource.getRepository(KpiPeriod);
|
||||||
/**
|
/**
|
||||||
* สร้างตัวชี้วัดตามตำแหน่ง
|
* สร้างตัวชี้วัดตามตำแหน่ง
|
||||||
* @param requestBody
|
* @param requestBody
|
||||||
|
|
@ -43,6 +45,14 @@ export class kpiRoleController extends Controller {
|
||||||
@Request() request: { user: Record<string, any> },
|
@Request() request: { user: Record<string, any> },
|
||||||
) {
|
) {
|
||||||
const kpiRole = Object.assign(new KpiRole(), requestBody);
|
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()
|
await new CallAPI()
|
||||||
.PostData(request, "org/find/all", {
|
.PostData(request, "org/find/all", {
|
||||||
node: requestBody.node,
|
node: requestBody.node,
|
||||||
|
|
@ -93,6 +103,14 @@ export class kpiRoleController extends Controller {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตัวชี้วัดตามตำแหน่งนี้");
|
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);
|
Object.assign(kpiRole, requestBody);
|
||||||
await new CallAPI()
|
await new CallAPI()
|
||||||
.PostData(request, "org/find/all", {
|
.PostData(request, "org/find/all", {
|
||||||
|
|
@ -133,6 +151,7 @@ export class kpiRoleController extends Controller {
|
||||||
async GetKpiRoleById(@Path() id: string) {
|
async GetKpiRoleById(@Path() id: string) {
|
||||||
const kpiRole = await this.kpiRoleRepository.findOne({
|
const kpiRole = await this.kpiRoleRepository.findOne({
|
||||||
where: { id: id },
|
where: { id: id },
|
||||||
|
relations: { kpiPeriod: true },
|
||||||
});
|
});
|
||||||
if (!kpiRole) {
|
if (!kpiRole) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตัวชี้วัดตามตำแหน่งนี้");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตัวชี้วัดตามตำแหน่งนี้");
|
||||||
|
|
@ -157,8 +176,9 @@ export class kpiRoleController extends Controller {
|
||||||
}
|
}
|
||||||
const formattedData = {
|
const formattedData = {
|
||||||
id: kpiRole.id,
|
id: kpiRole.id,
|
||||||
year: kpiRole.year,
|
year: kpiRole.kpiPeriod == null ? null : kpiRole.kpiPeriod.year,
|
||||||
// round: kpiRole.round,
|
round: kpiRole.kpiPeriod == null ? null : kpiRole.kpiPeriod.durationKPI,
|
||||||
|
kpiPeriodId: kpiRole.kpiPeriodId,
|
||||||
including: kpiRole.including,
|
including: kpiRole.including,
|
||||||
includingName: kpiRole.includingName,
|
includingName: kpiRole.includingName,
|
||||||
target: kpiRole.target,
|
target: kpiRole.target,
|
||||||
|
|
@ -214,9 +234,11 @@ export class kpiRoleController extends Controller {
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.andWhere(
|
.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", {
|
.andWhere(position != undefined ? "kpiRole.position LIKE :position" : "1=1", {
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,6 @@ import { KpiPeriod } from "./kpiPeriod";
|
||||||
|
|
||||||
@Entity("kpiPlan")
|
@Entity("kpiPlan")
|
||||||
export class KpiPlan extends EntityBase {
|
export class KpiPlan extends EntityBase {
|
||||||
@Column({
|
|
||||||
nullable: true,
|
|
||||||
comment: "ปีงบประมาณ",
|
|
||||||
})
|
|
||||||
year: number;
|
|
||||||
|
|
||||||
@Column({
|
@Column({
|
||||||
nullable: true,
|
nullable: true,
|
||||||
comment: "รหัสตัวชี้วัด",
|
comment: "รหัสตัวชี้วัด",
|
||||||
|
|
@ -295,8 +289,6 @@ export class KpiPlan extends EntityBase {
|
||||||
kpiPeriod: KpiPeriod;
|
kpiPeriod: KpiPeriod;
|
||||||
}
|
}
|
||||||
export class createKpiPlan {
|
export class createKpiPlan {
|
||||||
@Column()
|
|
||||||
year: number | null;
|
|
||||||
@Column()
|
@Column()
|
||||||
including: string | null;
|
including: string | null;
|
||||||
@Column()
|
@Column()
|
||||||
|
|
@ -336,8 +328,6 @@ export class createKpiPlan {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class updateKpiPlan {
|
export class updateKpiPlan {
|
||||||
@Column()
|
|
||||||
year: number | null;
|
|
||||||
@Column()
|
@Column()
|
||||||
including: string | null;
|
including: string | null;
|
||||||
@Column()
|
@Column()
|
||||||
|
|
|
||||||
|
|
@ -12,12 +12,6 @@ export class KpiRole extends EntityBase {
|
||||||
})
|
})
|
||||||
position: string;
|
position: string;
|
||||||
|
|
||||||
@Column({
|
|
||||||
nullable: true,
|
|
||||||
comment: "ปีงบประมาณ",
|
|
||||||
})
|
|
||||||
year: number;
|
|
||||||
|
|
||||||
@Column({
|
@Column({
|
||||||
nullable: true,
|
nullable: true,
|
||||||
comment: "รหัสตัวชี้วัด",
|
comment: "รหัสตัวชี้วัด",
|
||||||
|
|
@ -230,8 +224,6 @@ export class createKpiRole {
|
||||||
@Column()
|
@Column()
|
||||||
position: string | null;
|
position: string | null;
|
||||||
@Column()
|
@Column()
|
||||||
year: number | null;
|
|
||||||
@Column()
|
|
||||||
including: string | null;
|
including: string | null;
|
||||||
@Column()
|
@Column()
|
||||||
includingName: string | null;
|
includingName: string | null;
|
||||||
|
|
@ -269,8 +261,6 @@ export class updateKpiRole {
|
||||||
@Column()
|
@Column()
|
||||||
position: string | null;
|
position: string | null;
|
||||||
@Column()
|
@Column()
|
||||||
year: number | null;
|
|
||||||
@Column()
|
|
||||||
including: string | null;
|
including: string | null;
|
||||||
@Column()
|
@Column()
|
||||||
includingName: string | null;
|
includingName: string | null;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||||
|
|
||||||
|
export class UpdateTableKpiPlanAddKpiPeriod1713523478564 implements MigrationInterface {
|
||||||
|
name = 'UpdateTableKpiPlanAddKpiPeriod1713523478564'
|
||||||
|
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`ALTER TABLE \`kpiPlan\` DROP COLUMN \`round\``);
|
||||||
|
await queryRunner.query(`ALTER TABLE \`kpiPlan\` DROP COLUMN \`year\``);
|
||||||
|
await queryRunner.query(`ALTER TABLE \`kpiRole\` DROP COLUMN \`round\``);
|
||||||
|
await queryRunner.query(`ALTER TABLE \`kpiRole\` DROP COLUMN \`year\``);
|
||||||
|
await queryRunner.query(`ALTER TABLE \`kpiPlan\` ADD \`kpiPeriodId\` varchar(40) NULL COMMENT 'ไอดีรอบ'`);
|
||||||
|
await queryRunner.query(`ALTER TABLE \`kpiRole\` ADD \`kpiPeriodId\` varchar(40) NULL COMMENT 'ไอดีรอบ'`);
|
||||||
|
await queryRunner.query(`ALTER TABLE \`kpiPlan\` ADD CONSTRAINT \`FK_7e2320c78b8ae3a68ac771ea369\` FOREIGN KEY (\`kpiPeriodId\`) REFERENCES \`kpiPeriod\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
|
||||||
|
await queryRunner.query(`ALTER TABLE \`kpiRole\` ADD CONSTRAINT \`FK_6959e3ae543841bd5808bc58f22\` FOREIGN KEY (\`kpiPeriodId\`) REFERENCES \`kpiPeriod\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`ALTER TABLE \`kpiRole\` DROP FOREIGN KEY \`FK_6959e3ae543841bd5808bc58f22\``);
|
||||||
|
await queryRunner.query(`ALTER TABLE \`kpiPlan\` DROP FOREIGN KEY \`FK_7e2320c78b8ae3a68ac771ea369\``);
|
||||||
|
await queryRunner.query(`ALTER TABLE \`kpiRole\` DROP COLUMN \`kpiPeriodId\``);
|
||||||
|
await queryRunner.query(`ALTER TABLE \`kpiPlan\` DROP COLUMN \`kpiPeriodId\``);
|
||||||
|
await queryRunner.query(`ALTER TABLE \`kpiRole\` ADD \`year\` int NULL COMMENT 'ปีงบประมาณ'`);
|
||||||
|
await queryRunner.query(`ALTER TABLE \`kpiRole\` ADD \`round\` varchar(255) NULL COMMENT 'รอบการประเมิน'`);
|
||||||
|
await queryRunner.query(`ALTER TABLE \`kpiPlan\` ADD \`year\` int NULL COMMENT 'ปีงบประมาณ'`);
|
||||||
|
await queryRunner.query(`ALTER TABLE \`kpiPlan\` ADD \`round\` varchar(255) NULL COMMENT 'รอบการประเมิน'`);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue