mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-17 19:37:02 +00:00
✨ open more than one ticket per user as long as it is using another whatsapp
This commit is contained in:
@@ -2,9 +2,12 @@ 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,
|
||||
whatsappId: number
|
||||
): Promise<void> => {
|
||||
const ticket = await Ticket.findOne({
|
||||
where: { contactId, status: { [Op.or]: ["open", "pending"] } }
|
||||
where: { contactId, whatsappId, status: { [Op.or]: ["open", "pending"] } }
|
||||
});
|
||||
|
||||
if (ticket) {
|
||||
|
||||
@@ -17,7 +17,7 @@ const CreateTicketService = async ({
|
||||
}: Request): Promise<Ticket> => {
|
||||
const defaultWhatsapp = await GetDefaultWhatsApp(userId);
|
||||
|
||||
await CheckContactOpenTickets(contactId);
|
||||
await CheckContactOpenTickets(contactId, defaultWhatsapp.id);
|
||||
|
||||
const { isGroup } = await ShowContactService(contactId);
|
||||
|
||||
|
||||
@@ -15,7 +15,8 @@ const FindOrCreateTicketService = async (
|
||||
status: {
|
||||
[Op.or]: ["open", "pending"]
|
||||
},
|
||||
contactId: groupContact ? groupContact.id : contact.id
|
||||
contactId: groupContact ? groupContact.id : contact.id,
|
||||
whatsappId: whatsappId
|
||||
}
|
||||
});
|
||||
|
||||
@@ -26,7 +27,8 @@ const FindOrCreateTicketService = async (
|
||||
if (!ticket && groupContact) {
|
||||
ticket = await Ticket.findOne({
|
||||
where: {
|
||||
contactId: groupContact.id
|
||||
contactId: groupContact.id,
|
||||
whatsappId: whatsappId
|
||||
},
|
||||
order: [["updatedAt", "DESC"]]
|
||||
});
|
||||
@@ -46,7 +48,8 @@ const FindOrCreateTicketService = async (
|
||||
updatedAt: {
|
||||
[Op.between]: [+subHours(new Date(), 2), +new Date()]
|
||||
},
|
||||
contactId: contact.id
|
||||
contactId: contact.id,
|
||||
whatsappId: whatsappId
|
||||
},
|
||||
order: [["updatedAt", "DESC"]]
|
||||
});
|
||||
|
||||
@@ -36,7 +36,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({
|
||||
|
||||
Reference in New Issue
Block a user