ปรับ paging
This commit is contained in:
parent
aef3fbba79
commit
e49c4a9a55
4 changed files with 95 additions and 63 deletions
|
|
@ -14,6 +14,7 @@ import {
|
|||
Get,
|
||||
Query,
|
||||
} from "tsoa";
|
||||
import { Like} from "typeorm";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpStatusCode from "../interfaces/http-status";
|
||||
|
|
@ -121,10 +122,23 @@ export class SalaryRanksController extends Controller {
|
|||
@Query("pageSize") pageSize: number = 10,
|
||||
@Query("keyword") keyword?: string,
|
||||
) {
|
||||
let whereClause: any = {};
|
||||
if (keyword != undefined && keyword !== "") {
|
||||
whereClause = {
|
||||
where: [
|
||||
{ salaryId: id },
|
||||
{ salary: Like(`%${keyword}%`) },
|
||||
{ salaryHalf: Like(`%${keyword}%`) },
|
||||
{ salaryHalfSpecial: Like(`%${keyword}%`) },
|
||||
{ salaryFull: Like(`%${keyword}%`) },
|
||||
{ salaryFullSpecial: Like(`%${keyword}%`) },
|
||||
{ salaryFullHalf: Like(`%${keyword}%`) },
|
||||
{ salaryFullHalfSpecial: Like(`%${keyword}%`) },
|
||||
],
|
||||
};
|
||||
}
|
||||
const [salaryRank, total] = await this.salaryRankRepository.findAndCount({
|
||||
where: {
|
||||
salaryId: id,
|
||||
},
|
||||
...whereClause,
|
||||
select: [
|
||||
"id",
|
||||
"salary",
|
||||
|
|
@ -142,20 +156,20 @@ export class SalaryRanksController extends Controller {
|
|||
},
|
||||
...(keyword ? {} : { skip: (page - 1) * pageSize, take: pageSize }),
|
||||
});
|
||||
if (keyword != undefined && keyword !== "") {
|
||||
const filteredSalaryRank = salaryRank.filter(
|
||||
(x) =>
|
||||
x.salary?.toString().includes(keyword) ||
|
||||
x.salaryHalf?.toString().includes(keyword) ||
|
||||
x.salaryHalfSpecial?.toString().includes(keyword) ||
|
||||
x.salaryFull?.toString().includes(keyword) ||
|
||||
x.salaryFullSpecial?.toString().includes(keyword) ||
|
||||
x.salaryFullHalf?.toString().includes(keyword) ||
|
||||
x.salaryFullHalfSpecial?.toString().includes(keyword),
|
||||
);
|
||||
const slicedData = filteredSalaryRank.slice((page - 1) * pageSize, page * pageSize);
|
||||
return new HttpSuccess({ data: slicedData, total: filteredSalaryRank.length });
|
||||
}
|
||||
// if (keyword != undefined && keyword !== "") {
|
||||
// const filteredSalaryRank = salaryRank.filter(
|
||||
// (x) =>
|
||||
// x.salary?.toString().includes(keyword) ||
|
||||
// x.salaryHalf?.toString().includes(keyword) ||
|
||||
// x.salaryHalfSpecial?.toString().includes(keyword) ||
|
||||
// x.salaryFull?.toString().includes(keyword) ||
|
||||
// x.salaryFullSpecial?.toString().includes(keyword) ||
|
||||
// x.salaryFullHalf?.toString().includes(keyword) ||
|
||||
// x.salaryFullHalfSpecial?.toString().includes(keyword),
|
||||
// );
|
||||
// const slicedData = filteredSalaryRank.slice((page - 1) * pageSize, page * pageSize);
|
||||
// return new HttpSuccess({ data: slicedData, total: filteredSalaryRank.length });
|
||||
// }
|
||||
|
||||
return new HttpSuccess({ data: salaryRank, total });
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue