searching default whatsapp using user link

This commit is contained in:
Ricardo Paes
2022-02-23 11:19:36 -03:00
parent a6a63a0408
commit afb5d68602
5 changed files with 13 additions and 8 deletions

View File

@@ -24,7 +24,10 @@ interface ContactData {
number: string;
}
const createContact = async (newContact: string) => {
const createContact = async (
userId: number,
newContact: string
) => {
await CheckIsValidContact(newContact);
const validNumber: any = await CheckContactNumber(newContact);
@@ -42,7 +45,7 @@ const createContact = async (newContact: string) => {
const contact = await CreateOrUpdateContactService(contactData);
const defaultWhatsapp = await GetDefaultWhatsApp();
const defaultWhatsapp = await GetDefaultWhatsApp(userId);
const createTicket = await FindOrCreateTicketService(
contact,
@@ -76,7 +79,8 @@ export const index = async (req: Request, res: Response): Promise<Response> => {
throw new AppError(err.message);
}
const contactAndTicket = await createContact(newContact.number);
const userId:number = parseInt(req.user.id);
const contactAndTicket = await createContact(userId, newContact.number);
if (medias) {
await Promise.all(

View File

@@ -2,7 +2,8 @@ import { Request, Response } from "express";
import ImportContactsService from "../services/WbotServices/ImportContactsService";
export const store = async (req: Request, res: Response): Promise<Response> => {
await ImportContactsService();
const userId:number = parseInt(req.user.id);
await ImportContactsService(userId);
return res.status(200).json({ message: "contacts imported" });
};