ปรับ paging
This commit is contained in:
parent
aef3fbba79
commit
e49c4a9a55
4 changed files with 95 additions and 63 deletions
|
|
@ -17,7 +17,7 @@ import { Salarys, CreateSalary, UpdateSalary } from "../entities/Salarys";
|
|||
import { PosType } from "../entities/PosType";
|
||||
import { PosLevel } from "../entities/PosLevel";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import { Not } from "typeorm";
|
||||
import { Like, Not } from "typeorm";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import HttpStatusCode from "../interfaces/http-status";
|
||||
|
|
@ -253,6 +253,15 @@ export class SalaryController extends Controller {
|
|||
) {
|
||||
const [salary, total] = await this.salaryRepository.findAndCount({
|
||||
relations: ["posLevel_", "posType_"],
|
||||
where: {
|
||||
name: Like(`%${keyword}%`),
|
||||
posType_: {
|
||||
posTypeName: Like(`%${keyword}%`)
|
||||
},
|
||||
posLevel_: {
|
||||
posLevelName: Like(`%${keyword}%`)
|
||||
}
|
||||
},
|
||||
order: {
|
||||
isActive: "DESC",
|
||||
posType_: {
|
||||
|
|
@ -264,37 +273,37 @@ export class SalaryController extends Controller {
|
|||
},
|
||||
...(keyword ? {} : { skip: (page - 1) * pageSize, take: pageSize }),
|
||||
});
|
||||
if (keyword != undefined && keyword !== "") {
|
||||
const filteredSalary = salary.filter(
|
||||
(x) =>
|
||||
x.name?.toString().includes(keyword) ||
|
||||
x.isSpecial?.toString().includes(keyword) || //new 20.02.67
|
||||
x.posLevel_?.posLevelName?.toString().includes(keyword) ||
|
||||
x.posType_?.posTypeName?.toString().includes(keyword) ||
|
||||
x.isActive?.toString().includes(keyword) ||
|
||||
x.date?.toString().includes(keyword) ||
|
||||
x.startDate?.toString().includes(keyword) ||
|
||||
x.endDate?.toString().includes(keyword) ||
|
||||
x.details?.toString().includes(keyword),
|
||||
);
|
||||
// if (keyword != undefined && keyword !== "") {
|
||||
// const filteredSalary = salary.filter(
|
||||
// (x) =>
|
||||
// x.name?.toString().includes(keyword) ||
|
||||
// x.isSpecial?.toString().includes(keyword) || //new 20.02.67
|
||||
// x.posLevel_?.posLevelName?.toString().includes(keyword) ||
|
||||
// x.posType_?.posTypeName?.toString().includes(keyword) ||
|
||||
// x.isActive?.toString().includes(keyword) ||
|
||||
// x.date?.toString().includes(keyword) ||
|
||||
// x.startDate?.toString().includes(keyword) ||
|
||||
// x.endDate?.toString().includes(keyword) ||
|
||||
// x.details?.toString().includes(keyword),
|
||||
// );
|
||||
|
||||
const formattedData = filteredSalary.map((item) => ({
|
||||
id: item.id,
|
||||
name: item.name,
|
||||
isSpecial: item.isSpecial,
|
||||
posTypeId: item.posType_?.id,
|
||||
posType: item.posType_?.posTypeName,
|
||||
posLevelId: item.posLevel_?.id,
|
||||
posLevel: item.posLevel_?.posLevelName,
|
||||
isActive: item.isActive,
|
||||
date: item.date,
|
||||
startDate: item.startDate,
|
||||
endDate: item.endDate,
|
||||
details: item.details,
|
||||
}));
|
||||
const slicedData = formattedData.slice((page - 1) * pageSize, page * pageSize);
|
||||
return new HttpSuccess({ data: slicedData, total: formattedData.length });
|
||||
}
|
||||
// const formattedData = filteredSalary.map((item) => ({
|
||||
// id: item.id,
|
||||
// name: item.name,
|
||||
// isSpecial: item.isSpecial,
|
||||
// posTypeId: item.posType_?.id,
|
||||
// posType: item.posType_?.posTypeName,
|
||||
// posLevelId: item.posLevel_?.id,
|
||||
// posLevel: item.posLevel_?.posLevelName,
|
||||
// isActive: item.isActive,
|
||||
// date: item.date,
|
||||
// startDate: item.startDate,
|
||||
// endDate: item.endDate,
|
||||
// details: item.details,
|
||||
// }));
|
||||
// const slicedData = formattedData.slice((page - 1) * pageSize, page * pageSize);
|
||||
// return new HttpSuccess({ data: slicedData, total: formattedData.length });
|
||||
// }
|
||||
|
||||
const formattedData = salary.map((item) => ({
|
||||
id: item.id,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue