Atualização em andamento
parent
6e2ba241b3
commit
d23a826385
|
@ -2,14 +2,16 @@ 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 | string, whatsappId: number | string): 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) {
|
||||||
throw new AppError("ERR_OTHER_OPEN_TICKET");
|
throw new AppError("ERR_OTHER_OPEN_TICKET");
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default CheckContactOpenTickets;
|
export default CheckContactOpenTickets;
|
||||||
|
|
|
@ -44,15 +44,18 @@ const CreateTicketService = async ({
|
||||||
|
|
||||||
const defaultWhatsapp = await GetDefaultWhatsApp(userId);
|
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, })
|
const user = await User.findByPk(userId, { raw: true, })
|
||||||
console.log('user.profile: ', user?.profile)
|
console.log('user.profile: ', user?.profile)
|
||||||
|
|
||||||
|
|
||||||
const matchingQueue = await whatsappQueueMatchingUserQueue(userId, defaultWhatsapp, user?.profile);
|
const matchingQueue = await whatsappQueueMatchingUserQueue(userId, defaultWhatsapp, user?.profile);
|
||||||
console.log('matchingQueue: ', matchingQueue)
|
console.log('matchingQueue: ', matchingQueue)
|
||||||
const queueId = matchingQueue ? matchingQueue.queueId : undefined
|
const queueId = matchingQueue ? matchingQueue.queueId : undefined
|
||||||
|
|
||||||
await CheckContactOpenTickets(contactId);
|
await CheckContactOpenTickets(contactId, defaultWhatsapp.id);
|
||||||
|
|
||||||
const { isGroup } = await ShowContactService(contactId);
|
const { isGroup } = await ShowContactService(contactId);
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,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({
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
import Whatsapp from "../../models/Whatsapp";
|
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({
|
// const whatsapp = await Whatsapp.findOne({
|
||||||
// raw: true,
|
// raw: true,
|
||||||
|
@ -10,13 +10,23 @@ const ListWhatsAppsNumber = async (whatsappId: string | number, status: string):
|
||||||
|
|
||||||
const whatsapp = await Whatsapp.findByPk(whatsappId, { raw: true })
|
const whatsapp = await Whatsapp.findByPk(whatsappId, { raw: true })
|
||||||
|
|
||||||
|
let whatsapps: any = []
|
||||||
|
|
||||||
if (whatsapp) {
|
if (whatsapp) {
|
||||||
|
|
||||||
const whatsapps = await Whatsapp.findAll({
|
if (status) {
|
||||||
|
whatsapps = await Whatsapp.findAll({
|
||||||
raw: true,
|
raw: true,
|
||||||
where: { number: whatsapp.number, status: status },
|
where: { number: whatsapp.number, status: status },
|
||||||
attributes: ['id', 'number', 'status', 'isDefault', 'url']
|
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 };
|
return { whatsapps, whatsapp };
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue