API สร้างผังเงินเดือน
This commit is contained in:
parent
637a7b9605
commit
90e1050ad7
2 changed files with 111 additions and 4 deletions
107
src/controllers/SalaryController.ts
Normal file
107
src/controllers/SalaryController.ts
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Put,
|
||||
Delete,
|
||||
Patch,
|
||||
Route,
|
||||
Security,
|
||||
Tags,
|
||||
Body,
|
||||
Path,
|
||||
Request,
|
||||
Example,
|
||||
} from "tsoa";
|
||||
import { Salarys, CreateSalary, UpdateSalary } from "../entities/Salarys";
|
||||
import { PosType } from "../entities/PosType";
|
||||
import { PosLevel } from "../entities/PosLevel";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import { In, IsNull, Not } from "typeorm";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import HttpStatusCode from "../interfaces/http-status";
|
||||
|
||||
@Route("api/v1/salary")
|
||||
@Tags("Salary")
|
||||
@Security("bearerAuth")
|
||||
export class Salary extends Controller {
|
||||
|
||||
private salaryRepository = AppDataSource.getRepository(Salarys);
|
||||
private poTypeRepository = AppDataSource.getRepository(PosType);
|
||||
private posLevelRepository = AppDataSource.getRepository(PosLevel);
|
||||
|
||||
/**
|
||||
* API สร้างผังเงินเดือน
|
||||
*
|
||||
* @summary SLR_001 - สร้างผังเงินเดือน #1
|
||||
*
|
||||
*/
|
||||
@Post()
|
||||
@Example(
|
||||
{
|
||||
salaryType: "string", //*ประเภทผัง (OFFICER->"ข้าราชการกรุงเทพมหานครสามัญ",EMPLOYEE->"ลูกจ้างประจำกรุงเทพมหานคร")
|
||||
posType: "string", //*ระดับของตำแหน่ง
|
||||
posLevel: "string", //*ประเภทของตำแหน่ง
|
||||
isActive: "boolean", //*สถานะการใช้งาน
|
||||
date: "datetime", //ให้ไว้ ณ วันที่
|
||||
startDate: "datetime", //วันที่มีผลบังคับใช้
|
||||
endDate: "datetime", //วันที่สิ้นสุดบังคับใช้
|
||||
detail: "string", //คำอธิบาย
|
||||
}
|
||||
)
|
||||
async create(
|
||||
@Body() requestBody: CreateSalary,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
){
|
||||
const salarys = Object.assign(new Salarys(), requestBody);
|
||||
if (!salarys) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
const chk_salaryType = ["OFFICER", "EMPLOYEE"];
|
||||
if (!chk_salaryType.includes(salarys.salaryType.toUpperCase())) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทผัง ไม่ถูกต้อง");
|
||||
}
|
||||
|
||||
const chk_posTypeId = await this.poTypeRepository.findOne({
|
||||
where: { id: salarys.posTypeId }
|
||||
})
|
||||
if(!chk_posTypeId){
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทของตำแหน่ง ไม่ถูกต้อง");
|
||||
}
|
||||
|
||||
const chk_posLevelId = await this.posLevelRepository.findOne({
|
||||
where: { id: salarys.posLevelId }
|
||||
});
|
||||
if(!chk_posLevelId){
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ระดับของตำแหน่ง ไม่ถูกต้อง");
|
||||
}
|
||||
|
||||
const chk_3fields = await this.salaryRepository.findOne({
|
||||
where: {
|
||||
salaryType: salarys.salaryType,
|
||||
posTypeId: salarys.posTypeId,
|
||||
posLevelId: salarys.posLevelId
|
||||
}
|
||||
})
|
||||
if(chk_3fields && salarys.isActive){
|
||||
salarys.isActive = false;
|
||||
}
|
||||
|
||||
try {
|
||||
salarys.salaryType = salarys.salaryType.toUpperCase();
|
||||
salarys.createdUserId = request.user.sub;
|
||||
salarys.createdFullName = request.user.name;
|
||||
salarys.lastUpdateUserId = request.user.sub;
|
||||
salarys.lastUpdateFullName = request.user.name;
|
||||
await this.salaryRepository.save(salarys);
|
||||
return new HttpSuccess(salarys.id);
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -14,13 +14,13 @@ export class Salarys extends EntityBase {
|
|||
|
||||
@Column({
|
||||
length: 40,
|
||||
comment: "Id ระดับของตำแหน่ง",
|
||||
comment: "Id ประเภทของตำแหน่ง",
|
||||
})
|
||||
posTypeId: string;
|
||||
|
||||
@Column({
|
||||
length: 40,
|
||||
comment: "Id ประเภทของตำแหน่ง",
|
||||
comment: "Id ระดับของตำแหน่ง",
|
||||
})
|
||||
posLevelId: string;
|
||||
|
||||
|
|
@ -73,7 +73,7 @@ export class Salarys extends EntityBase {
|
|||
posLevel_: PosLevel;
|
||||
}
|
||||
|
||||
export class CreateSalaryRank {
|
||||
export class CreateSalary {
|
||||
|
||||
@Column()
|
||||
salaryType: string;
|
||||
|
|
@ -101,4 +101,4 @@ export class CreateSalaryRank {
|
|||
|
||||
}
|
||||
|
||||
export type UpdateSalaryRank = Partial<CreateSalaryRank> ;
|
||||
export type UpdateSalary = Partial<CreateSalary> ;
|
||||
Loading…
Add table
Add a link
Reference in a new issue