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