paging เกณ

This commit is contained in:
Kittapath 2024-03-14 18:00:59 +07:00
parent 5682fb8424
commit 18e95c57cb

View file

@ -21,7 +21,7 @@ import HttpSuccess from "../interfaces/http-success";
import HttpStatusCode from "../interfaces/http-status";
import { PosLevel, CreatePosLevel, UpdatePosLevel } from "../entities/PosLevel";
import HttpError from "../interfaces/http-error";
import { In, Not } from "typeorm";
import { ILike, In, Like, Not } from "typeorm";
import {
CreateSalaryFormulaEmployee,
SalaryFormulaEmployee,
@ -195,7 +195,7 @@ export class SalaryFormulaEmployeeController extends Controller {
@Get("{id}")
async getFormulaDetail(@Path() id: string) {
const getFormula = await this.salaryFormulaEmployeeRepository.findOne({
relations: ["salaryEmployee", "posType", "posLevel"],
relations: ["salaryEmployee", "posType", "posLevel", "salaryEmployeeMins"],
where: { id: id },
});
if (!getFormula) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผังค่าจ้างนี้");
@ -210,6 +210,7 @@ export class SalaryFormulaEmployeeController extends Controller {
salary: getFormula.salary,
salaryMax: getFormula.salaryMax,
salaryEmployeeId: getFormula.salaryEmployeeId,
salaryEmployeeMinIds: getFormula.salaryEmployeeMins.map((x) => x.id),
};
return new HttpSuccess(mapFormula);
@ -221,25 +222,43 @@ export class SalaryFormulaEmployeeController extends Controller {
*
*/
@Get()
async getFormula() {
const getFormula = await this.salaryFormulaEmployeeRepository.find({
relations: ["salaryEmployee", "posType", "posLevel"],
async getFormula(
@Query("page") page: number = 1,
@Query("pageSize") pageSize: number = 10,
@Query("keyword") keyword?: string,
) {
const [getFormula, total] = await this.salaryFormulaEmployeeRepository.findAndCount({
relations: ["salaryEmployee", "posType", "posLevel", "salaryEmployeeMins"],
where: {
details: Like(`%${keyword}%`),
position: Like(`%${keyword}%`),
// posLevel: { posLevelName: keyword },
posType: { posTypeName: Like(`%${keyword}%`) },
// salaryEmployeeMins: { group: keyword },
// salaryEmployee: { group: keyword },
},
order: {
lastUpdatedAt: "DESC",
},
...(keyword ? {} : { skip: (page - 1) * pageSize, take: pageSize }),
});
const mapFormula = getFormula.map((item) => ({
id: item.id,
// posLevelId: item.posLevelId,
posLevel: item.posLevel != null ? item.posLevel.posLevelName : null,
position: item.position,
position: item.position, ////
// posTypeId: item.posTypeId,
posType: item.posType != null ? item.posType.posTypeName : null,
details: item.details,
salaryMin: item.salaryMin,
salary: item.salary,
salaryMax: item.salaryMax,
details: item.details, ////
salaryMin: item.salaryMin, //
salary: item.salary, //
salaryMax: item.salaryMax, //
// salaryEmployeeId: item.salaryEmployeeId,
group: item.salaryEmployee != null ? item.salaryEmployee.group : null,
salaryEmployeeMin:
item.salaryEmployeeMins != null ? item.salaryEmployeeMins.map((x) => x.group) : null,
}));
return new HttpSuccess(mapFormula);
return new HttpSuccess({ data: mapFormula, total });
}
}