ปรับ 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,
|
||||
|
|
|
|||
|
|
@ -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 { ILike, In, Like, Not } from "typeorm";
|
||||
import { In, Like, Not } from "typeorm";
|
||||
import {
|
||||
CreateSalaryFormulaEmployee,
|
||||
SalaryFormulaEmployee,
|
||||
|
|
|
|||
|
|
@ -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 });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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