migrated import contacts controller to typescript

This commit is contained in:
canove
2020-09-22 11:09:52 -03:00
parent 9bab61c7dc
commit 0d8b4cd60c
7 changed files with 131 additions and 126 deletions

View File

@@ -1,38 +1,8 @@
// const Contact = require("../models/Contact");
// const Whatsapp = require("../models/Whatsapp");
// const { getIO } = require("../libs/socket");
// const { getWbot, initWbot } = require("../libs/wbot");
import { Request, Response } from "express";
import ImportContactsService from "../services/WbotServices/ImportContactsService";
// exports.store = async (req, res, next) => {
// const defaultWhatsapp = await Whatsapp.findOne({
// where: { default: true }
// });
export const store = async (req: Request, res: Response): Promise<Response> => {
await ImportContactsService();
// if (!defaultWhatsapp) {
// return res
// .status(404)
// .json({ error: "No default WhatsApp found. Check Connection page." });
// }
// const io = getIO();
// const wbot = getWbot(defaultWhatsapp);
// let phoneContacts;
// try {
// phoneContacts = await wbot.getContacts();
// } catch (err) {
// console.log(err);
// return res.status(500).json({
// error: "Could not check whatsapp contact. Check connection page."
// });
// }
// await Promise.all(
// phoneContacts.map(async ({ number, name }) => {
// await Contact.create({ number, name });
// })
// );
// return res.status(200).json({ message: "contacts imported" });
// };
return res.status(200).json({ message: "contacts imported" });
};