ผังเงินเดือนลูกจ้าง

This commit is contained in:
Kittapath 2024-03-13 09:30:04 +07:00
parent 0cf3d3dc85
commit 87f29e22e9
7 changed files with 699 additions and 61 deletions

View file

@ -4,7 +4,6 @@ import {
Post,
Put,
Delete,
Patch,
Route,
Security,
Tags,
@ -18,12 +17,11 @@ import { Salarys, CreateSalary, UpdateSalary } from "../entities/Salarys";
import { PosType } from "../entities/PosType";
import { PosLevel } from "../entities/PosLevel";
import { AppDataSource } from "../database/data-source";
import { DeepPartial, In, IsNull, Not } from "typeorm";
import { Not } from "typeorm";
import HttpSuccess from "../interfaces/http-success";
import HttpError from "../interfaces/http-error";
import HttpStatusCode from "../interfaces/http-status";
import { SalaryRanks } from "../entities/SalaryRanks";
import { query } from "express";
import { randomUUID } from "crypto";
@Route("api/v1/salary")
@ -56,7 +54,6 @@ export class Salary extends Controller {
@Body() requestBody: CreateSalary,
@Request() request: { user: Record<string, any> },
) {
// try {
const salarys = Object.assign(new Salarys(), requestBody);
if (!salarys) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
@ -78,7 +75,6 @@ export class Salary extends Controller {
const chk_3fields = await this.salaryRepository.findOne({
where: {
name: salarys.name,
posTypeId: salarys.posTypeId,
posLevelId: salarys.posLevelId,
},
@ -94,9 +90,6 @@ export class Salary extends Controller {
salarys.lastUpdateFullName = request.user.name;
await this.salaryRepository.save(salarys);
return new HttpSuccess(salarys.id);
// } catch (error: any) {
// throw new Error(error);
// }
}
/**
@ -122,7 +115,6 @@ export class Salary extends Controller {
@Body() requestBody: UpdateSalary,
@Request() request: { user: Record<string, any> },
) {
// try {
const chk_Salary = await this.salaryRepository.findOne({
where: { id: id },
});
@ -147,7 +139,7 @@ export class Salary extends Controller {
});
if (chk_3fields.length > 0 && requestBody.isActive) {
chk_3fields.forEach(async (item) => {
chk_3fields.forEach(async (item) => {
item.isActive = false;
item.lastUpdateUserId = request.user.sub;
item.lastUpdateFullName = request.user.name;
@ -177,9 +169,6 @@ export class Salary extends Controller {
this.salaryRepository.merge(chk_Salary, mergeData);
await this.salaryRepository.save(chk_Salary);
return new HttpSuccess(id);
// } catch (error: any) {
// throw new Error(error);
// }
}
/**
@ -191,7 +180,6 @@ export class Salary extends Controller {
*/
@Delete("{id}")
async delete_salary(@Path() id: string) {
// try {
const chk_Salary = await this.salaryRepository.findOne({
where: { id: id },
});
@ -210,9 +198,6 @@ export class Salary extends Controller {
await this.salaryRankRepository.remove(del_SalaryRank);
await this.salaryRepository.remove(chk_Salary);
return new HttpSuccess();
// } catch (error: any) {
// throw new Error(error);
// }
}
/**
@ -234,7 +219,6 @@ export class Salary extends Controller {
detail: "string", //คำอธิบาย
})
async GetSalaryById(@Path() id: string) {
// try {
const salary = await this.salaryRepository.findOne({
where: { id: id },
select: [
@ -253,9 +237,6 @@ export class Salary extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผังเงินเดือนนี้");
}
return new HttpSuccess(salary);
// } catch (error: any) {
// throw new Error(error);
// }
}
/**
@ -273,13 +254,12 @@ export class Salary extends Controller {
const [salary, total] = await this.salaryRepository.findAndCount({
relations: ["posLevel_", "posType_"],
order: {
// startDate: "DESC",
isActive: "DESC",
posType_: {
posTypeRank: "DESC"
posTypeRank: "DESC",
},
posLevel_: {
posLevelRank: "DESC"
posLevelRank: "DESC",
},
},
...(keyword ? {} : { skip: (page - 1) * pageSize, take: pageSize }),