ประวัติโครงการลูกจ้่าง
This commit is contained in:
parent
c2af2a3b08
commit
a5ee4afd06
2 changed files with 30 additions and 11 deletions
|
|
@ -37,15 +37,18 @@ export class DevelopmentHistoryController extends Controller {
|
|||
* @summary DEV_006 - เพิ่มประวัติการฝึกอบรม/ดูงาน#6
|
||||
*
|
||||
*/
|
||||
@Post()
|
||||
@Post("{type}")
|
||||
async CreateDevelopmentHistory(
|
||||
@Path() type: string,
|
||||
@Body() requestBody: CreateDevelopmentHistory,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
const _type = type.trim().toUpperCase();
|
||||
const chk_name = await this.developmentHistoryRepository.find({
|
||||
where: {
|
||||
citizenId: requestBody.citizenId,
|
||||
developmentId: requestBody.developmentId,
|
||||
type: _type,
|
||||
},
|
||||
});
|
||||
if (chk_name.length > 0) {
|
||||
|
|
@ -60,7 +63,7 @@ export class DevelopmentHistoryController extends Controller {
|
|||
}
|
||||
|
||||
const development = Object.assign(new DevelopmentHistory(), requestBody);
|
||||
|
||||
development.type = _type;
|
||||
development.createdUserId = request.user.sub;
|
||||
development.createdFullName = request.user.name;
|
||||
development.lastUpdateUserId = request.user.sub;
|
||||
|
|
@ -76,14 +79,16 @@ export class DevelopmentHistoryController extends Controller {
|
|||
*
|
||||
* @param {string} id Id โครงการ
|
||||
*/
|
||||
@Put("{id}")
|
||||
@Put("{type}/{id}")
|
||||
async UpdateDevelopmentHistory(
|
||||
@Path() type: string,
|
||||
@Path() id: string,
|
||||
@Body() requestBody: UpdateDevelopmentHistory,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
const _type = type.trim().toUpperCase();
|
||||
const development = await this.developmentHistoryRepository.findOne({
|
||||
where: { id },
|
||||
where: { id: id, type: _type },
|
||||
});
|
||||
if (!development) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัติการฝึกอบรม/ดูงานนี้");
|
||||
|
|
@ -92,6 +97,7 @@ export class DevelopmentHistoryController extends Controller {
|
|||
where: {
|
||||
citizenId: requestBody.citizenId,
|
||||
developmentId: requestBody.developmentId,
|
||||
type: _type,
|
||||
id: Not(id),
|
||||
},
|
||||
});
|
||||
|
|
@ -105,6 +111,7 @@ export class DevelopmentHistoryController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรม");
|
||||
}
|
||||
Object.assign(development, requestBody);
|
||||
development.type = _type;
|
||||
development.lastUpdateUserId = request.user.sub;
|
||||
development.lastUpdateFullName = request.user.name;
|
||||
await this.developmentHistoryRepository.save(development);
|
||||
|
|
@ -118,10 +125,11 @@ export class DevelopmentHistoryController extends Controller {
|
|||
*
|
||||
* @param {string} id Id โครงการ
|
||||
*/
|
||||
@Delete("{id}")
|
||||
async DeleteDevelopmentHistory(@Path() id: string) {
|
||||
@Delete("{type}/{id}")
|
||||
async DeleteDevelopmentHistory(@Path() type: string, @Path() id: string) {
|
||||
const _type = type.trim().toUpperCase();
|
||||
const development = await this.developmentHistoryRepository.findOne({
|
||||
where: { id },
|
||||
where: { id: id, type: _type },
|
||||
});
|
||||
if (!development) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัติการฝึกอบรม/ดูงานนี้");
|
||||
|
|
@ -137,13 +145,15 @@ export class DevelopmentHistoryController extends Controller {
|
|||
* @summary DEV_009 - รายการประวัติการฝึกอบรม/ดูงาน #9
|
||||
*
|
||||
*/
|
||||
@Get()
|
||||
@Get("{type}")
|
||||
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 [development, total] = await AppDataSource.getRepository(DevelopmentHistory)
|
||||
.createQueryBuilder("developmentHistory")
|
||||
// .andWhere(year == null ? "developmentHistory.year LIKE :year" : "1=1", { year: `${year}` })
|
||||
|
|
@ -165,10 +175,11 @@ export class DevelopmentHistoryController extends Controller {
|
|||
*
|
||||
* @param {string} id Id โครงการ
|
||||
*/
|
||||
@Get("{id}")
|
||||
async GetDevelopemtHistoryById(@Path() id: string) {
|
||||
@Get("{type}/{id}")
|
||||
async GetDevelopemtHistoryById(@Path() type: string, @Path() id: string) {
|
||||
const _type = type.trim().toUpperCase();
|
||||
const getDevelopment = await this.developmentHistoryRepository.findOne({
|
||||
where: { id: id },
|
||||
where: { id: id, type: _type },
|
||||
});
|
||||
if (!getDevelopment) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัติการฝึกอบรม/ดูงานนี้");
|
||||
|
|
|
|||
|
|
@ -6,6 +6,14 @@ import { Development } from "./Development";
|
|||
|
||||
@Entity("developmentHistory")
|
||||
export class DevelopmentHistory extends EntityBase {
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "ประเภทราชการ",
|
||||
length: 40,
|
||||
default: null,
|
||||
})
|
||||
type: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "ยศ",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue