เพิ่มประวัติลูกจ้าง
This commit is contained in:
parent
e9732a1e52
commit
44022b311f
6 changed files with 316 additions and 2 deletions
226
src/controllers/DevelopmentEmployeeHistoryController.ts
Normal file
226
src/controllers/DevelopmentEmployeeHistoryController.ts
Normal file
|
|
@ -0,0 +1,226 @@
|
|||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Put,
|
||||
Delete,
|
||||
Route,
|
||||
Security,
|
||||
Tags,
|
||||
Body,
|
||||
Path,
|
||||
Request,
|
||||
Query,
|
||||
} from "tsoa";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import { Not } from "typeorm";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import HttpStatusCode from "../interfaces/http-status";
|
||||
import { Development } from "../entities/Development";
|
||||
import {
|
||||
CreateDevelopmentHistory,
|
||||
DevelopmentHistory,
|
||||
UpdateDevelopmentHistory,
|
||||
} from "../entities/DevelopmentHistory";
|
||||
import { EmployeePosType } from "../entities/EmployeePosType";
|
||||
import { EmployeePosLevel } from "../entities/EmployeePosLevel";
|
||||
|
||||
@Route("api/v1/development/history/employee")
|
||||
@Tags("DevelopmentEmployeeHistory")
|
||||
@Security("bearerAuth")
|
||||
export class DevelopmentHistoryController extends Controller {
|
||||
private developmentHistoryRepository = AppDataSource.getRepository(DevelopmentHistory);
|
||||
private developmentRepository = AppDataSource.getRepository(Development);
|
||||
private posTypeRepository = AppDataSource.getRepository(EmployeePosType);
|
||||
private posLevelRepository = AppDataSource.getRepository(EmployeePosLevel);
|
||||
|
||||
/**
|
||||
* API เพิ่มประวัติการฝึกอบรม/ดูงาน
|
||||
*
|
||||
* @summary DEV_006 - เพิ่มประวัติการฝึกอบรม/ดูงาน#6
|
||||
*
|
||||
*/
|
||||
@Post()
|
||||
async CreateDevelopmentHistory(
|
||||
@Body() requestBody: CreateDevelopmentHistory,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
const type = "EMPLOYEE";
|
||||
const chk_name = await this.developmentHistoryRepository.find({
|
||||
where: {
|
||||
citizenId: requestBody.citizenId,
|
||||
developmentId: requestBody.developmentId,
|
||||
type: type,
|
||||
},
|
||||
});
|
||||
if (chk_name.length > 0) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประวัติการฝึกอบรม/ดูงาน มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
|
||||
const checkId = await this.developmentRepository.findOne({
|
||||
where: { id: requestBody.developmentId },
|
||||
});
|
||||
if (!checkId) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรม");
|
||||
}
|
||||
if (requestBody.posTypeId != null) {
|
||||
const checkId = await this.posTypeRepository.findOne({
|
||||
where: { id: requestBody.posTypeId },
|
||||
});
|
||||
if (!checkId) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง");
|
||||
}
|
||||
}
|
||||
if (requestBody.posLevelId != null) {
|
||||
const checkId = await this.posLevelRepository.findOne({
|
||||
where: { id: requestBody.posLevelId },
|
||||
});
|
||||
if (!checkId) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง");
|
||||
}
|
||||
}
|
||||
|
||||
const development = Object.assign(new DevelopmentHistory(), requestBody);
|
||||
development.type = type;
|
||||
development.employeePosTypeId = requestBody.posTypeId;
|
||||
development.employeePosLevelId = requestBody.posLevelId;
|
||||
development.createdUserId = request.user.sub;
|
||||
development.createdFullName = request.user.name;
|
||||
development.lastUpdateUserId = request.user.sub;
|
||||
development.lastUpdateFullName = request.user.name;
|
||||
await this.developmentHistoryRepository.save(development);
|
||||
return new HttpSuccess(development.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* API แก้ไขประวัติการฝึกอบรม/ดูงาน
|
||||
*
|
||||
* @summary DEV_007 - แก้ไขประวัติการฝึกอบรม/ดูงาน #7
|
||||
*
|
||||
* @param {string} id Id โครงการ
|
||||
*/
|
||||
@Put("{id}")
|
||||
async UpdateDevelopmentHistory(
|
||||
@Path() id: string,
|
||||
@Body() requestBody: UpdateDevelopmentHistory,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
const type = "EMPLOYEE";
|
||||
const development = await this.developmentHistoryRepository.findOne({
|
||||
where: { id: id, type: type },
|
||||
});
|
||||
if (!development) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัติการฝึกอบรม/ดูงานนี้");
|
||||
}
|
||||
const chk_name = await this.developmentHistoryRepository.find({
|
||||
where: {
|
||||
citizenId: requestBody.citizenId,
|
||||
developmentId: requestBody.developmentId,
|
||||
type: type,
|
||||
id: Not(id),
|
||||
},
|
||||
});
|
||||
if (chk_name.length > 0) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประวัติการฝึกอบรม/ดูงาน มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
const checkId = await this.developmentRepository.findOne({
|
||||
where: { id: requestBody.developmentId },
|
||||
});
|
||||
if (!checkId) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรม");
|
||||
}
|
||||
if (requestBody.posTypeId != null) {
|
||||
const checkId = await this.posTypeRepository.findOne({
|
||||
where: { id: requestBody.posTypeId },
|
||||
});
|
||||
if (!checkId) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง");
|
||||
}
|
||||
}
|
||||
if (requestBody.posLevelId != null) {
|
||||
const checkId = await this.posLevelRepository.findOne({
|
||||
where: { id: requestBody.posLevelId },
|
||||
});
|
||||
if (!checkId) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง");
|
||||
}
|
||||
}
|
||||
Object.assign(development, requestBody);
|
||||
development.type = type;
|
||||
development.employeePosTypeId = requestBody.posTypeId;
|
||||
development.employeePosLevelId = requestBody.posLevelId;
|
||||
development.lastUpdateUserId = request.user.sub;
|
||||
development.lastUpdateFullName = request.user.name;
|
||||
await this.developmentHistoryRepository.save(development);
|
||||
return new HttpSuccess(development.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* API ลบประวัติการฝึกอบรม/ดูงาน
|
||||
*
|
||||
* @summary DEV_008 - ลบประวัติการฝึกอบรม/ดูงาน #8
|
||||
*
|
||||
* @param {string} id Id โครงการ
|
||||
*/
|
||||
@Delete("{id}")
|
||||
async DeleteDevelopmentHistory(@Path() id: string) {
|
||||
const type = "EMPLOYEE";
|
||||
const development = await this.developmentHistoryRepository.findOne({
|
||||
where: { id: id, type: type },
|
||||
});
|
||||
if (!development) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัติการฝึกอบรม/ดูงานนี้");
|
||||
}
|
||||
|
||||
await this.developmentHistoryRepository.remove(development);
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* API รายการประวัติการฝึกอบรม/ดูงาน
|
||||
*
|
||||
* @summary DEV_009 - รายการประวัติการฝึกอบรม/ดูงาน #9
|
||||
*
|
||||
*/
|
||||
@Get()
|
||||
async GetDevelopmentHistoryLists(
|
||||
@Query("page") page: number = 1,
|
||||
@Query("pageSize") pageSize: number = 10,
|
||||
@Query("keyword") keyword?: string,
|
||||
@Query("year") year?: number,
|
||||
) {
|
||||
const type = "EMPLOYEE";
|
||||
const [development, total] = await AppDataSource.getRepository(DevelopmentHistory)
|
||||
.createQueryBuilder("developmentHistory")
|
||||
// .andWhere(year == null ? "developmentHistory.year LIKE :year" : "1=1", { year: `${year}` })
|
||||
// .orWhere("developmentHistory.projectName LIKE :keyword", { keyword: `${keyword}` })
|
||||
// .select(["development.id", "development.projectName", "development.year"])
|
||||
// .orderBy("developmentHistory.year", "DESC")
|
||||
.orderBy("developmentHistory.createdAt", "DESC")
|
||||
.skip((page - 1) * pageSize)
|
||||
.take(pageSize)
|
||||
.getManyAndCount();
|
||||
|
||||
return new HttpSuccess({ data: development, total });
|
||||
}
|
||||
|
||||
/**
|
||||
* API รายละเอียดประวัติการฝึกอบรม/ดูงาน
|
||||
*
|
||||
* @summary DEV_010 - รายละเอียดประวัติการฝึกอบรม/ดูงาน #10
|
||||
*
|
||||
* @param {string} id Id โครงการ
|
||||
*/
|
||||
@Get("{id}")
|
||||
async GetDevelopemtHistoryById(@Path() id: string) {
|
||||
const type = "EMPLOYEE";
|
||||
const getDevelopment = await this.developmentHistoryRepository.findOne({
|
||||
where: { id: id, type: type },
|
||||
});
|
||||
if (!getDevelopment) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัติการฝึกอบรม/ดูงานนี้");
|
||||
}
|
||||
return new HttpSuccess(getDevelopment);
|
||||
}
|
||||
}
|
||||
|
|
@ -23,13 +23,17 @@ import {
|
|||
DevelopmentHistory,
|
||||
UpdateDevelopmentHistory,
|
||||
} from "../entities/DevelopmentHistory";
|
||||
import { PosType } from "../entities/PosType";
|
||||
import { PosLevel } from "../entities/PosLevel";
|
||||
|
||||
@Route("api/v1/development/history/officer")
|
||||
@Tags("DevelopmentHistory")
|
||||
@Tags("DevelopmentOfficerHistory")
|
||||
@Security("bearerAuth")
|
||||
export class DevelopmentHistoryController extends Controller {
|
||||
private developmentHistoryRepository = AppDataSource.getRepository(DevelopmentHistory);
|
||||
private developmentRepository = AppDataSource.getRepository(Development);
|
||||
private posTypeRepository = AppDataSource.getRepository(PosType);
|
||||
private posLevelRepository = AppDataSource.getRepository(PosLevel);
|
||||
|
||||
/**
|
||||
* API เพิ่มประวัติการฝึกอบรม/ดูงาน
|
||||
|
|
@ -60,6 +64,22 @@ export class DevelopmentHistoryController extends Controller {
|
|||
if (!checkId) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรม");
|
||||
}
|
||||
if (requestBody.posTypeId != null) {
|
||||
const checkId = await this.posTypeRepository.findOne({
|
||||
where: { id: requestBody.posTypeId },
|
||||
});
|
||||
if (!checkId) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง");
|
||||
}
|
||||
}
|
||||
if (requestBody.posLevelId != null) {
|
||||
const checkId = await this.posLevelRepository.findOne({
|
||||
where: { id: requestBody.posLevelId },
|
||||
});
|
||||
if (!checkId) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง");
|
||||
}
|
||||
}
|
||||
|
||||
const development = Object.assign(new DevelopmentHistory(), requestBody);
|
||||
development.type = type;
|
||||
|
|
@ -108,6 +128,22 @@ export class DevelopmentHistoryController extends Controller {
|
|||
if (!checkId) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรม");
|
||||
}
|
||||
if (requestBody.posTypeId != null) {
|
||||
const checkId = await this.posTypeRepository.findOne({
|
||||
where: { id: requestBody.posTypeId },
|
||||
});
|
||||
if (!checkId) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง");
|
||||
}
|
||||
}
|
||||
if (requestBody.posLevelId != null) {
|
||||
const checkId = await this.posLevelRepository.findOne({
|
||||
where: { id: requestBody.posLevelId },
|
||||
});
|
||||
if (!checkId) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง");
|
||||
}
|
||||
}
|
||||
Object.assign(development, requestBody);
|
||||
development.type = type;
|
||||
development.lastUpdateUserId = request.user.sub;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ import { EntityBase } from "./base/Base";
|
|||
import { PosLevel } from "./PosLevel";
|
||||
import { PosType } from "./PosType";
|
||||
import { Development } from "./Development";
|
||||
import { EmployeePosType } from "./EmployeePosType";
|
||||
import { EmployeePosLevel } from "./EmployeePosLevel";
|
||||
|
||||
@Entity("developmentHistory")
|
||||
export class DevelopmentHistory extends EntityBase {
|
||||
|
|
@ -84,6 +86,28 @@ export class DevelopmentHistory extends EntityBase {
|
|||
@JoinColumn({ name: "posTypeId" })
|
||||
posType: PosType;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
length: 40,
|
||||
comment: "ไอดีระดับตำแหน่ง",
|
||||
})
|
||||
employeePosLevelId: string | null;
|
||||
|
||||
@ManyToOne(() => EmployeePosLevel, (employeePosLevel) => employeePosLevel.developmentHistorys)
|
||||
@JoinColumn({ name: "employeePosLevelId" })
|
||||
employeePosLevel: EmployeePosLevel;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
length: 40,
|
||||
comment: "ไอดีประเภทตำแหน่ง",
|
||||
})
|
||||
employeePosTypeId: string | null;
|
||||
|
||||
@ManyToOne(() => EmployeePosType, (employeePosType) => employeePosType.developmentHistorys)
|
||||
@JoinColumn({ name: "employeePosTypeId" })
|
||||
employeePosType: EmployeePosType;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "โครงการ/หลักสูตรการฝึกอบรม",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { Entity, Column, ManyToOne, JoinColumn } from "typeorm";
|
||||
import { Entity, Column, ManyToOne, JoinColumn, OneToMany } from "typeorm";
|
||||
import { EntityBase } from "./base/Base";
|
||||
import { EmployeePosType } from "./EmployeePosType";
|
||||
import { DevelopmentHistory } from "./DevelopmentHistory";
|
||||
|
||||
enum EmployeePosLevelAuthoritys {
|
||||
HEAD = "HEAD",
|
||||
|
|
@ -40,6 +41,9 @@ export class EmployeePosLevel extends EntityBase {
|
|||
@ManyToOne(() => EmployeePosType, (posType: EmployeePosType) => posType.posLevels)
|
||||
@JoinColumn({ name: "posTypeId" })
|
||||
posType: EmployeePosType;
|
||||
|
||||
@OneToMany(() => DevelopmentHistory, (developmentHistory) => developmentHistory.employeePosLevel)
|
||||
developmentHistorys: DevelopmentHistory[];
|
||||
}
|
||||
|
||||
export class CreateEmployeePosLevel {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { Entity, Column, OneToMany } from "typeorm";
|
||||
import { EntityBase } from "./base/Base";
|
||||
import { EmployeePosLevel } from "./EmployeePosLevel";
|
||||
import { DevelopmentHistory } from "./DevelopmentHistory";
|
||||
|
||||
@Entity("employeePosType")
|
||||
export class EmployeePosType extends EntityBase {
|
||||
|
|
@ -27,6 +28,9 @@ export class EmployeePosType extends EntityBase {
|
|||
|
||||
@OneToMany(() => EmployeePosLevel, (posLevel: EmployeePosLevel) => posLevel.posType)
|
||||
posLevels: EmployeePosLevel[];
|
||||
|
||||
@OneToMany(() => DevelopmentHistory, (developmentHistory) => developmentHistory.employeePosType)
|
||||
developmentHistorys: DevelopmentHistory[];
|
||||
}
|
||||
|
||||
export class CreateEmployeePosType {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class UpdateTableDevelopmentHistoryAddType1712120794817 implements MigrationInterface {
|
||||
name = 'UpdateTableDevelopmentHistoryAddType1712120794817'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`developmentHistory\` ADD \`employeePosLevelId\` varchar(40) NULL COMMENT 'ไอดีระดับตำแหน่ง'`);
|
||||
await queryRunner.query(`ALTER TABLE \`developmentHistory\` ADD \`employeePosTypeId\` varchar(40) NULL COMMENT 'ไอดีประเภทตำแหน่ง'`);
|
||||
await queryRunner.query(`ALTER TABLE \`developmentHistory\` ADD CONSTRAINT \`FK_a905f077069e27d2fc9bb8f5f5c\` FOREIGN KEY (\`employeePosLevelId\`) REFERENCES \`employeePosLevel\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
|
||||
await queryRunner.query(`ALTER TABLE \`developmentHistory\` ADD CONSTRAINT \`FK_25dd3134b725bb2ec455872374f\` FOREIGN KEY (\`employeePosTypeId\`) REFERENCES \`employeePosType\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`developmentHistory\` DROP FOREIGN KEY \`FK_25dd3134b725bb2ec455872374f\``);
|
||||
await queryRunner.query(`ALTER TABLE \`developmentHistory\` DROP FOREIGN KEY \`FK_a905f077069e27d2fc9bb8f5f5c\``);
|
||||
await queryRunner.query(`ALTER TABLE \`developmentHistory\` DROP COLUMN \`employeePosTypeId\``);
|
||||
await queryRunner.query(`ALTER TABLE \`developmentHistory\` DROP COLUMN \`employeePosLevelId\``);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue