diff --git a/src/controllers/SalaryEmployeeController.ts b/src/controllers/SalaryEmployeeController.ts index 6b63b16..c8a295a 100644 --- a/src/controllers/SalaryEmployeeController.ts +++ b/src/controllers/SalaryEmployeeController.ts @@ -19,7 +19,7 @@ import { UpdateSalaryEmployee, } from "../entities/SalaryEmployee"; import { AppDataSource } from "../database/data-source"; -import { Not } from "typeorm"; +import { Not, Like } from "typeorm"; import HttpSuccess from "../interfaces/http-success"; import HttpError from "../interfaces/http-error"; import HttpStatusCode from "../interfaces/http-status"; @@ -216,38 +216,53 @@ export class SalaryEmployeeController extends Controller { @Query("pageSize") pageSize: number = 10, @Query("keyword") keyword?: string, ) { + let whereClause : any = {}; + if (keyword != undefined && keyword !== "") { + whereClause = { + where: [ + { name: Like(`%${keyword}%`) }, + { group: Like(`%${keyword}%`) }, + { isActive: Like(`%${keyword}%`) }, + { date: Like(`%${keyword}%`) }, + { startDate: Like(`%${keyword}%`) }, + { endDate: Like(`%${keyword}%`) }, + { details: Like(`%${keyword}%`) }, + ] + }; + } const [salary, total] = await this.salaryEmployeeRepository.findAndCount({ + ...whereClause, order: { isActive: "DESC", group: "ASC", }, ...(keyword ? {} : { skip: (page - 1) * pageSize, take: pageSize }), }); - if (keyword != undefined && keyword !== "") { - const filteredSalary = salary.filter( - (x) => - x.name?.toString().includes(keyword) || - x.group?.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.group?.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, - group: item.group, - 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, + // group: item.group, + // 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,