enabled socket io on tickets controller

This commit is contained in:
canove
2020-09-20 12:00:30 -03:00
parent 02c37276ba
commit 95c6dcb32f
3 changed files with 39 additions and 87 deletions

View File

@@ -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" });
};