enabled socket events on contact controller

This commit is contained in:
canove
2020-09-20 11:47:46 -03:00
parent a879bb95ca
commit 23d16679b6
2 changed files with 20 additions and 18 deletions

View File

@@ -1,4 +1,5 @@
import { Request, Response } from "express"; import { Request, Response } from "express";
import { getIO } from "../libs/socket";
import ListContactsService from "../services/ContactServices/ListContactsService"; import ListContactsService from "../services/ContactServices/ListContactsService";
import CreateContactService from "../services/ContactServices/CreateContactService"; import CreateContactService from "../services/ContactServices/CreateContactService";
@@ -6,7 +7,6 @@ import ShowContactService from "../services/ContactServices/ShowContactService";
import UpdateContactService from "../services/ContactServices/UpdateContactService"; import UpdateContactService from "../services/ContactServices/UpdateContactService";
import DeleteContactService from "../services/ContactServices/DeleteContactService"; import DeleteContactService from "../services/ContactServices/DeleteContactService";
// const { getIO } = require("../libs/socket");
// const { getWbot } = require("../libs/wbot"); // const { getWbot } = require("../libs/wbot");
type IndexQuery = { type IndexQuery = {
@@ -57,7 +57,6 @@ export const store = async (req: Request, res: Response): Promise<Response> => {
// } // }
// const wbot = getWbot(defaultWhatsapp); // const wbot = getWbot(defaultWhatsapp);
// const io = getIO();
// try { // try {
// const isValidNumber = await wbot.isRegisteredUser( // const isValidNumber = await wbot.isRegisteredUser(
@@ -86,10 +85,11 @@ export const store = async (req: Request, res: Response): Promise<Response> => {
// } // }
// ); // );
// io.emit("contact", { const io = getIO();
// action: "create", io.emit("contact", {
// contact: contact action: "create",
// }); contact
});
return res.status(200).json(contact); return res.status(200).json(contact);
}; };
@@ -112,11 +112,11 @@ export const update = async (
const contact = await UpdateContactService({ contactData, contactId }); const contact = await UpdateContactService({ contactData, contactId });
// const io = getIO(); const io = getIO();
// io.emit("contact", { io.emit("contact", {
// action: "update", action: "update",
// contact: contact contact
// }); });
return res.status(200).json(contact); return res.status(200).json(contact);
}; };
@@ -129,11 +129,11 @@ export const remove = async (
await DeleteContactService(contactId); await DeleteContactService(contactId);
// const io = getIO(); const io = getIO();
// io.emit("contact", { io.emit("contact", {
// action: "delete", action: "delete",
// contactId: contactId contactId
// }); });
return res.status(200).json({ message: "Contact deleted" }); return res.status(200).json({ message: "Contact deleted" });
}; };

View File

@@ -16,8 +16,8 @@ interface Request {
const CreateContactService = async ({ const CreateContactService = async ({
name, name,
number, number,
email, email = "",
extraInfo extraInfo = []
}: Request): Promise<Contact> => { }: Request): Promise<Contact> => {
const numberExists = await Contact.findOne({ const numberExists = await Contact.findOne({
where: { number } where: { number }
@@ -27,6 +27,8 @@ const CreateContactService = async ({
throw new AppError("A contact with this number already exists."); throw new AppError("A contact with this number already exists.");
} }
console.log("extra", extraInfo);
const contact = await Contact.create( const contact = await Contact.create(
{ {
name, name,