Merge branch 'develop' of github.com:Frappet/bma-ehr-salary into develop
This commit is contained in:
commit
c680dcd6a8
1 changed files with 40 additions and 25 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue