mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-18 19:59:20 +00:00
enabled socket io on tickets controller
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
import { Request, Response } from "express";
|
||||
import { getIO } from "../libs/socket";
|
||||
|
||||
import CreateTicketService from "../services/TicketServices/CreateTicketService";
|
||||
import DeleteTicketService from "../services/TicketServices/DeleteTicketService";
|
||||
import ListTicketsService from "../services/TicketServices/ListTicketsService";
|
||||
import UpdateTicketService from "../services/TicketServices/UpdateTicketService";
|
||||
|
||||
// const { getIO } = require("../libs/socket");
|
||||
|
||||
type IndexQuery = {
|
||||
searchParam: string;
|
||||
pageNumber: string;
|
||||
@@ -30,54 +30,6 @@ export const index = async (req: Request, res: Response): Promise<Response> => {
|
||||
|
||||
const userId = req.user.id;
|
||||
|
||||
// let includeCondition = [
|
||||
// {
|
||||
// model: Contact,
|
||||
// as: "contact",
|
||||
// attributes: ["name", "number", "profilePicUrl"]
|
||||
// }
|
||||
// ];
|
||||
|
||||
// if (searchParam) {
|
||||
// includeCondition = [
|
||||
// ...includeCondition,
|
||||
// {
|
||||
// model: Message,
|
||||
// as: "messages",
|
||||
// attributes: ["id", "body"],
|
||||
// where: {
|
||||
// body: Sequelize.where(
|
||||
// Sequelize.fn("LOWER", Sequelize.col("body")),
|
||||
// "LIKE",
|
||||
// "%" + searchParam.toLowerCase() + "%"
|
||||
// )
|
||||
// },
|
||||
// required: false,
|
||||
// duplicating: false
|
||||
// }
|
||||
// ];
|
||||
|
||||
// whereCondition = {
|
||||
// [Sequelize.Op.or]: [
|
||||
// {
|
||||
// "$contact.name$": Sequelize.where(
|
||||
// Sequelize.fn("LOWER", Sequelize.col("name")),
|
||||
// "LIKE",
|
||||
// "%" + searchParam.toLowerCase() + "%"
|
||||
// )
|
||||
// },
|
||||
// { "$contact.number$": { [Sequelize.Op.like]: `%${searchParam}%` } },
|
||||
// {
|
||||
// "$message.body$": Sequelize.where(
|
||||
// Sequelize.fn("LOWER", Sequelize.col("body")),
|
||||
// "LIKE",
|
||||
// "%" + searchParam.toLowerCase() + "%"
|
||||
// )
|
||||
// }
|
||||
// ]
|
||||
// };
|
||||
// }
|
||||
|
||||
const { tickets, count, hasMore } = await ListTicketsService({
|
||||
searchParam,
|
||||
pageNumber,
|
||||
@@ -95,11 +47,11 @@ export const store = async (req: Request, res: Response): Promise<Response> => {
|
||||
|
||||
const ticket = await CreateTicketService({ contactId, status });
|
||||
|
||||
// const io = getIO();
|
||||
// io.to("notification").emit("ticket", {
|
||||
// action: "create",
|
||||
// ticket: serializaedTicket
|
||||
// });
|
||||
const io = getIO();
|
||||
io.to("notification").emit("ticket", {
|
||||
action: "create",
|
||||
ticket
|
||||
});
|
||||
|
||||
return res.status(200).json(ticket);
|
||||
};
|
||||
@@ -113,11 +65,11 @@ export const update = async (
|
||||
|
||||
const ticket = await UpdateTicketService({ ticketData, ticketId });
|
||||
|
||||
// const io = getIO();
|
||||
// io.to("notification").emit("ticket", {
|
||||
// action: "updateStatus",
|
||||
// ticket: ticket
|
||||
// });
|
||||
const io = getIO();
|
||||
io.to("notification").emit("ticket", {
|
||||
action: "updateStatus",
|
||||
ticket
|
||||
});
|
||||
|
||||
return res.status(200).json(ticket);
|
||||
};
|
||||
@@ -130,11 +82,11 @@ export const remove = async (
|
||||
|
||||
await DeleteTicketService(ticketId);
|
||||
|
||||
// const io = getIO();
|
||||
// io.to("notification").emit("ticket", {
|
||||
// action: "delete",
|
||||
// ticketId: ticket.id
|
||||
// });
|
||||
const io = getIO();
|
||||
io.to("notification").emit("ticket", {
|
||||
action: "delete",
|
||||
ticketId: +ticketId
|
||||
});
|
||||
|
||||
return res.status(200).json({ message: "ticket deleted" });
|
||||
};
|
||||
|
||||
@@ -24,7 +24,7 @@ const UpdateTicketService = async ({
|
||||
{
|
||||
model: Contact,
|
||||
as: "contact",
|
||||
attributes: ["name", "number", "profilePicUrl"]
|
||||
attributes: ["id", "name", "number", "profilePicUrl"]
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
@@ -111,31 +111,31 @@ const Connections = () => {
|
||||
fetchSession();
|
||||
}, []);
|
||||
|
||||
// useEffect(() => {
|
||||
// const socket = openSocket(process.env.REACT_APP_BACKEND_URL);
|
||||
useEffect(() => {
|
||||
const socket = openSocket(process.env.REACT_APP_BACKEND_URL);
|
||||
|
||||
// socket.on("whatsapp", data => {
|
||||
// if (data.action === "update") {
|
||||
// dispatch({ type: "UPDATE_WHATSAPPS", payload: data.whatsapp });
|
||||
// }
|
||||
// });
|
||||
socket.on("whatsapp", data => {
|
||||
if (data.action === "update") {
|
||||
dispatch({ type: "UPDATE_WHATSAPPS", payload: data.whatsapp });
|
||||
}
|
||||
});
|
||||
|
||||
// socket.on("whatsapp", data => {
|
||||
// if (data.action === "delete") {
|
||||
// dispatch({ type: "DELETE_WHATSAPPS", payload: data.whatsappId });
|
||||
// }
|
||||
// });
|
||||
socket.on("whatsapp", data => {
|
||||
if (data.action === "delete") {
|
||||
dispatch({ type: "DELETE_WHATSAPPS", payload: data.whatsappId });
|
||||
}
|
||||
});
|
||||
|
||||
// socket.on("whatsappSession", data => {
|
||||
// if (data.action === "update") {
|
||||
// dispatch({ type: "UPDATE_SESSION", payload: data.session });
|
||||
// }
|
||||
// });
|
||||
socket.on("whatsappSession", data => {
|
||||
if (data.action === "update") {
|
||||
dispatch({ type: "UPDATE_SESSION", payload: data.session });
|
||||
}
|
||||
});
|
||||
|
||||
// return () => {
|
||||
// socket.disconnect();
|
||||
// };
|
||||
// }, []);
|
||||
return () => {
|
||||
socket.disconnect();
|
||||
};
|
||||
}, []);
|
||||
|
||||
// const handleDisconnectSession = async whatsAppId => {
|
||||
// try {
|
||||
|
||||
Reference in New Issue
Block a user