ประวัติโครงการลูกจ้่าง

This commit is contained in:
Kittapath 2024-04-03 11:28:08 +07:00
parent c2af2a3b08
commit a5ee4afd06
2 changed files with 30 additions and 11 deletions

View file

@ -37,15 +37,18 @@ export class DevelopmentHistoryController extends Controller {
* @summary DEV_006 - /#6 * @summary DEV_006 - /#6
* *
*/ */
@Post() @Post("{type}")
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 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,
}, },
}); });
if (chk_name.length > 0) { if (chk_name.length > 0) {
@ -60,7 +63,7 @@ export class DevelopmentHistoryController extends Controller {
} }
const development = Object.assign(new DevelopmentHistory(), requestBody); const development = Object.assign(new DevelopmentHistory(), requestBody);
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;
@ -76,14 +79,16 @@ export class DevelopmentHistoryController extends Controller {
* *
* @param {string} id Id * @param {string} id Id
*/ */
@Put("{id}") @Put("{type}/{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 development = await this.developmentHistoryRepository.findOne({ const development = await this.developmentHistoryRepository.findOne({
where: { id }, where: { id: id, type: _type },
}); });
if (!development) { if (!development) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัติการฝึกอบรม/ดูงานนี้"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัติการฝึกอบรม/ดูงานนี้");
@ -92,6 +97,7 @@ export class DevelopmentHistoryController extends Controller {
where: { where: {
citizenId: requestBody.citizenId, citizenId: requestBody.citizenId,
developmentId: requestBody.developmentId, developmentId: requestBody.developmentId,
type: _type,
id: Not(id), id: Not(id),
}, },
}); });
@ -105,6 +111,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.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);
@ -118,10 +125,11 @@ export class DevelopmentHistoryController extends Controller {
* *
* @param {string} id Id * @param {string} id Id
*/ */
@Delete("{id}") @Delete("{type}/{id}")
async DeleteDevelopmentHistory(@Path() id: string) { async DeleteDevelopmentHistory(@Path() type: string, @Path() id: string) {
const _type = type.trim().toUpperCase();
const development = await this.developmentHistoryRepository.findOne({ const development = await this.developmentHistoryRepository.findOne({
where: { id }, where: { id: id, type: _type },
}); });
if (!development) { if (!development) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัติการฝึกอบรม/ดูงานนี้"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัติการฝึกอบรม/ดูงานนี้");
@ -137,13 +145,15 @@ export class DevelopmentHistoryController extends Controller {
* @summary DEV_009 - / #9 * @summary DEV_009 - / #9
* *
*/ */
@Get() @Get("{type}")
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 [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}` })
@ -165,10 +175,11 @@ export class DevelopmentHistoryController extends Controller {
* *
* @param {string} id Id * @param {string} id Id
*/ */
@Get("{id}") @Get("{type}/{id}")
async GetDevelopemtHistoryById(@Path() id: string) { async GetDevelopemtHistoryById(@Path() type: string, @Path() id: string) {
const _type = type.trim().toUpperCase();
const getDevelopment = await this.developmentHistoryRepository.findOne({ const getDevelopment = await this.developmentHistoryRepository.findOne({
where: { id: id }, where: { id: id, type: _type },
}); });
if (!getDevelopment) { if (!getDevelopment) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัติการฝึกอบรม/ดูงานนี้"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัติการฝึกอบรม/ดูงานนี้");

View file

@ -6,6 +6,14 @@ import { Development } from "./Development";
@Entity("developmentHistory") @Entity("developmentHistory")
export class DevelopmentHistory extends EntityBase { export class DevelopmentHistory extends EntityBase {
@Column({
nullable: true,
comment: "ประเภทราชการ",
length: 40,
default: null,
})
type: string;
@Column({ @Column({
nullable: true, nullable: true,
comment: "ยศ", comment: "ยศ",