diff --git a/backend/src/controllers/ContactController.ts b/backend/src/controllers/ContactController.ts index 987cc6b..6242fd4 100644 --- a/backend/src/controllers/ContactController.ts +++ b/backend/src/controllers/ContactController.ts @@ -1,4 +1,5 @@ import { Request, Response } from "express"; +import { getIO } from "../libs/socket"; import ListContactsService from "../services/ContactServices/ListContactsService"; import CreateContactService from "../services/ContactServices/CreateContactService"; @@ -6,7 +7,6 @@ import ShowContactService from "../services/ContactServices/ShowContactService"; import UpdateContactService from "../services/ContactServices/UpdateContactService"; import DeleteContactService from "../services/ContactServices/DeleteContactService"; -// const { getIO } = require("../libs/socket"); // const { getWbot } = require("../libs/wbot"); type IndexQuery = { @@ -57,7 +57,6 @@ export const store = async (req: Request, res: Response): Promise => { // } // const wbot = getWbot(defaultWhatsapp); - // const io = getIO(); // try { // const isValidNumber = await wbot.isRegisteredUser( @@ -86,10 +85,11 @@ export const store = async (req: Request, res: Response): Promise => { // } // ); - // io.emit("contact", { - // action: "create", - // contact: contact - // }); + const io = getIO(); + io.emit("contact", { + action: "create", + contact + }); return res.status(200).json(contact); }; @@ -112,11 +112,11 @@ export const update = async ( const contact = await UpdateContactService({ contactData, contactId }); - // const io = getIO(); - // io.emit("contact", { - // action: "update", - // contact: contact - // }); + const io = getIO(); + io.emit("contact", { + action: "update", + contact + }); return res.status(200).json(contact); }; @@ -129,11 +129,11 @@ export const remove = async ( await DeleteContactService(contactId); - // const io = getIO(); - // io.emit("contact", { - // action: "delete", - // contactId: contactId - // }); + const io = getIO(); + io.emit("contact", { + action: "delete", + contactId + }); return res.status(200).json({ message: "Contact deleted" }); }; diff --git a/backend/src/services/ContactServices/CreateContactService.ts b/backend/src/services/ContactServices/CreateContactService.ts index 3c821aa..ecc8955 100644 --- a/backend/src/services/ContactServices/CreateContactService.ts +++ b/backend/src/services/ContactServices/CreateContactService.ts @@ -16,8 +16,8 @@ interface Request { const CreateContactService = async ({ name, number, - email, - extraInfo + email = "", + extraInfo = [] }: Request): Promise => { const numberExists = await Contact.findOne({ where: { number } @@ -27,6 +27,8 @@ const CreateContactService = async ({ throw new AppError("A contact with this number already exists."); } + console.log("extra", extraInfo); + const contact = await Contact.create( { name,