feat: show an alert when connection with whatsapp brokes

This commit is contained in:
canove
2020-10-27 19:59:38 -03:00
parent 79e27b71cc
commit 4e259a3de7
13 changed files with 360 additions and 296 deletions

View File

@@ -2,6 +2,7 @@ import { Request, Response } from "express";
import { getWbot } from "../libs/wbot";
import ShowWhatsAppService from "../services/WhatsappService/ShowWhatsAppService";
import { StartWhatsAppSession } from "../services/WbotServices/StartWhatsAppSession";
import UpdateWhatsAppService from "../services/WhatsappService/UpdateWhatsAppService";
const store = async (req: Request, res: Response): Promise<Response> => {
const { whatsappId } = req.params;
@@ -14,9 +15,11 @@ const store = async (req: Request, res: Response): Promise<Response> => {
const update = async (req: Request, res: Response): Promise<Response> => {
const { whatsappId } = req.params;
const whatsapp = await ShowWhatsAppService(whatsappId);
await whatsapp.update({ session: "" });
const { whatsapp } = await UpdateWhatsAppService({
whatsappId,
whatsappData: { session: "" }
});
StartWhatsAppSession(whatsapp);

View File

@@ -21,12 +21,6 @@ export const initWbot = async (whatsapp: Whatsapp): Promise<Session> => {
sessionCfg = JSON.parse(whatsapp.session);
}
const currentSessionIndex = sessions.findIndex(s => s.id === whatsapp.id);
if (currentSessionIndex !== -1) {
sessions[currentSessionIndex].destroy();
sessions.splice(currentSessionIndex, 1);
}
const wbot: Session = new Client({
session: sessionCfg
});

View File

@@ -7,6 +7,7 @@ import Whatsapp from "../../models/Whatsapp";
interface WhatsappData {
name?: string;
status?: string;
session?: string;
isDefault?: boolean;
}
@@ -29,7 +30,7 @@ const UpdateWhatsAppService = async ({
isDefault: Yup.boolean()
});
const { name, status, isDefault } = whatsappData;
const { name, status, isDefault, session } = whatsappData;
try {
await schema.validate({ name, status, isDefault });
@@ -58,6 +59,7 @@ const UpdateWhatsAppService = async ({
await whatsapp.update({
name,
status,
session,
isDefault
});