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 CheckContactOpenTickets from "../../helpers/CheckContactOpenTickets";
|
||||||
import GetDefaultWhatsApp from "../../helpers/GetDefaultWhatsApp";
|
import GetDefaultWhatsApp from "../../helpers/GetDefaultWhatsApp";
|
||||||
import Ticket from "../../models/Ticket";
|
import Ticket from "../../models/Ticket";
|
||||||
|
import User from "../../models/User";
|
||||||
import ShowContactService from "../ContactServices/ShowContactService";
|
import ShowContactService from "../ContactServices/ShowContactService";
|
||||||
|
|
||||||
interface Request {
|
interface Request {
|
||||||
contactId: number;
|
contactId: number;
|
||||||
status: string;
|
status: string;
|
||||||
userId: number;
|
userId: number;
|
||||||
|
queueId ?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CreateTicketService = async ({
|
const CreateTicketService = async ({
|
||||||
contactId,
|
contactId,
|
||||||
status,
|
status,
|
||||||
userId
|
userId,
|
||||||
|
queueId
|
||||||
}: Request): Promise<Ticket> => {
|
}: Request): Promise<Ticket> => {
|
||||||
const defaultWhatsapp = await GetDefaultWhatsApp(userId);
|
const defaultWhatsapp = await GetDefaultWhatsApp(userId);
|
||||||
|
|
||||||
@@ -21,11 +24,17 @@ const CreateTicketService = async ({
|
|||||||
|
|
||||||
const { isGroup } = await ShowContactService(contactId);
|
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", {
|
const { id }: Ticket = await defaultWhatsapp.$create("ticket", {
|
||||||
contactId,
|
contactId,
|
||||||
status,
|
status,
|
||||||
isGroup,
|
isGroup,
|
||||||
userId
|
userId,
|
||||||
|
queueId
|
||||||
});
|
});
|
||||||
|
|
||||||
const ticket = await Ticket.findByPk(id, { include: ["contact"] });
|
const ticket = await Ticket.findByPk(id, { include: ["contact"] });
|
||||||
|
|||||||
Reference in New Issue
Block a user