mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-20 04:39:20 +00:00
enable socket io in all controllers
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import { Request, Response } from "express";
|
import { Request, Response } from "express";
|
||||||
|
import { getIO } from "../libs/socket";
|
||||||
|
|
||||||
import CreateWhatsAppService from "../services/WhatsappService/CreateWhatsAppService";
|
import CreateWhatsAppService from "../services/WhatsappService/CreateWhatsAppService";
|
||||||
import DeleteWhatsAppService from "../services/WhatsappService/DeleteWhatsAppService";
|
import DeleteWhatsAppService from "../services/WhatsappService/DeleteWhatsAppService";
|
||||||
@@ -25,8 +26,6 @@ export const index = async (req: Request, res: Response): Promise<Response> => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const store = async (req: Request, res: Response): Promise<Response> => {
|
export const store = async (req: Request, res: Response): Promise<Response> => {
|
||||||
// const io = getIO();
|
|
||||||
|
|
||||||
const { name, status, isDefault }: WhatsappData = req.body;
|
const { name, status, isDefault }: WhatsappData = req.body;
|
||||||
|
|
||||||
const whatsapp = await CreateWhatsAppService({ name, status, isDefault });
|
const whatsapp = await CreateWhatsAppService({ name, status, isDefault });
|
||||||
@@ -42,10 +41,11 @@ export const store = async (req: Request, res: Response): Promise<Response> => {
|
|||||||
// })
|
// })
|
||||||
// .catch(err => console.log(err));
|
// .catch(err => console.log(err));
|
||||||
|
|
||||||
// io.emit("whatsapp", {
|
const io = getIO();
|
||||||
// action: "update",
|
io.emit("whatsapp", {
|
||||||
// whatsapp: whatsapp
|
action: "update",
|
||||||
// });
|
whatsapp
|
||||||
|
});
|
||||||
|
|
||||||
return res.status(200).json(whatsapp);
|
return res.status(200).json(whatsapp);
|
||||||
};
|
};
|
||||||
@@ -66,7 +66,6 @@ export const update = async (
|
|||||||
const whatsappData = req.body;
|
const whatsappData = req.body;
|
||||||
|
|
||||||
const whatsapp = await UpdateWhatsAppService({ whatsappData, whatsappId });
|
const whatsapp = await UpdateWhatsAppService({ whatsappData, whatsappId });
|
||||||
// const io = getIO();
|
|
||||||
|
|
||||||
// const whatsapp = await Whatsapp.findByPk(whatsappId);
|
// const whatsapp = await Whatsapp.findByPk(whatsappId);
|
||||||
|
|
||||||
@@ -76,10 +75,11 @@ export const update = async (
|
|||||||
|
|
||||||
// await whatsapp.update(req.body);
|
// await whatsapp.update(req.body);
|
||||||
|
|
||||||
// io.emit("whatsapp", {
|
const io = getIO();
|
||||||
// action: "update",
|
io.emit("whatsapp", {
|
||||||
// whatsapp: whatsapp
|
action: "update",
|
||||||
// });
|
whatsapp
|
||||||
|
});
|
||||||
|
|
||||||
return res.status(200).json(whatsapp);
|
return res.status(200).json(whatsapp);
|
||||||
};
|
};
|
||||||
@@ -88,16 +88,16 @@ export const remove = async (
|
|||||||
req: Request,
|
req: Request,
|
||||||
res: Response
|
res: Response
|
||||||
): Promise<Response> => {
|
): Promise<Response> => {
|
||||||
// const io = getIO();
|
|
||||||
const { whatsappId } = req.params;
|
const { whatsappId } = req.params;
|
||||||
|
|
||||||
await DeleteWhatsAppService(whatsappId);
|
await DeleteWhatsAppService(whatsappId);
|
||||||
// removeWbot(whatsapp.id);
|
// removeWbot(whatsapp.id);
|
||||||
|
|
||||||
// io.emit("whatsapp", {
|
const io = getIO();
|
||||||
// action: "delete",
|
io.emit("whatsapp", {
|
||||||
// whatsappId: whatsapp.id
|
action: "delete",
|
||||||
// });
|
whatsappId: +whatsappId
|
||||||
|
});
|
||||||
|
|
||||||
return res.status(200).json({ message: "Whatsapp deleted." });
|
return res.status(200).json({ message: "Whatsapp deleted." });
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user