Atualização em andamento

adriano 2023-06-19 09:24:48 -03:00
parent 6e2ba241b3
commit d23a826385
4 changed files with 26 additions and 11 deletions

View File

@ -2,14 +2,16 @@ import { Op } from "sequelize";
import AppError from "../errors/AppError";
import Ticket from "../models/Ticket";
const CheckContactOpenTickets = async (contactId: number): Promise<void> => {
const CheckContactOpenTickets = async (contactId: number | string, whatsappId: number | string): Promise<void> => {
const ticket = await Ticket.findOne({
where: { contactId, status: { [Op.or]: ["open", "pending"] } }
where: { contactId, whatsappId, status: { [Op.or]: ["open", "pending"] } }
});
if (ticket) {
throw new AppError("ERR_OTHER_OPEN_TICKET");
}
};
export default CheckContactOpenTickets;

View File

@ -44,15 +44,18 @@ const CreateTicketService = async ({
const defaultWhatsapp = await GetDefaultWhatsApp(userId);
// console.log('defaultWhatsapp: ',defaultWhatsapp)
// console.log('JSON.parse(JSON.stringify(defaultWhatsapp)): ',JSON.parse(JSON.stringify(defaultWhatsapp)))
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);
await CheckContactOpenTickets(contactId, defaultWhatsapp.id);
const { isGroup } = await ShowContactService(contactId);

View File

@ -49,7 +49,7 @@ const UpdateTicketService = async ({
const oldUserId = ticket.user?.id;
if (oldStatus === "closed") {
await CheckContactOpenTickets(ticket.contact.id);
await CheckContactOpenTickets(ticket.contact.id, ticket.whatsappId);
}
await ticket.update({

View File

@ -1,7 +1,7 @@
import Whatsapp from "../../models/Whatsapp";
const ListWhatsAppsNumber = async (whatsappId: string | number, status: string): Promise<Whatsapp[] | any> => {
const ListWhatsAppsNumber = async (whatsappId: string | number, status?: string): Promise<Whatsapp[] | any> => {
// const whatsapp = await Whatsapp.findOne({
// raw: true,
@ -10,13 +10,23 @@ const ListWhatsAppsNumber = async (whatsappId: string | number, status: string):
const whatsapp = await Whatsapp.findByPk(whatsappId, { raw: true })
let whatsapps: any = []
if (whatsapp) {
const whatsapps = await Whatsapp.findAll({
raw: true,
where: { number: whatsapp.number, status: status },
attributes: ['id', 'number', 'status', 'isDefault', 'url']
});
if (status) {
whatsapps = await Whatsapp.findAll({
raw: true,
where: { number: whatsapp.number, status: status },
attributes: ['id', 'number', 'status', 'isDefault', 'url']
});
} else {
whatsapps = await Whatsapp.findAll({
raw: true,
where: { number: whatsapp.number },
attributes: ['id', 'number', 'status', 'isDefault', 'url']
});
}
return { whatsapps, whatsapp };