2022-02-28 13:51:11 +00:00
|
|
|
import { Sequelize } from "sequelize";
|
2022-03-23 02:59:01 +00:00
|
|
|
import StatusChatEnd from "../../models/StatusChatEnd";
|
2022-02-28 13:51:11 +00:00
|
|
|
|
|
|
|
interface Request {
|
|
|
|
searchParam?: string;
|
|
|
|
pageNumber?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface Response {
|
2022-03-23 02:59:01 +00:00
|
|
|
statusChatEnd: StatusChatEnd[];
|
2022-02-28 13:51:11 +00:00
|
|
|
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);
|
|
|
|
|
2022-03-23 02:59:01 +00:00
|
|
|
const { count, rows: statusChatEnd } = await StatusChatEnd.findAndCountAll({
|
2022-02-28 13:51:11 +00:00
|
|
|
where: whereCondition,
|
2024-04-12 21:33:15 +00:00
|
|
|
attributes: ["id", "name", "farewellMessage", "isDefault"],
|
2022-02-28 13:51:11 +00:00
|
|
|
limit,
|
|
|
|
offset,
|
2024-04-12 21:33:15 +00:00
|
|
|
order: [["name", "ASC"]]
|
2022-02-28 13:51:11 +00:00
|
|
|
});
|
|
|
|
|
2022-03-23 02:59:01 +00:00
|
|
|
const hasMore = count > offset + statusChatEnd.length;
|
2022-02-28 13:51:11 +00:00
|
|
|
|
|
|
|
return {
|
2022-03-23 02:59:01 +00:00
|
|
|
statusChatEnd,
|
2022-02-28 13:51:11 +00:00
|
|
|
count,
|
|
|
|
hasMore
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ListSchedulingService;
|
|
|
|
|