feat: checking default whatsapp on import and create contacts

This commit is contained in:
canove
2020-09-06 14:31:53 -03:00
parent b793d28e60
commit fae02cf8e3
2 changed files with 24 additions and 2 deletions

View File

@@ -2,6 +2,7 @@ const Sequelize = require("sequelize");
const { Op } = require("sequelize");
const Contact = require("../models/Contact");
const Whatsapp = require("../models/Whatsapp");
const ContactCustomField = require("../models/ContactCustomField");
const { getIO } = require("../libs/socket");
@@ -39,7 +40,17 @@ exports.index = async (req, res) => {
};
exports.store = async (req, res) => {
const wbot = getWbot();
const defaultWhatsapp = await Whatsapp.findOne({
where: { default: true },
});
if (!defaultWhatsapp) {
return res
.status(404)
.json({ error: "No default WhatsApp found. Check Connection page." });
}
const wbot = getWbot(defaultWhatsapp);
const io = getIO();
const newContact = req.body;

View File

@@ -1,10 +1,21 @@
const Contact = require("../models/Contact");
const Whatsapp = require("../models/Whatsapp");
const { getIO } = require("../libs/socket");
const { getWbot, initWbot } = require("../libs/wbot");
exports.store = async (req, res, next) => {
const defaultWhatsapp = await Whatsapp.findOne({
where: { default: true },
});
if (!defaultWhatsapp) {
return res
.status(404)
.json({ error: "No default WhatsApp found. Check Connection page." });
}
const io = getIO();
const wbot = getWbot();
const wbot = getWbot(defaultWhatsapp);
let phoneContacts;