diff --git a/src/controllers/DevelopmentHistoryController.ts b/src/controllers/DevelopmentHistoryController.ts index 564e9e0..c9ca194 100644 --- a/src/controllers/DevelopmentHistoryController.ts +++ b/src/controllers/DevelopmentHistoryController.ts @@ -24,7 +24,7 @@ import { UpdateDevelopmentHistory, } from "../entities/DevelopmentHistory"; -@Route("api/v1/development/history") +@Route("api/v1/development/history/officer") @Tags("DevelopmentHistory") @Security("bearerAuth") export class DevelopmentHistoryController extends Controller { @@ -37,18 +37,17 @@ export class DevelopmentHistoryController extends Controller { * @summary DEV_006 - เพิ่มประวัติการฝึกอบรม/ดูงาน#6 * */ - @Post("{type}") + @Post() async CreateDevelopmentHistory( - @Path() type: string, @Body() requestBody: CreateDevelopmentHistory, @Request() request: { user: Record }, ) { - const _type = type.trim().toUpperCase(); + const type = "OFFICER"; const chk_name = await this.developmentHistoryRepository.find({ where: { citizenId: requestBody.citizenId, developmentId: requestBody.developmentId, - type: _type, + type: type, }, }); if (chk_name.length > 0) { @@ -63,7 +62,7 @@ export class DevelopmentHistoryController extends Controller { } const development = Object.assign(new DevelopmentHistory(), requestBody); - development.type = _type; + development.type = type; development.createdUserId = request.user.sub; development.createdFullName = request.user.name; development.lastUpdateUserId = request.user.sub; @@ -79,16 +78,15 @@ export class DevelopmentHistoryController extends Controller { * * @param {string} id Id โครงการ */ - @Put("{type}/{id}") + @Put("{id}") async UpdateDevelopmentHistory( - @Path() type: string, @Path() id: string, @Body() requestBody: UpdateDevelopmentHistory, @Request() request: { user: Record }, ) { - const _type = type.trim().toUpperCase(); + const type = "OFFICER"; const development = await this.developmentHistoryRepository.findOne({ - where: { id: id, type: _type }, + where: { id: id, type: type }, }); if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัติการฝึกอบรม/ดูงานนี้"); @@ -97,7 +95,7 @@ export class DevelopmentHistoryController extends Controller { where: { citizenId: requestBody.citizenId, developmentId: requestBody.developmentId, - type: _type, + type: type, id: Not(id), }, }); @@ -111,7 +109,7 @@ export class DevelopmentHistoryController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรม"); } Object.assign(development, requestBody); - development.type = _type; + development.type = type; development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; await this.developmentHistoryRepository.save(development); @@ -125,11 +123,11 @@ export class DevelopmentHistoryController extends Controller { * * @param {string} id Id โครงการ */ - @Delete("{type}/{id}") - async DeleteDevelopmentHistory(@Path() type: string, @Path() id: string) { - const _type = type.trim().toUpperCase(); + @Delete("{id}") + async DeleteDevelopmentHistory(@Path() id: string) { + const type = "OFFICER"; const development = await this.developmentHistoryRepository.findOne({ - where: { id: id, type: _type }, + where: { id: id, type: type }, }); if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัติการฝึกอบรม/ดูงานนี้"); @@ -145,15 +143,14 @@ export class DevelopmentHistoryController extends Controller { * @summary DEV_009 - รายการประวัติการฝึกอบรม/ดูงาน #9 * */ - @Get("{type}") + @Get() async GetDevelopmentHistoryLists( - @Path() type: string, @Query("page") page: number = 1, @Query("pageSize") pageSize: number = 10, @Query("keyword") keyword?: string, @Query("year") year?: number, ) { - const _type = type.trim().toUpperCase(); + const type = "OFFICER"; const [development, total] = await AppDataSource.getRepository(DevelopmentHistory) .createQueryBuilder("developmentHistory") // .andWhere(year == null ? "developmentHistory.year LIKE :year" : "1=1", { year: `${year}` }) @@ -175,11 +172,11 @@ export class DevelopmentHistoryController extends Controller { * * @param {string} id Id โครงการ */ - @Get("{type}/{id}") - async GetDevelopemtHistoryById(@Path() type: string, @Path() id: string) { - const _type = type.trim().toUpperCase(); + @Get("{id}") + async GetDevelopemtHistoryById(@Path() id: string) { + const type = "OFFICER"; const getDevelopment = await this.developmentHistoryRepository.findOne({ - where: { id: id, type: _type }, + where: { id: id, type: type }, }); if (!getDevelopment) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัติการฝึกอบรม/ดูงานนี้"); diff --git a/src/migration/1712119650901-add_table_developmentHistory2.ts b/src/migration/1712119650901-add_table_developmentHistory2.ts new file mode 100644 index 0000000..c7dc6d5 --- /dev/null +++ b/src/migration/1712119650901-add_table_developmentHistory2.ts @@ -0,0 +1,14 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AddTableDevelopmentHistory21712119650901 implements MigrationInterface { + name = 'AddTableDevelopmentHistory21712119650901' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentHistory\` ADD \`type\` varchar(40) NULL COMMENT 'ประเภทราชการ'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentHistory\` DROP COLUMN \`type\``); + } + +}