เพิ่มประวัติลูกจ้าง

This commit is contained in:
Kittapath 2024-04-03 12:07:57 +07:00
parent e9732a1e52
commit 44022b311f
6 changed files with 316 additions and 2 deletions

View file

@ -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;