mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-18 19:59:20 +00:00
improvement: change default whatsapp logic
This commit is contained in:
@@ -25,7 +25,11 @@ export const index = async (req: Request, res: Response): Promise<Response> => {
|
||||
export const store = async (req: Request, res: Response): Promise<Response> => {
|
||||
const { name, status, isDefault }: WhatsappData = req.body;
|
||||
|
||||
const whatsapp = await CreateWhatsAppService({ name, status, isDefault });
|
||||
const { whatsapp, oldDefaultWhatsapp } = await CreateWhatsAppService({
|
||||
name,
|
||||
status,
|
||||
isDefault
|
||||
});
|
||||
|
||||
initWbot(whatsapp)
|
||||
.then(() => {
|
||||
@@ -40,6 +44,13 @@ export const store = async (req: Request, res: Response): Promise<Response> => {
|
||||
whatsapp
|
||||
});
|
||||
|
||||
if (oldDefaultWhatsapp) {
|
||||
io.emit("whatsapp", {
|
||||
action: "update",
|
||||
whatsapp: oldDefaultWhatsapp
|
||||
});
|
||||
}
|
||||
|
||||
return res.status(200).json(whatsapp);
|
||||
};
|
||||
|
||||
@@ -58,7 +69,10 @@ export const update = async (
|
||||
const { whatsappId } = req.params;
|
||||
const whatsappData = req.body;
|
||||
|
||||
const whatsapp = await UpdateWhatsAppService({ whatsappData, whatsappId });
|
||||
const { whatsapp, oldDefaultWhatsapp } = await UpdateWhatsAppService({
|
||||
whatsappData,
|
||||
whatsappId
|
||||
});
|
||||
|
||||
const io = getIO();
|
||||
io.emit("whatsapp", {
|
||||
@@ -66,6 +80,13 @@ export const update = async (
|
||||
whatsapp
|
||||
});
|
||||
|
||||
if (oldDefaultWhatsapp) {
|
||||
io.emit("whatsapp", {
|
||||
action: "update",
|
||||
whatsapp: oldDefaultWhatsapp
|
||||
});
|
||||
}
|
||||
|
||||
return res.status(200).json(whatsapp);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user