44 lines
1006 B
TypeScript
44 lines
1006 B
TypeScript
import { Sequelize } from "sequelize";
|
|
import Schedule from "../../models/Schedule";
|
|
|
|
interface Request {
|
|
searchParam?: string;
|
|
pageNumber?: string;
|
|
}
|
|
|
|
interface Response {
|
|
schedules: Schedule[];
|
|
count: number;
|
|
hasMore: boolean;
|
|
}
|
|
|
|
const ListSchedulingService = async ({
|
|
searchParam = "",
|
|
pageNumber = "1"
|
|
}: Request): Promise<Response> => {
|
|
const whereCondition = {
|
|
message: Sequelize.where(
|
|
Sequelize.fn("LOWER", Sequelize.col("name")), "LIKE", `%${searchParam.toLowerCase().trim()}%`)
|
|
};
|
|
const limit = 20;
|
|
const offset = limit * (+pageNumber - 1);
|
|
|
|
const { count, rows: schedules } = await Schedule.findAndCountAll({
|
|
where: whereCondition,
|
|
attributes: ['id', 'name'],
|
|
limit,
|
|
offset,
|
|
order: [["id", "ASC"]]
|
|
});
|
|
|
|
const hasMore = count > offset + schedules.length;
|
|
|
|
return {
|
|
schedules,
|
|
count,
|
|
hasMore
|
|
};
|
|
};
|
|
|
|
export default ListSchedulingService;
|
|
|