mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-17 19:37:02 +00:00
✨ When starting ticket set queue automatically if user is only one linked
This commit is contained in:
@@ -2,18 +2,21 @@ import AppError from "../../errors/AppError";
|
||||
import CheckContactOpenTickets from "../../helpers/CheckContactOpenTickets";
|
||||
import GetDefaultWhatsApp from "../../helpers/GetDefaultWhatsApp";
|
||||
import Ticket from "../../models/Ticket";
|
||||
import User from "../../models/User";
|
||||
import ShowContactService from "../ContactServices/ShowContactService";
|
||||
|
||||
interface Request {
|
||||
contactId: number;
|
||||
status: string;
|
||||
userId: number;
|
||||
queueId ?: number;
|
||||
}
|
||||
|
||||
const CreateTicketService = async ({
|
||||
contactId,
|
||||
status,
|
||||
userId
|
||||
userId,
|
||||
queueId
|
||||
}: Request): Promise<Ticket> => {
|
||||
const defaultWhatsapp = await GetDefaultWhatsApp(userId);
|
||||
|
||||
@@ -21,11 +24,17 @@ const CreateTicketService = async ({
|
||||
|
||||
const { isGroup } = await ShowContactService(contactId);
|
||||
|
||||
if(queueId === undefined) {
|
||||
const user = await User.findByPk(userId, { include: ["queues"]});
|
||||
queueId = user?.queues.length === 1 ? user.queues[0].id : undefined;
|
||||
}
|
||||
|
||||
const { id }: Ticket = await defaultWhatsapp.$create("ticket", {
|
||||
contactId,
|
||||
status,
|
||||
isGroup,
|
||||
userId
|
||||
userId,
|
||||
queueId
|
||||
});
|
||||
|
||||
const ticket = await Ticket.findByPk(id, { include: ["contact"] });
|
||||
|
||||
Reference in New Issue
Block a user