Adição do userProfile para quando abrir um novo chat associar com o perfil do usuario

adriano 2023-06-03 07:45:47 -03:00
parent 9c351d1e9a
commit f00220ff37
2 changed files with 11 additions and 5 deletions

View File

@ -2,9 +2,9 @@ import Whatsapp from "../models/Whatsapp";
import ShowQueuesByUser from "../services/UserServices/ShowQueuesByUser";
import ShowWhatsAppService from "../services/WhatsappService/ShowWhatsAppService";
async function whatsappQueueMatchingUserQueue(userId: number, whatsapp: Whatsapp) {
async function whatsappQueueMatchingUserQueue(userId: number, whatsapp: Whatsapp, userProfile: string = 'user') {
const userQueues = await ShowQueuesByUser({ profile: 'user', userId: userId });
const userQueues = await ShowQueuesByUser({ profile: userProfile, userId: userId });
if (!userQueues || userQueues && userQueues.length == 0) return
@ -18,7 +18,7 @@ async function whatsappQueueMatchingUserQueue(userId: number, whatsapp: Whatsapp
// console.log('-----> whatsappQueues: ', whatsappQueues);
const matchingQueue = userQueues.find(queue => whatsappQueues.includes(queue.name));
const matchingQueue = userQueues.find(queue => whatsappQueues.includes(queue.name));
return matchingQueue
}

View File

@ -18,6 +18,7 @@ import ShowQueuesByUser from "../UserServices/ShowQueuesByUser";
import ShowWhatsAppService from "../WhatsappService/ShowWhatsAppService";
import Whatsapp from "../../models/Whatsapp";
import whatsappQueueMatchingUserQueue from "../../helpers/whatsappQueueMatchingUserQueue";
import User from "../../models/User";
let flatten = require('flat')
@ -40,8 +41,13 @@ const CreateTicketService = async ({
const defaultWhatsapp = await GetDefaultWhatsApp(userId);
const matchingQueue = await whatsappQueueMatchingUserQueue(userId, defaultWhatsapp);
console.log('matchingQueue: ', matchingQueue)
const user = await User.findByPk(userId, { raw: true, })
console.log('user.profile: ', user?.profile)
const matchingQueue = await whatsappQueueMatchingUserQueue(userId, defaultWhatsapp, user?.profile);
console.log('matchingQueue: ', matchingQueue)
const queueId = matchingQueue ? matchingQueue.queueId : undefined
await CheckContactOpenTickets(contactId);