API แก้ไขผังเงินเดือน
This commit is contained in:
parent
8c4d2e4d1a
commit
bf8f0c207d
1 changed files with 87 additions and 1 deletions
|
|
@ -50,7 +50,7 @@ export class Salary extends Controller {
|
||||||
detail: "string", //คำอธิบาย
|
detail: "string", //คำอธิบาย
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
async create(
|
async create_salary(
|
||||||
@Body() requestBody: CreateSalary,
|
@Body() requestBody: CreateSalary,
|
||||||
@Request() request: { user: Record<string, any> },
|
@Request() request: { user: Record<string, any> },
|
||||||
){
|
){
|
||||||
|
|
@ -102,6 +102,92 @@ export class Salary extends Controller {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API แก้ไขผังเงินเดือน
|
||||||
|
*
|
||||||
|
* @summary SLR_002 - แก้ไขผังเงินเดือน #2
|
||||||
|
*
|
||||||
|
* @param {string} id Guid, *Id ผังเงินเดือน
|
||||||
|
*/
|
||||||
|
@Put("{id}")
|
||||||
|
@Example(
|
||||||
|
{
|
||||||
|
salaryType: "string", //*ประเภทผัง (OFFICER->"ข้าราชการกรุงเทพมหานครสามัญ",EMPLOYEE->"ลูกจ้างประจำกรุงเทพมหานคร")
|
||||||
|
posType: "string", //*ระดับของตำแหน่ง
|
||||||
|
posLevel: "string", //*ประเภทของตำแหน่ง
|
||||||
|
isActive: "boolean", //*สถานะการใช้งาน
|
||||||
|
date: "datetime", //ให้ไว้ ณ วันที่
|
||||||
|
startDate: "datetime", //วันที่มีผลบังคับใช้
|
||||||
|
endDate: "datetime", //วันที่สิ้นสุดบังคับใช้
|
||||||
|
detail: "string", //คำอธิบาย
|
||||||
|
},
|
||||||
|
)
|
||||||
|
async update_salary(
|
||||||
|
@Path() id: string,
|
||||||
|
@Body() requestBody: UpdateSalary,
|
||||||
|
@Request() request: { user: Record<string, any> },
|
||||||
|
) {
|
||||||
|
|
||||||
|
const chk_Salary = await this.salaryRepository.findOne({
|
||||||
|
where: { id: id },
|
||||||
|
});
|
||||||
|
if (!chk_Salary) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดี: "+ id);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(chk_Salary.isActive && !requestBody.isActive){
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถแก้ไขสถานะการใช้งานที่เป็น Default ได้");
|
||||||
|
}
|
||||||
|
|
||||||
|
const chk_3fields = await this.salaryRepository.findOne({
|
||||||
|
where: {
|
||||||
|
salaryType: requestBody.salaryType,
|
||||||
|
posTypeId: requestBody.posTypeId,
|
||||||
|
posLevelId: requestBody.posLevelId,
|
||||||
|
isActive: true,
|
||||||
|
id: Not(id)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if(chk_3fields != null && requestBody.isActive) {
|
||||||
|
chk_3fields.isActive = false;
|
||||||
|
chk_3fields.lastUpdateUserId = request.user.sub;
|
||||||
|
chk_3fields.lastUpdateFullName = request.user.name;
|
||||||
|
chk_3fields.lastUpdatedAt = new Date();
|
||||||
|
await this.salaryRepository.save(chk_3fields);
|
||||||
|
}
|
||||||
|
|
||||||
|
const chk_salaryType = ["OFFICER", "EMPLOYEE"];
|
||||||
|
if (!chk_salaryType.includes(String(requestBody.salaryType).toUpperCase())) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทผัง ไม่ถูกต้อง");
|
||||||
|
}
|
||||||
|
|
||||||
|
const chk_posTypeId = await this.poTypeRepository.findOne({
|
||||||
|
where: { id: requestBody.posTypeId }
|
||||||
|
})
|
||||||
|
if(!chk_posTypeId){
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทของตำแหน่ง ไม่ถูกต้อง");
|
||||||
|
}
|
||||||
|
|
||||||
|
const chk_posLevelId = await this.posLevelRepository.findOne({
|
||||||
|
where: { id: requestBody.posLevelId }
|
||||||
|
});
|
||||||
|
if(!chk_posLevelId){
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ระดับของตำแหน่ง ไม่ถูกต้อง");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
chk_Salary.lastUpdateUserId = request.user.sub;
|
||||||
|
chk_Salary.lastUpdateFullName = request.user.name;
|
||||||
|
chk_Salary.lastUpdatedAt = new Date();
|
||||||
|
this.salaryRepository.merge(chk_Salary, requestBody);
|
||||||
|
await this.salaryRepository.save(chk_Salary);
|
||||||
|
return new HttpSuccess(id);
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue