feat: support displaing quoted messages

This commit is contained in:
canove
2020-10-28 17:54:29 -03:00
parent 4e259a3de7
commit 74d3772eb1
7 changed files with 118 additions and 22 deletions

View File

@@ -28,7 +28,7 @@ const CreateMessageService = async ({
await Message.upsert(messageData);
const message = await Message.findByPk(messageData.id, {
include: ["contact"]
include: ["contact", "quotedMsg"]
});
if (!message) {

View File

@@ -1,4 +1,3 @@
import { where, fn, col } from "sequelize";
import AppError from "../../errors/AppError";
import Message from "../../models/Message";
import Ticket from "../../models/Ticket";
@@ -6,7 +5,6 @@ import ShowTicketService from "../TicketServices/ShowTicketService";
interface Request {
ticketId: string;
searchParam?: string;
pageNumber?: string;
}
@@ -18,7 +16,6 @@ interface Response {
}
const ListMessagesService = async ({
searchParam = "",
pageNumber = "1",
ticketId
}: Request): Promise<Response> => {
@@ -28,23 +25,14 @@ const ListMessagesService = async ({
throw new AppError("ERR_NO_TICKET_FOUND", 404);
}
const whereCondition = {
body: where(
fn("LOWER", col("body")),
"LIKE",
`%${searchParam.toLowerCase()}%`
),
ticketId
};
// await setMessagesAsRead(ticket);
const limit = 20;
const offset = limit * (+pageNumber - 1);
const { count, rows: messages } = await Message.findAndCountAll({
where: whereCondition,
where: { ticketId },
limit,
include: ["contact"],
include: ["contact", "quotedMsg"],
offset,
order: [["createdAt", "DESC"]]
});