kpi period
This commit is contained in:
parent
5e223c86fb
commit
4914a0d733
3 changed files with 213 additions and 0 deletions
153
src/controllers/KpiPeriodController.ts
Normal file
153
src/controllers/KpiPeriodController.ts
Normal file
|
|
@ -0,0 +1,153 @@
|
||||||
|
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 { KpiPeriod, createKpi, updateKpi } from "../entities/kpi";
|
||||||
|
|
||||||
|
@Route("api/v1/kpi/period")
|
||||||
|
@Tags("kpi")
|
||||||
|
@Security("bearerAuth")
|
||||||
|
@Response(
|
||||||
|
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||||
|
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
|
||||||
|
)
|
||||||
|
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||||
|
export class kpiController extends Controller {
|
||||||
|
private kpiRepository = AppDataSource.getRepository(KpiPeriod);
|
||||||
|
/**
|
||||||
|
* สร้างรอบการประเมินผลการปฏิบัติหน้าที่ราชการ
|
||||||
|
* @param requestBody
|
||||||
|
* @param request
|
||||||
|
*/
|
||||||
|
@Post()
|
||||||
|
@Example({
|
||||||
|
durationKPI: "string", //รอบเดือนที่สร้าง
|
||||||
|
startDate: "datetime", //วันเริ่มต้น
|
||||||
|
endDate: "datetime", //วันสิ้นสุด
|
||||||
|
})
|
||||||
|
async createKpi(
|
||||||
|
@Body() requestBody: createKpi,
|
||||||
|
@Request() request: { user: Record<string, any> },
|
||||||
|
) {
|
||||||
|
const kpi = Object.assign(new KpiPeriod(), requestBody);
|
||||||
|
kpi.durationKPI = requestBody.durationKPI.trim().toUpperCase();
|
||||||
|
kpi.createdUserId = request.user.sub;
|
||||||
|
kpi.createdFullName = request.user.name;
|
||||||
|
kpi.lastUpdateUserId = request.user.sub;
|
||||||
|
kpi.lastUpdateFullName = request.user.name;
|
||||||
|
await this.kpiRepository.save(kpi);
|
||||||
|
return new HttpSuccess(kpi.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API แก้ไขรอบการประเมินผลการปฏิบัติหน้าที่ราชการ
|
||||||
|
* @param id
|
||||||
|
* @param requestBody
|
||||||
|
* @param request
|
||||||
|
*/
|
||||||
|
@Put("{id}")
|
||||||
|
async update_kpi(
|
||||||
|
@Path() id: string,
|
||||||
|
@Body() requestBody: updateKpi,
|
||||||
|
@Request() request: { user: Record<string, any> },
|
||||||
|
) {
|
||||||
|
const kpi_update = await this.kpiRepository.findOne({
|
||||||
|
where: { id: id },
|
||||||
|
});
|
||||||
|
if (!kpi_update) {
|
||||||
|
throw new HttpError(
|
||||||
|
HttpStatusCode.NOT_FOUND,
|
||||||
|
"ไม่พบข้อมูลรอบการประเมินผลการปฏิบัติหน้าที่ราชการนี้",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
requestBody.durationKPI = requestBody.durationKPI.trim().toUpperCase();
|
||||||
|
this.kpiRepository.merge(kpi_update, requestBody);
|
||||||
|
kpi_update.createdUserId = request.user.sub;
|
||||||
|
kpi_update.createdFullName = request.user.name;
|
||||||
|
kpi_update.lastUpdateUserId = request.user.sub;
|
||||||
|
kpi_update.lastUpdateFullName = request.user.name;
|
||||||
|
await this.kpiRepository.save(kpi_update);
|
||||||
|
return new HttpSuccess(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API รอบการประเมินผลการปฏิบัติหน้าที่ราชการ
|
||||||
|
* @param id Guid, *Id รอบการประเมินผลการปฏิบัติหน้าที่ราชการ
|
||||||
|
*/
|
||||||
|
@Get("{id}")
|
||||||
|
@Example({
|
||||||
|
durationKPI: "string", //รอบเดือนที่สร้าง
|
||||||
|
startDate: "datetime", //วันเริ่มต้น
|
||||||
|
endDate: "datetime", //วันสิ้นสุด
|
||||||
|
})
|
||||||
|
async GetSalaryById(@Path() id: string) {
|
||||||
|
const kpi = await this.kpiRepository.findOne({
|
||||||
|
where: { id: id },
|
||||||
|
select: ["durationKPI", "startDate", "endDate"],
|
||||||
|
});
|
||||||
|
if (!kpi) {
|
||||||
|
throw new HttpError(
|
||||||
|
HttpStatusCode.NOT_FOUND,
|
||||||
|
"ไม่พบข้อมูลรอบการประเมินผลการปฏิบัติหน้าที่ราชการนี้",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return new HttpSuccess(kpi);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API list รอบการประเมินผลการปฏิบัติหน้าที่ราชการ
|
||||||
|
* @param page
|
||||||
|
* @param pageSize
|
||||||
|
* @param keyword
|
||||||
|
*/
|
||||||
|
@Get()
|
||||||
|
async listKpiPeriod(
|
||||||
|
@Query("page") page: number = 1,
|
||||||
|
@Query("pageSize") pageSize: number = 10,
|
||||||
|
@Query("keyword") keyword?: string,
|
||||||
|
) {
|
||||||
|
const [kpiPeriod, total] = await this.kpiRepository.findAndCount({
|
||||||
|
...(keyword ? {} : { skip: (page - 1) * pageSize, take: pageSize }),
|
||||||
|
});
|
||||||
|
|
||||||
|
return new HttpSuccess({ data: kpiPeriod, total });
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API ลบรอบการประเมินผลการปฏิบัติหน้าที่ราชการ
|
||||||
|
* @param id
|
||||||
|
*/
|
||||||
|
@Delete("{id}")
|
||||||
|
async delete_salary(@Path() id: string) {
|
||||||
|
const chk_KpiPeriod = await this.kpiRepository.findOne({
|
||||||
|
where: { id: id },
|
||||||
|
});
|
||||||
|
if (!chk_KpiPeriod) {
|
||||||
|
throw new HttpError(
|
||||||
|
HttpStatusCode.NOT_FOUND,
|
||||||
|
"ไม่พบข้อมูลรอบการประเมินผลการปฏิบัติหน้าที่ราชการนี้",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.kpiRepository.remove(chk_KpiPeriod);
|
||||||
|
return new HttpSuccess();
|
||||||
|
}
|
||||||
|
}
|
||||||
45
src/entities/kpi.ts
Normal file
45
src/entities/kpi.ts
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
import { Entity, Column } from "typeorm";
|
||||||
|
import { EntityBase } from "./base/Base";
|
||||||
|
|
||||||
|
@Entity("kpiPeriod")
|
||||||
|
export class KpiPeriod extends EntityBase {
|
||||||
|
@Column({
|
||||||
|
nullable: true,
|
||||||
|
comment: "รอบการประเมิน",
|
||||||
|
default: null,
|
||||||
|
})
|
||||||
|
durationKPI: string;
|
||||||
|
|
||||||
|
@Column({
|
||||||
|
nullable: true,
|
||||||
|
type: "datetime",
|
||||||
|
comment: "วันเริ่มต้น",
|
||||||
|
default: null,
|
||||||
|
})
|
||||||
|
startDate: Date;
|
||||||
|
|
||||||
|
@Column({
|
||||||
|
nullable: true,
|
||||||
|
type: "datetime",
|
||||||
|
comment: "วันสิ้นสุด",
|
||||||
|
default: null,
|
||||||
|
})
|
||||||
|
endDate: Date;
|
||||||
|
}
|
||||||
|
export class createKpi {
|
||||||
|
@Column()
|
||||||
|
durationKPI: string;
|
||||||
|
@Column()
|
||||||
|
startDate: Date;
|
||||||
|
@Column()
|
||||||
|
endDate: Date;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class updateKpi {
|
||||||
|
@Column()
|
||||||
|
durationKPI: string;
|
||||||
|
@Column()
|
||||||
|
startDate: Date;
|
||||||
|
@Column()
|
||||||
|
endDate: Date;
|
||||||
|
}
|
||||||
15
src/migration/1712285860812-add_table_kpiperiod.ts
Normal file
15
src/migration/1712285860812-add_table_kpiperiod.ts
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||||
|
|
||||||
|
export class AddTableKpiperiod1712285860812 implements MigrationInterface {
|
||||||
|
name = "AddTableKpiperiod1712285860812";
|
||||||
|
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(
|
||||||
|
`CREATE TABLE \`kpiPeriod\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`durationKPI\` varchar(255) NULL COMMENT 'รอบการประเมิน', \`startDate\` datetime NULL COMMENT 'วันเริ่มต้น', \`endDate\` datetime NULL COMMENT 'วันสิ้นสุด', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`DROP TABLE \`kpiPeriod\``);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue