ระดับชั้นงานลูกจ้างประจำ
This commit is contained in:
parent
bc394f503c
commit
af8e2667f3
3 changed files with 207 additions and 1 deletions
190
src/controllers/EmployeePosLevelController.ts
Normal file
190
src/controllers/EmployeePosLevelController.ts
Normal file
|
|
@ -0,0 +1,190 @@
|
|||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Put,
|
||||
Delete,
|
||||
Route,
|
||||
Security,
|
||||
Tags,
|
||||
Body,
|
||||
Path,
|
||||
Request,
|
||||
SuccessResponse,
|
||||
Response,
|
||||
} from "tsoa";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpStatusCode from "../interfaces/http-status";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import { Not } from "typeorm";
|
||||
import { EmployeePosType,} from "../entities/EmployeePosType";
|
||||
import { EmployeePosLevel, CreateEmployeePosLevel, UpdateEmployeePosLevel } from "../entities/EmployeePosLevel";
|
||||
import { EmployeePosDict } from "../entities/EmployeePosDict";
|
||||
|
||||
@Route("api/v1/org/employee/pos/level")
|
||||
@Tags("EmployeePosLevel")
|
||||
@Security("bearerAuth")
|
||||
@Response(
|
||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
|
||||
)
|
||||
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||
export class EmployeePosLevelController extends Controller {
|
||||
|
||||
private employeePosDictRepository = AppDataSource.getRepository(EmployeePosDict);
|
||||
private employeePosTypeRepository = AppDataSource.getRepository(EmployeePosType);
|
||||
private employeePosLevelRepository = AppDataSource.getRepository(EmployeePosLevel);
|
||||
|
||||
/**
|
||||
* API เพิ่มระดับชั้นงานลูกจ้างประจำ
|
||||
*
|
||||
* @summary ORG_ - เพิ่มระดับชั้นงานลูกจ้างประจำ (ADMIN) #
|
||||
*
|
||||
*/
|
||||
@Post()
|
||||
async CreateEmpLevel(
|
||||
@Body()
|
||||
requestBody: CreateEmployeePosLevel,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
const EmpPosLevel = Object.assign(new EmployeePosLevel(), requestBody);
|
||||
if (!EmpPosLevel) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
const EmpPosType = await this.employeePosTypeRepository.findOne({
|
||||
where: { id: requestBody.employeePosTypeId }
|
||||
});
|
||||
if (!EmpPosType) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทกลุ่มงานลูกจ้างประจำนี้");
|
||||
}
|
||||
|
||||
const chkEmpPosLevelName = await this.employeePosLevelRepository.findOne({
|
||||
where: {
|
||||
posLevelName: requestBody.posLevelName,
|
||||
},
|
||||
});
|
||||
if (chkEmpPosLevelName) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ชื่อระดับชั้นงานลูกจ้างประจำนี้มีอยู่ในระบบแล้ว",
|
||||
);
|
||||
}
|
||||
|
||||
EmpPosLevel.createdUserId = request.user.sub;
|
||||
EmpPosLevel.createdFullName = request.user.name;
|
||||
EmpPosLevel.lastUpdateUserId = request.user.sub;
|
||||
EmpPosLevel.lastUpdateFullName = request.user.name;
|
||||
await this.employeePosLevelRepository.save(EmpPosLevel);
|
||||
return new HttpSuccess(EmpPosLevel.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* API แก้ไขระดับชั้นงานลูกจ้างประจำ
|
||||
*
|
||||
* @summary ORG_ - แก้ไขระดับชั้นงานลูกจ้างประจำ (ADMIN) #
|
||||
*
|
||||
* @param {string} id Id ระดับชั้นงานลูกจ้างประจำ
|
||||
*/
|
||||
@Put("{id}")
|
||||
async EditEmpLevel(
|
||||
@Path() id: string,
|
||||
@Body() requestBody: UpdateEmployeePosLevel,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
const EmpPosLevel = await this.employeePosLevelRepository.findOne({ where: { id } });
|
||||
if (!EmpPosLevel) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับชั้นงานลูกจ้างประจำนี้");
|
||||
}
|
||||
|
||||
const EmpPosType = await this.employeePosTypeRepository.findOne({
|
||||
where: { id: requestBody.employeePosTypeId }
|
||||
});
|
||||
if (!EmpPosType) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทกลุ่มงานลูกจ้างประจำนี้");
|
||||
}
|
||||
|
||||
const chkEmpPosLevel = await this.employeePosLevelRepository.findOne({
|
||||
where: {
|
||||
id: Not(id),
|
||||
posLevelName: requestBody.posLevelName,
|
||||
},
|
||||
});
|
||||
if (chkEmpPosLevel) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ชื่อระดับชั้นงานลูกจ้างประจำนี้มีอยู่ในระบบแล้ว",
|
||||
);
|
||||
}
|
||||
EmpPosLevel.lastUpdateUserId = request.user.sub;
|
||||
EmpPosLevel.lastUpdateFullName = request.user.name;
|
||||
this.employeePosLevelRepository.merge(EmpPosLevel, requestBody);
|
||||
await this.employeePosLevelRepository.save(EmpPosLevel);
|
||||
return new HttpSuccess(EmpPosLevel.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* API ลบระดับชั้นงานลูกจ้างประจำ
|
||||
*
|
||||
* @summary ORG_ - ลบระดับชั้นงานลูกจ้างประจำ (ADMIN) #
|
||||
*
|
||||
* @param {string} id Id ระดับชั้นงานลูกจ้างประจำ
|
||||
*/
|
||||
@Delete("{id}")
|
||||
async deleteType(@Path() id: string) {
|
||||
const delEmpPosLevel = await this.employeePosLevelRepository.findOne({ where: { id } });
|
||||
if (!delEmpPosLevel) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับชั้นงานลูกจ้างประจำนี้");
|
||||
}
|
||||
|
||||
//ตารางตำแหน่งลูกจ้างประจำ
|
||||
const EmpPosition = await this.employeePosDictRepository.find({
|
||||
where: { employeePosLevelId: id },
|
||||
});
|
||||
if (EmpPosition.length > 0) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ไม่สามารถลบได้เนื่องจากพบข้อมูลที่ตารางตำแหน่งลูกจ้างประจำ",
|
||||
);
|
||||
}
|
||||
|
||||
await this.employeePosLevelRepository.remove(delEmpPosLevel);
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* API รายละเอียดระดับชั้นงานลูกจ้างประจำ
|
||||
*
|
||||
* @summary ORG_ - รายละเอียดระดับชั้นงานลูกจ้างประจำ (ADMIN) #
|
||||
*
|
||||
* @param {string} id Id ระดับชั้นงานลูกจ้างประจำ
|
||||
*/
|
||||
@Get("{id}")
|
||||
async GetEmpLevelById(@Path() id: string) {
|
||||
const getEmpPosLevel = await this.employeePosLevelRepository.findOne({
|
||||
select: ["id", "posLevelName", "posLevelRank",],
|
||||
where: { id: id },
|
||||
});
|
||||
if (!getEmpPosLevel) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับชั้นงานลูกจ้างประจำนี้");
|
||||
}
|
||||
|
||||
return new HttpSuccess(getEmpPosLevel);
|
||||
}
|
||||
|
||||
/**
|
||||
* API รายการระดับชั้นงานลูกจ้างประจำ
|
||||
*
|
||||
* @summary ORG_ - รายการระดับชั้นงานลูกจ้างประจำ (ADMIN) #
|
||||
*
|
||||
*/
|
||||
@Get()
|
||||
async GetEmpPosLevel() {
|
||||
const empPosLevel = await this.employeePosLevelRepository.find({
|
||||
select: ["id","posLevelName", "posLevelRank",],
|
||||
});
|
||||
|
||||
return new HttpSuccess(empPosLevel);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue