Compare commits

..

No commits in common. "7bc957df777e18dee24bf49edb09ab61eb809b88" and "8eb2156845d0aebdd1eba1a671319534fd89ba6c" have entirely different histories.

5 changed files with 3 additions and 102 deletions

View File

@ -303,8 +303,7 @@ export const remoteTicketCreation = async (
id: ticket.id, id: ticket.id,
createdAt: ticket.createdAt, createdAt: ticket.createdAt,
updatedAt: ticket.updatedAt, updatedAt: ticket.updatedAt,
whatsappId: ticket.whatsappId, whatsappId: ticket.whatsappId
status: ticket.status
}) })
); );
@ -625,26 +624,6 @@ export const update = async (
await setMessageAsRead(ticket); await setMessageAsRead(ticket);
} }
if (ticketData.status == "open" || ticketData.status == "pending") {
let ticketRemote = await get({
key: `remote:ticketId:${ticketId}`
});
if (ticketRemote) {
ticketRemote = JSON.parse(ticketRemote);
ticketRemote = {
...ticketRemote,
...{
status: ticketData.status == "open" ? "open" : "pending",
updatedAt: ticket.updatedAt
}
};
set(`remote:ticketId:${ticketId}`, JSON.stringify(ticketRemote));
}
}
if (ticketData.userId) { if (ticketData.userId) {
const dateToday = splitDateTime( const dateToday = splitDateTime(
new Date(format(new Date(), "yyyy-MM-dd HH:mm:ss", { locale: ptBR })) new Date(format(new Date(), "yyyy-MM-dd HH:mm:ss", { locale: ptBR }))

View File

@ -2,7 +2,6 @@ import { intervalToDuration } from "date-fns";
import { del, get, set } from "./RedisClient"; import { del, get, set } from "./RedisClient";
import { getIO } from "../libs/socket"; import { getIO } from "../libs/socket";
import controllByNumber from "./controllByNumber"; import controllByNumber from "./controllByNumber";
import UpdateTicketService from "../services/TicketServices/UpdateTicketService";
let timer: any; let timer: any;
@ -12,64 +11,6 @@ const AutoRemoteTickets = async () => {
if (!obj?.tickets) return; if (!obj?.tickets) return;
// console.log("remote tickets: ", obj?.tickets);
for (const ticket of obj.tickets) {
if (!ticket.includes("open") || ticket.includes("messageDateTime"))
continue;
const regex = /"updatedAt":"([^"]+)"/;
let match = ticket.match(regex);
const updatedAt = match ? match[1] : null;
console.log("updatedAt: ", updatedAt);
let timeDiff: any = intervalToDuration({
start: new Date(updatedAt),
end: new Date()
});
console.log("----------> idle time timeDiff: ", timeDiff);
if (timeDiff.minutes > 2) {
match = ticket.match(/"id":(\d+)/);
let ticketId = match ? match[1] : null;
console.log("ticketId: ", ticketId);
ticketId = JSON.parse(ticketId);
let ticketRemote = await get({
key: `remote:ticketId:${ticketId}`
});
if (ticketRemote) {
ticketRemote = JSON.parse(ticketRemote);
ticketRemote = {
...ticketRemote,
...{ status: "pending" }
};
set(`remote:ticketId:${ticketId}`, JSON.stringify(ticketRemote));
await UpdateTicketService({
ticketData: {
status: "pending",
userId: null
},
ticketId
});
const io = getIO();
io.emit("remoteTickesControllIdleOpen", {
action: "update",
ticketId
});
}
}
}
for (const ticket of obj.tickets) { for (const ticket of obj.tickets) {
if (!ticket.includes("messageDateTime")) continue; if (!ticket.includes("messageDateTime")) continue;

View File

@ -15,7 +15,7 @@ var flatten = require("flat");
interface TicketData { interface TicketData {
status?: string; status?: string;
userId?: number | null; userId?: number;
queueId?: number; queueId?: number;
statusChatEnd?: string; statusChatEnd?: string;
statusChatEndId?: number; statusChatEndId?: number;

View File

@ -45,7 +45,7 @@ const NewTicketModal = ({ modalOpen, onClose }) => {
const fetchContacts = async () => { const fetchContacts = async () => {
try { try {
const { data } = await api.get("contacts", { const { data } = await api.get("contacts", {
params: { searchParam, userId: user.id }, params: { searchParam },
}); });
setOptions(data.contacts); setOptions(data.contacts);
setLoading(false); setLoading(false);

View File

@ -158,25 +158,6 @@ const Ticket = () => {
} }
}) })
socket.on("remoteTickesControllIdleOpen", (data) => {
if (data.action === "update") {
let url_ticketId
try {
let url_split = window.location.href.split('tickets')
url_ticketId = url_split[url_split.length - 1].match(/\d+/)[0]
if (url_ticketId && +url_ticketId === data.ticketId) {
history.push("/tickets")
}
} catch (error) {
console.log('error on try do the send seen: ', error)
}
}
})
return () => { return () => {
socket.disconnect() socket.disconnect()
} }