mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-20 04:39:20 +00:00
✨ searching default whatsapp using user link
This commit is contained in:
@@ -24,7 +24,10 @@ interface ContactData {
|
|||||||
number: string;
|
number: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const createContact = async (newContact: string) => {
|
const createContact = async (
|
||||||
|
userId: number,
|
||||||
|
newContact: string
|
||||||
|
) => {
|
||||||
await CheckIsValidContact(newContact);
|
await CheckIsValidContact(newContact);
|
||||||
|
|
||||||
const validNumber: any = await CheckContactNumber(newContact);
|
const validNumber: any = await CheckContactNumber(newContact);
|
||||||
@@ -42,7 +45,7 @@ const createContact = async (newContact: string) => {
|
|||||||
|
|
||||||
const contact = await CreateOrUpdateContactService(contactData);
|
const contact = await CreateOrUpdateContactService(contactData);
|
||||||
|
|
||||||
const defaultWhatsapp = await GetDefaultWhatsApp();
|
const defaultWhatsapp = await GetDefaultWhatsApp(userId);
|
||||||
|
|
||||||
const createTicket = await FindOrCreateTicketService(
|
const createTicket = await FindOrCreateTicketService(
|
||||||
contact,
|
contact,
|
||||||
@@ -76,7 +79,8 @@ export const index = async (req: Request, res: Response): Promise<Response> => {
|
|||||||
throw new AppError(err.message);
|
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) {
|
if (medias) {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ import { Request, Response } from "express";
|
|||||||
import ImportContactsService from "../services/WbotServices/ImportContactsService";
|
import ImportContactsService from "../services/WbotServices/ImportContactsService";
|
||||||
|
|
||||||
export const store = async (req: Request, res: Response): Promise<Response> => {
|
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" });
|
return res.status(200).json({ message: "contacts imported" });
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import Ticket from "../models/Ticket";
|
|||||||
|
|
||||||
const GetTicketWbot = async (ticket: Ticket): Promise<Session> => {
|
const GetTicketWbot = async (ticket: Ticket): Promise<Session> => {
|
||||||
if (!ticket.whatsappId) {
|
if (!ticket.whatsappId) {
|
||||||
const defaultWhatsapp = await GetDefaultWhatsApp();
|
const defaultWhatsapp = await GetDefaultWhatsApp(ticket.user.id);
|
||||||
|
|
||||||
await ticket.$set("whatsapp", defaultWhatsapp);
|
await ticket.$set("whatsapp", defaultWhatsapp);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ const CreateTicketService = async ({
|
|||||||
status,
|
status,
|
||||||
userId
|
userId
|
||||||
}: Request): Promise<Ticket> => {
|
}: Request): Promise<Ticket> => {
|
||||||
const defaultWhatsapp = await GetDefaultWhatsApp();
|
const defaultWhatsapp = await GetDefaultWhatsApp(userId);
|
||||||
|
|
||||||
await CheckContactOpenTickets(contactId);
|
await CheckContactOpenTickets(contactId);
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ import { getWbot } from "../../libs/wbot";
|
|||||||
import Contact from "../../models/Contact";
|
import Contact from "../../models/Contact";
|
||||||
import { logger } from "../../utils/logger";
|
import { logger } from "../../utils/logger";
|
||||||
|
|
||||||
const ImportContactsService = async (): Promise<void> => {
|
const ImportContactsService = async (userId:number): Promise<void> => {
|
||||||
const defaultWhatsapp = await GetDefaultWhatsApp();
|
const defaultWhatsapp = await GetDefaultWhatsApp(userId);
|
||||||
|
|
||||||
const wbot = getWbot(defaultWhatsapp.id);
|
const wbot = getWbot(defaultWhatsapp.id);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user