diff --git a/backend/src/controllers/WhatsAppController.ts b/backend/src/controllers/WhatsAppController.ts index 38d1c8f..ff24f29 100644 --- a/backend/src/controllers/WhatsAppController.ts +++ b/backend/src/controllers/WhatsAppController.ts @@ -12,18 +12,18 @@ import UpdateWhatsAppService from "../services/WhatsappService/UpdateWhatsAppSer // import wbotMessageListener from "../services/wbotMessageListener"; // import wbotMonitor from "../services/wbotMonitor"; -export const index = async (req: Request, res: Response): Promise => { - const whatsapps = await ListWhatsAppsService(); - - return res.status(200).json(whatsapps); -}; - interface WhatsappData { name: string; status?: string; isDefault?: boolean; } +export const index = async (req: Request, res: Response): Promise => { + const whatsapps = await ListWhatsAppsService(); + + return res.status(200).json(whatsapps); +}; + export const store = async (req: Request, res: Response): Promise => { // const io = getIO(); @@ -53,7 +53,9 @@ export const store = async (req: Request, res: Response): Promise => { export const show = async (req: Request, res: Response): Promise => { const { whatsappId } = req.params; - const whatsapp = await FindWhatsAppService({ where: { id: +whatsappId } }); + console.log(whatsappId); + + const whatsapp = await FindWhatsAppService(whatsappId); return res.status(200).json(whatsapp); }; diff --git a/backend/src/services/WhatsappService/FindWhatsAppService.ts b/backend/src/services/WhatsappService/FindWhatsAppService.ts index 1f0d893..741b9a8 100644 --- a/backend/src/services/WhatsappService/FindWhatsAppService.ts +++ b/backend/src/services/WhatsappService/FindWhatsAppService.ts @@ -1,24 +1,10 @@ import Whatsapp from "../../models/Whatsapp"; import AppError from "../../errors/AppError"; -interface WhereParams { - id?: number; - name?: string; - isDefault?: boolean; -} - -interface Request { - where?: WhereParams; -} - -const FindWhatsAppService = async ({ - where -}: Request): Promise => { - const whereCondition = { ...where }; - - const whatsapp = await Whatsapp.findOne({ - where: whereCondition - }); +const FindWhatsAppService = async ( + id: string | number +): Promise => { + const whatsapp = await Whatsapp.findByPk(id); if (!whatsapp) { throw new AppError("No whatsapp found with this conditions.", 404); diff --git a/backend/src/services/WhatsappService/ListWhatsAppsService.ts b/backend/src/services/WhatsappService/ListWhatsAppsService.ts index 2c2b884..2213530 100644 --- a/backend/src/services/WhatsappService/ListWhatsAppsService.ts +++ b/backend/src/services/WhatsappService/ListWhatsAppsService.ts @@ -1,13 +1,9 @@ import Whatsapp from "../../models/Whatsapp"; -interface Response { - whatsapps: Whatsapp[]; -} - -const ListWhatsAppsService = async (): Promise => { +const ListWhatsAppsService = async (): Promise => { const whatsapps = await Whatsapp.findAll(); - return { whatsapps }; + return whatsapps; }; export default ListWhatsAppsService; diff --git a/frontend/src/components/WhatsAppModal/index.js b/frontend/src/components/WhatsAppModal/index.js index 538f867..5bf4f28 100644 --- a/frontend/src/components/WhatsAppModal/index.js +++ b/frontend/src/components/WhatsAppModal/index.js @@ -60,7 +60,7 @@ const WhatsAppModal = ({ open, onClose, whatsAppId }) => { const classes = useStyles(); const initialState = { name: "", - default: false, + isDefault: false, }; const [whatsApp, setWhatsApp] = useState(initialState); diff --git a/frontend/src/pages/Connections/index.js b/frontend/src/pages/Connections/index.js index 7961ad9..ce7a406 100644 --- a/frontend/src/pages/Connections/index.js +++ b/frontend/src/pages/Connections/index.js @@ -111,31 +111,31 @@ const Connections = () => { fetchSession(); }, []); - useEffect(() => { - const socket = openSocket(process.env.REACT_APP_BACKEND_URL); + // useEffect(() => { + // const socket = openSocket(process.env.REACT_APP_BACKEND_URL); - socket.on("whatsapp", data => { - if (data.action === "update") { - dispatch({ type: "UPDATE_WHATSAPPS", payload: data.whatsapp }); - } - }); + // socket.on("whatsapp", data => { + // if (data.action === "update") { + // dispatch({ type: "UPDATE_WHATSAPPS", payload: data.whatsapp }); + // } + // }); - socket.on("whatsapp", data => { - if (data.action === "delete") { - dispatch({ type: "DELETE_WHATSAPPS", payload: data.whatsappId }); - } - }); + // socket.on("whatsapp", data => { + // if (data.action === "delete") { + // dispatch({ type: "DELETE_WHATSAPPS", payload: data.whatsappId }); + // } + // }); - socket.on("whatsappSession", data => { - if (data.action === "update") { - dispatch({ type: "UPDATE_SESSION", payload: data.session }); - } - }); + // socket.on("whatsappSession", data => { + // if (data.action === "update") { + // dispatch({ type: "UPDATE_SESSION", payload: data.session }); + // } + // }); - return () => { - socket.disconnect(); - }; - }, []); + // return () => { + // socket.disconnect(); + // }; + // }, []); // const handleDisconnectSession = async whatsAppId => { // try { @@ -199,13 +199,13 @@ const Connections = () => { > Are you sure? It cannot be reverted. - + /> */}