ประวัติราชการ
This commit is contained in:
parent
a5ee4afd06
commit
e9732a1e52
2 changed files with 34 additions and 23 deletions
|
|
@ -24,7 +24,7 @@ import {
|
||||||
UpdateDevelopmentHistory,
|
UpdateDevelopmentHistory,
|
||||||
} from "../entities/DevelopmentHistory";
|
} from "../entities/DevelopmentHistory";
|
||||||
|
|
||||||
@Route("api/v1/development/history")
|
@Route("api/v1/development/history/officer")
|
||||||
@Tags("DevelopmentHistory")
|
@Tags("DevelopmentHistory")
|
||||||
@Security("bearerAuth")
|
@Security("bearerAuth")
|
||||||
export class DevelopmentHistoryController extends Controller {
|
export class DevelopmentHistoryController extends Controller {
|
||||||
|
|
@ -37,18 +37,17 @@ export class DevelopmentHistoryController extends Controller {
|
||||||
* @summary DEV_006 - เพิ่มประวัติการฝึกอบรม/ดูงาน#6
|
* @summary DEV_006 - เพิ่มประวัติการฝึกอบรม/ดูงาน#6
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Post("{type}")
|
@Post()
|
||||||
async CreateDevelopmentHistory(
|
async CreateDevelopmentHistory(
|
||||||
@Path() type: string,
|
|
||||||
@Body() requestBody: CreateDevelopmentHistory,
|
@Body() requestBody: CreateDevelopmentHistory,
|
||||||
@Request() request: { user: Record<string, any> },
|
@Request() request: { user: Record<string, any> },
|
||||||
) {
|
) {
|
||||||
const _type = type.trim().toUpperCase();
|
const type = "OFFICER";
|
||||||
const chk_name = await this.developmentHistoryRepository.find({
|
const chk_name = await this.developmentHistoryRepository.find({
|
||||||
where: {
|
where: {
|
||||||
citizenId: requestBody.citizenId,
|
citizenId: requestBody.citizenId,
|
||||||
developmentId: requestBody.developmentId,
|
developmentId: requestBody.developmentId,
|
||||||
type: _type,
|
type: type,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (chk_name.length > 0) {
|
if (chk_name.length > 0) {
|
||||||
|
|
@ -63,7 +62,7 @@ export class DevelopmentHistoryController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
const development = Object.assign(new DevelopmentHistory(), requestBody);
|
const development = Object.assign(new DevelopmentHistory(), requestBody);
|
||||||
development.type = _type;
|
development.type = type;
|
||||||
development.createdUserId = request.user.sub;
|
development.createdUserId = request.user.sub;
|
||||||
development.createdFullName = request.user.name;
|
development.createdFullName = request.user.name;
|
||||||
development.lastUpdateUserId = request.user.sub;
|
development.lastUpdateUserId = request.user.sub;
|
||||||
|
|
@ -79,16 +78,15 @@ export class DevelopmentHistoryController extends Controller {
|
||||||
*
|
*
|
||||||
* @param {string} id Id โครงการ
|
* @param {string} id Id โครงการ
|
||||||
*/
|
*/
|
||||||
@Put("{type}/{id}")
|
@Put("{id}")
|
||||||
async UpdateDevelopmentHistory(
|
async UpdateDevelopmentHistory(
|
||||||
@Path() type: string,
|
|
||||||
@Path() id: string,
|
@Path() id: string,
|
||||||
@Body() requestBody: UpdateDevelopmentHistory,
|
@Body() requestBody: UpdateDevelopmentHistory,
|
||||||
@Request() request: { user: Record<string, any> },
|
@Request() request: { user: Record<string, any> },
|
||||||
) {
|
) {
|
||||||
const _type = type.trim().toUpperCase();
|
const type = "OFFICER";
|
||||||
const development = await this.developmentHistoryRepository.findOne({
|
const development = await this.developmentHistoryRepository.findOne({
|
||||||
where: { id: id, type: _type },
|
where: { id: id, type: type },
|
||||||
});
|
});
|
||||||
if (!development) {
|
if (!development) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัติการฝึกอบรม/ดูงานนี้");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัติการฝึกอบรม/ดูงานนี้");
|
||||||
|
|
@ -97,7 +95,7 @@ export class DevelopmentHistoryController extends Controller {
|
||||||
where: {
|
where: {
|
||||||
citizenId: requestBody.citizenId,
|
citizenId: requestBody.citizenId,
|
||||||
developmentId: requestBody.developmentId,
|
developmentId: requestBody.developmentId,
|
||||||
type: _type,
|
type: type,
|
||||||
id: Not(id),
|
id: Not(id),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
@ -111,7 +109,7 @@ export class DevelopmentHistoryController extends Controller {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรม");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรม");
|
||||||
}
|
}
|
||||||
Object.assign(development, requestBody);
|
Object.assign(development, requestBody);
|
||||||
development.type = _type;
|
development.type = type;
|
||||||
development.lastUpdateUserId = request.user.sub;
|
development.lastUpdateUserId = request.user.sub;
|
||||||
development.lastUpdateFullName = request.user.name;
|
development.lastUpdateFullName = request.user.name;
|
||||||
await this.developmentHistoryRepository.save(development);
|
await this.developmentHistoryRepository.save(development);
|
||||||
|
|
@ -125,11 +123,11 @@ export class DevelopmentHistoryController extends Controller {
|
||||||
*
|
*
|
||||||
* @param {string} id Id โครงการ
|
* @param {string} id Id โครงการ
|
||||||
*/
|
*/
|
||||||
@Delete("{type}/{id}")
|
@Delete("{id}")
|
||||||
async DeleteDevelopmentHistory(@Path() type: string, @Path() id: string) {
|
async DeleteDevelopmentHistory(@Path() id: string) {
|
||||||
const _type = type.trim().toUpperCase();
|
const type = "OFFICER";
|
||||||
const development = await this.developmentHistoryRepository.findOne({
|
const development = await this.developmentHistoryRepository.findOne({
|
||||||
where: { id: id, type: _type },
|
where: { id: id, type: type },
|
||||||
});
|
});
|
||||||
if (!development) {
|
if (!development) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัติการฝึกอบรม/ดูงานนี้");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัติการฝึกอบรม/ดูงานนี้");
|
||||||
|
|
@ -145,15 +143,14 @@ export class DevelopmentHistoryController extends Controller {
|
||||||
* @summary DEV_009 - รายการประวัติการฝึกอบรม/ดูงาน #9
|
* @summary DEV_009 - รายการประวัติการฝึกอบรม/ดูงาน #9
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Get("{type}")
|
@Get()
|
||||||
async GetDevelopmentHistoryLists(
|
async GetDevelopmentHistoryLists(
|
||||||
@Path() type: string,
|
|
||||||
@Query("page") page: number = 1,
|
@Query("page") page: number = 1,
|
||||||
@Query("pageSize") pageSize: number = 10,
|
@Query("pageSize") pageSize: number = 10,
|
||||||
@Query("keyword") keyword?: string,
|
@Query("keyword") keyword?: string,
|
||||||
@Query("year") year?: number,
|
@Query("year") year?: number,
|
||||||
) {
|
) {
|
||||||
const _type = type.trim().toUpperCase();
|
const type = "OFFICER";
|
||||||
const [development, total] = await AppDataSource.getRepository(DevelopmentHistory)
|
const [development, total] = await AppDataSource.getRepository(DevelopmentHistory)
|
||||||
.createQueryBuilder("developmentHistory")
|
.createQueryBuilder("developmentHistory")
|
||||||
// .andWhere(year == null ? "developmentHistory.year LIKE :year" : "1=1", { year: `${year}` })
|
// .andWhere(year == null ? "developmentHistory.year LIKE :year" : "1=1", { year: `${year}` })
|
||||||
|
|
@ -175,11 +172,11 @@ export class DevelopmentHistoryController extends Controller {
|
||||||
*
|
*
|
||||||
* @param {string} id Id โครงการ
|
* @param {string} id Id โครงการ
|
||||||
*/
|
*/
|
||||||
@Get("{type}/{id}")
|
@Get("{id}")
|
||||||
async GetDevelopemtHistoryById(@Path() type: string, @Path() id: string) {
|
async GetDevelopemtHistoryById(@Path() id: string) {
|
||||||
const _type = type.trim().toUpperCase();
|
const type = "OFFICER";
|
||||||
const getDevelopment = await this.developmentHistoryRepository.findOne({
|
const getDevelopment = await this.developmentHistoryRepository.findOne({
|
||||||
where: { id: id, type: _type },
|
where: { id: id, type: type },
|
||||||
});
|
});
|
||||||
if (!getDevelopment) {
|
if (!getDevelopment) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัติการฝึกอบรม/ดูงานนี้");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัติการฝึกอบรม/ดูงานนี้");
|
||||||
|
|
|
||||||
14
src/migration/1712119650901-add_table_developmentHistory2.ts
Normal file
14
src/migration/1712119650901-add_table_developmentHistory2.ts
Normal 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\``);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue