Henrriky 2024-05-08 12:30:39 -03:00
commit 8772348aa3
7 changed files with 119 additions and 3 deletions

View File

@ -303,7 +303,8 @@ 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
}) })
); );
@ -624,6 +625,26 @@ 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

@ -0,0 +1,14 @@
import { QueryInterface, DataTypes } from "sequelize";
module.exports = {
up: (queryInterface: QueryInterface) => {
return queryInterface.addColumn("Users", "identifier", {
type: DataTypes.STRING,
allowNull: true
});
},
down: (queryInterface: QueryInterface) => {
return queryInterface.removeColumn("Users", "identifier");
}
};

View File

@ -2,6 +2,7 @@ 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;
@ -11,6 +12,64 @@ 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

@ -51,6 +51,9 @@ class User extends Model<User> {
@Column @Column
transferToOtherQueues: boolean; transferToOtherQueues: boolean;
@Column
identifier: string;
@Default("admin") @Default("admin")
@Column @Column
profile: string; profile: string;

View File

@ -15,7 +15,7 @@ var flatten = require("flat");
interface TicketData { interface TicketData {
status?: string; status?: string;
userId?: number; userId?: number | null;
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 }, params: { searchParam, userId: user.id },
}); });
setOptions(data.contacts); setOptions(data.contacts);
setLoading(false); setLoading(false);

View File

@ -158,6 +158,25 @@ 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()
} }