Merge branch 'master' of https://update-hitphone.omnihit.app.br/adriano.andrade/projeto-hit
commit
8772348aa3
|
@ -303,7 +303,8 @@ export const remoteTicketCreation = async (
|
|||
id: ticket.id,
|
||||
createdAt: ticket.createdAt,
|
||||
updatedAt: ticket.updatedAt,
|
||||
whatsappId: ticket.whatsappId
|
||||
whatsappId: ticket.whatsappId,
|
||||
status: ticket.status
|
||||
})
|
||||
);
|
||||
|
||||
|
@ -624,6 +625,26 @@ export const update = async (
|
|||
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) {
|
||||
const dateToday = splitDateTime(
|
||||
new Date(format(new Date(), "yyyy-MM-dd HH:mm:ss", { locale: ptBR }))
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
};
|
|
@ -2,6 +2,7 @@ import { intervalToDuration } from "date-fns";
|
|||
import { del, get, set } from "./RedisClient";
|
||||
import { getIO } from "../libs/socket";
|
||||
import controllByNumber from "./controllByNumber";
|
||||
import UpdateTicketService from "../services/TicketServices/UpdateTicketService";
|
||||
|
||||
let timer: any;
|
||||
|
||||
|
@ -11,6 +12,64 @@ const AutoRemoteTickets = async () => {
|
|||
|
||||
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) {
|
||||
if (!ticket.includes("messageDateTime")) continue;
|
||||
|
||||
|
|
|
@ -51,6 +51,9 @@ class User extends Model<User> {
|
|||
@Column
|
||||
transferToOtherQueues: boolean;
|
||||
|
||||
@Column
|
||||
identifier: string;
|
||||
|
||||
@Default("admin")
|
||||
@Column
|
||||
profile: string;
|
||||
|
|
|
@ -15,7 +15,7 @@ var flatten = require("flat");
|
|||
|
||||
interface TicketData {
|
||||
status?: string;
|
||||
userId?: number;
|
||||
userId?: number | null;
|
||||
queueId?: number;
|
||||
statusChatEnd?: string;
|
||||
statusChatEndId?: number;
|
||||
|
|
|
@ -45,7 +45,7 @@ const NewTicketModal = ({ modalOpen, onClose }) => {
|
|||
const fetchContacts = async () => {
|
||||
try {
|
||||
const { data } = await api.get("contacts", {
|
||||
params: { searchParam },
|
||||
params: { searchParam, userId: user.id },
|
||||
});
|
||||
setOptions(data.contacts);
|
||||
setLoading(false);
|
||||
|
|
|
@ -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 () => {
|
||||
socket.disconnect()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue