ประวัติราชการ

This commit is contained in:
Kittapath 2024-04-03 11:48:06 +07:00
parent a5ee4afd06
commit e9732a1e52
2 changed files with 34 additions and 23 deletions

View file

@ -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<string, any> },
) {
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<string, any> },
) {
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, "ไม่พบข้อมูลประวัติการฝึกอบรม/ดูงานนี้");

View file

@ -0,0 +1,14 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class AddTableDevelopmentHistory21712119650901 implements MigrationInterface {
name = 'AddTableDevelopmentHistory21712119650901'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`developmentHistory\` ADD \`type\` varchar(40) NULL COMMENT 'ประเภทราชการ'`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`developmentHistory\` DROP COLUMN \`type\``);
}
}