ปรับ paging
This commit is contained in:
parent
aef3fbba79
commit
e49c4a9a55
4 changed files with 95 additions and 63 deletions
|
|
@ -14,7 +14,7 @@ import {
|
|||
Get,
|
||||
Query,
|
||||
} from "tsoa";
|
||||
import { Not } from "typeorm";
|
||||
import { Not, Like } from "typeorm";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpStatusCode from "../interfaces/http-status";
|
||||
|
|
@ -143,26 +143,35 @@ export class SalaryRankEmployeeController extends Controller {
|
|||
@Query("pageSize") pageSize: number = 10,
|
||||
@Query("keyword") keyword?: string,
|
||||
) {
|
||||
let whereClause: any = {};
|
||||
if (keyword != undefined && keyword !== "") {
|
||||
whereClause = {
|
||||
where: [
|
||||
{ salaryEmployeeId: id, },
|
||||
{ step: Like(`%${keyword}%`) },
|
||||
{ salaryMonth: Like(`%${keyword}%`) },
|
||||
{ salaryDay: Like(`%${keyword}%`) },
|
||||
],
|
||||
};
|
||||
}
|
||||
const [salaryRankEmployee, total] = await this.salaryRankEmployeeRepository.findAndCount({
|
||||
where: {
|
||||
salaryEmployeeId: id,
|
||||
},
|
||||
...whereClause,
|
||||
select: ["id", "step", "salaryMonth", "salaryDay"],
|
||||
order: {
|
||||
step: "ASC",
|
||||
},
|
||||
...(keyword ? {} : { skip: (page - 1) * pageSize, take: pageSize }),
|
||||
});
|
||||
if (keyword != undefined && keyword !== "") {
|
||||
const filteredSalaryRankEmployee = salaryRankEmployee.filter(
|
||||
(x) =>
|
||||
x.step?.toString().includes(keyword) ||
|
||||
x.salaryMonth?.toString().includes(keyword) ||
|
||||
x.salaryDay?.toString().includes(keyword),
|
||||
);
|
||||
const slicedData = filteredSalaryRankEmployee.slice((page - 1) * pageSize, page * pageSize);
|
||||
return new HttpSuccess({ data: slicedData, total: filteredSalaryRankEmployee.length });
|
||||
}
|
||||
// if (keyword != undefined && keyword !== "") {
|
||||
// const filteredSalaryRankEmployee = salaryRankEmployee.filter(
|
||||
// (x) =>
|
||||
// x.step?.toString().includes(keyword) ||
|
||||
// x.salaryMonth?.toString().includes(keyword) ||
|
||||
// x.salaryDay?.toString().includes(keyword),
|
||||
// );
|
||||
// const slicedData = filteredSalaryRankEmployee.slice((page - 1) * pageSize, page * pageSize);
|
||||
// return new HttpSuccess({ data: slicedData, total: filteredSalaryRankEmployee.length });
|
||||
// }
|
||||
|
||||
return new HttpSuccess({ data: salaryRankEmployee, total });
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue