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