Feat: Added import contacts function on frontend

This commit is contained in:
canove
2020-07-28 10:45:35 -03:00
parent 915ee712dc
commit 124297a849
11 changed files with 128 additions and 141 deletions

View File

@@ -0,0 +1,18 @@
const Contact = require("../models/Contact");
const { getIO } = require("../libs/socket");
const { getWbot, init } = require("../libs/wbot");
exports.store = async (req, res, next) => {
const io = getIO();
const wbot = getWbot();
const phoneContacts = await wbot.getContacts();
await Promise.all(
phoneContacts.map(async ({ number, name }) => {
await Contact.create({ number, name });
})
);
return res.status(200).json({ message: "contacts imported" });
};