mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-20 04:39:20 +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 AppError from "../errors/AppError";
|
||||||
import Ticket from "../models/Ticket";
|
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({
|
const ticket = await Ticket.findOne({
|
||||||
where: { contactId, status: { [Op.or]: ["open", "pending"] } }
|
where: { contactId, whatsappId, status: { [Op.or]: ["open", "pending"] } }
|
||||||
});
|
});
|
||||||
|
|
||||||
if (ticket) {
|
if (ticket) {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ const CreateTicketService = async ({
|
|||||||
}: Request): Promise<Ticket> => {
|
}: Request): Promise<Ticket> => {
|
||||||
const defaultWhatsapp = await GetDefaultWhatsApp(userId);
|
const defaultWhatsapp = await GetDefaultWhatsApp(userId);
|
||||||
|
|
||||||
await CheckContactOpenTickets(contactId);
|
await CheckContactOpenTickets(contactId, defaultWhatsapp.id);
|
||||||
|
|
||||||
const { isGroup } = await ShowContactService(contactId);
|
const { isGroup } = await ShowContactService(contactId);
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,8 @@ const FindOrCreateTicketService = async (
|
|||||||
status: {
|
status: {
|
||||||
[Op.or]: ["open", "pending"]
|
[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) {
|
if (!ticket && groupContact) {
|
||||||
ticket = await Ticket.findOne({
|
ticket = await Ticket.findOne({
|
||||||
where: {
|
where: {
|
||||||
contactId: groupContact.id
|
contactId: groupContact.id,
|
||||||
|
whatsappId: whatsappId
|
||||||
},
|
},
|
||||||
order: [["updatedAt", "DESC"]]
|
order: [["updatedAt", "DESC"]]
|
||||||
});
|
});
|
||||||
@@ -46,7 +48,8 @@ const FindOrCreateTicketService = async (
|
|||||||
updatedAt: {
|
updatedAt: {
|
||||||
[Op.between]: [+subHours(new Date(), 2), +new Date()]
|
[Op.between]: [+subHours(new Date(), 2), +new Date()]
|
||||||
},
|
},
|
||||||
contactId: contact.id
|
contactId: contact.id,
|
||||||
|
whatsappId: whatsappId
|
||||||
},
|
},
|
||||||
order: [["updatedAt", "DESC"]]
|
order: [["updatedAt", "DESC"]]
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ const UpdateTicketService = async ({
|
|||||||
const oldUserId = ticket.user?.id;
|
const oldUserId = ticket.user?.id;
|
||||||
|
|
||||||
if (oldStatus === "closed") {
|
if (oldStatus === "closed") {
|
||||||
await CheckContactOpenTickets(ticket.contact.id);
|
await CheckContactOpenTickets(ticket.contact.id, ticket.whatsappId);
|
||||||
}
|
}
|
||||||
|
|
||||||
await ticket.update({
|
await ticket.update({
|
||||||
|
|||||||
Reference in New Issue
Block a user