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([
|
||||
|
|
|
|||
|
|
@ -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", {
|
||||
|
|
|
|||
|
|
@ -5,12 +5,6 @@ import { KpiPeriod } from "./kpiPeriod";
|
|||
|
||||
@Entity("kpiPlan")
|
||||
export class KpiPlan extends EntityBase {
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "ปีงบประมาณ",
|
||||
})
|
||||
year: number;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "รหัสตัวชี้วัด",
|
||||
|
|
@ -295,8 +289,6 @@ export class KpiPlan extends EntityBase {
|
|||
kpiPeriod: KpiPeriod;
|
||||
}
|
||||
export class createKpiPlan {
|
||||
@Column()
|
||||
year: number | null;
|
||||
@Column()
|
||||
including: string | null;
|
||||
@Column()
|
||||
|
|
@ -336,8 +328,6 @@ export class createKpiPlan {
|
|||
}
|
||||
|
||||
export class updateKpiPlan {
|
||||
@Column()
|
||||
year: number | null;
|
||||
@Column()
|
||||
including: string | null;
|
||||
@Column()
|
||||
|
|
|
|||
|
|
@ -12,12 +12,6 @@ export class KpiRole extends EntityBase {
|
|||
})
|
||||
position: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "ปีงบประมาณ",
|
||||
})
|
||||
year: number;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "รหัสตัวชี้วัด",
|
||||
|
|
@ -230,8 +224,6 @@ export class createKpiRole {
|
|||
@Column()
|
||||
position: string | null;
|
||||
@Column()
|
||||
year: number | null;
|
||||
@Column()
|
||||
including: string | null;
|
||||
@Column()
|
||||
includingName: string | null;
|
||||
|
|
@ -269,8 +261,6 @@ export class updateKpiRole {
|
|||
@Column()
|
||||
position: string | null;
|
||||
@Column()
|
||||
year: number | null;
|
||||
@Column()
|
||||
including: string | null;
|
||||
@Column()
|
||||
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