Criação do service para recuperar todos os tickets para o cache
parent
12c497f65b
commit
603e5fa2dd
Binary file not shown.
|
@ -157,7 +157,7 @@ const monitor = async () => {
|
|||
|
||||
if (countTest == 0) {
|
||||
try {
|
||||
console.log(' Carregando usuárion no listUserId...')
|
||||
console.log(' Carregando usuarios no listUserId...')
|
||||
listUserId = await ListUserParamiterService({ profile: 'user' })
|
||||
|
||||
} catch (error) {
|
||||
|
|
|
@ -16,4 +16,4 @@ StartAllWhatsAppsSessions();
|
|||
gracefulShutdown(server);
|
||||
|
||||
startSchedulingMonitor(5000)
|
||||
startWhoIsOnlineMonitor(2000)
|
||||
startWhoIsOnlineMonitor(50000)
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
import Ticket from "../../models/Ticket";
|
||||
import AppError from "../../errors/AppError";
|
||||
import { Op, where } from "sequelize";
|
||||
import { Sequelize } from "sequelize";
|
||||
|
||||
import { format } from "date-fns";
|
||||
import ptBR from 'date-fns/locale/pt-BR';
|
||||
|
||||
import { splitDateTime } from "../../helpers/SplitDateTime";
|
||||
import Contact from "../../models/Contact";
|
||||
import Queue from "../../models/Queue";
|
||||
const dateToday = splitDateTime(new Date(format(new Date(), 'yyyy-MM-dd HH:mm:ss', { locale: ptBR })))
|
||||
|
||||
const ListTicketsServiceCache = async (status?: string, date?: string): Promise<any> => {
|
||||
|
||||
let where_clause = {}
|
||||
|
||||
if (date) {
|
||||
where_clause = {
|
||||
createdAt: {
|
||||
[Op.gte]: date + ' 00:00:00.000000',
|
||||
[Op.lte]: date + ' 23:59:59.999999'
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// where_clause = {
|
||||
// createdAt: {
|
||||
// [Op.gte]: dateToday.fullDate + ' 00:00:00.000000',
|
||||
// [Op.lte]: dateToday.fullDate + ' 23:59:59.999999'
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
//where_clause = { ...where_clause, status: status }
|
||||
|
||||
const ticket = await Ticket.findAll({
|
||||
where: where_clause,
|
||||
raw: true,
|
||||
// nest:true,
|
||||
include:
|
||||
[
|
||||
{
|
||||
model: Contact,
|
||||
as: "contact",
|
||||
attributes: ["id", "name", "number", "profilePicUrl"]
|
||||
},
|
||||
{
|
||||
model: Queue,
|
||||
as: "queue",
|
||||
attributes: ["id", "name", "color"]
|
||||
}
|
||||
],
|
||||
|
||||
order: [["updatedAt", "DESC"]]
|
||||
});
|
||||
|
||||
|
||||
if (!ticket) {
|
||||
throw new AppError("ERR_NO_TICKET_FOUND", 404);
|
||||
}
|
||||
|
||||
return ticket;
|
||||
};
|
||||
|
||||
export default ListTicketsServiceCache;
|
|
@ -11,6 +11,8 @@ import ShowUserService from "../UserServices/ShowUserService";
|
|||
import { splitDateTime } from "../../helpers/SplitDateTime";
|
||||
const dateToday = splitDateTime(new Date(format(new Date(), 'yyyy-MM-dd HH:mm:ss', { locale: ptBR })))
|
||||
|
||||
import ListTicketServiceCache from "./ListTicketServiceCache"
|
||||
|
||||
|
||||
interface Request {
|
||||
searchParam?: string;
|
||||
|
@ -47,6 +49,11 @@ const ListTicketsService = async ({
|
|||
};
|
||||
let includeCondition: Includeable[];
|
||||
|
||||
|
||||
// test del
|
||||
// const test = await ListTicketServiceCache()
|
||||
// console.log('TEST:\n', test)
|
||||
//
|
||||
|
||||
|
||||
includeCondition = [
|
||||
|
@ -88,9 +95,9 @@ const ListTicketsService = async ({
|
|||
if (searchParam) {
|
||||
const sanitizedSearchParam = searchParam.toLocaleLowerCase().trim();
|
||||
|
||||
//othavio
|
||||
//othavio
|
||||
|
||||
console.log('sanitizedSearchParam:'+ sanitizedSearchParam, ' | sanitizedSearchParam.length: ',sanitizedSearchParam.length)
|
||||
console.log('sanitizedSearchParam:'+ sanitizedSearchParam, ' | date: ',date)
|
||||
|
||||
// includeCondition = [
|
||||
// ...includeCondition,
|
||||
|
@ -144,6 +151,9 @@ const ListTicketsService = async ({
|
|||
const limit = unlimited === 'true' ? 100000 : 40;
|
||||
const offset = limit * (+pageNumber - 1);
|
||||
|
||||
|
||||
// console.log('whereCondition: ', JSON.stringify(whereCondition))
|
||||
|
||||
const { count, rows: tickets } = await Ticket.findAndCountAll({
|
||||
where: whereCondition,
|
||||
include: includeCondition,
|
||||
|
@ -155,6 +165,8 @@ const ListTicketsService = async ({
|
|||
|
||||
const hasMore = count > offset + tickets.length;
|
||||
|
||||
|
||||
|
||||
return {
|
||||
tickets,
|
||||
count,
|
||||
|
|
|
@ -42,7 +42,7 @@ const ShowTicketReport = async ({
|
|||
|
||||
if(userId=='0'){
|
||||
where_clause = {
|
||||
createdAt: {
|
||||
updatedAt: {
|
||||
[Op.gte]: startDate+' 00:00:00.000000',
|
||||
[Op.lte]: endDate +' 23:59:59.999999'
|
||||
},
|
||||
|
@ -51,7 +51,7 @@ const ShowTicketReport = async ({
|
|||
else{
|
||||
where_clause = {
|
||||
userid: userId,
|
||||
createdAt: {
|
||||
updatedAt: {
|
||||
[Op.gte]: startDate+' 00:00:00.000000',
|
||||
[Op.lte]: endDate +' 23:59:59.999999'
|
||||
},
|
||||
|
|
|
@ -59,15 +59,7 @@ const SendWhatsAppMessage = async ({
|
|||
|
||||
|
||||
try {
|
||||
const sentMessage = await wbot.sendMessage(
|
||||
`${ticket.contact.number}@${ticket.isGroup ? "g" : "c"}.us`,
|
||||
body,
|
||||
{
|
||||
quotedMessageId: quotedMsgSerializedId,
|
||||
linkPreview: false
|
||||
}
|
||||
);
|
||||
|
||||
const sentMessage = await wbot.sendMessage(`${ticket.contact.number}@${ticket.isGroup ? "g" : "c"}.us`, body, { quotedMessageId: quotedMsgSerializedId, linkPreview: false });
|
||||
await ticket.update({ lastMessage: body });
|
||||
return sentMessage;
|
||||
} catch (err) {
|
||||
|
|
|
@ -188,7 +188,7 @@ const verifyQueue = async (
|
|||
|
||||
//Habilitar esse caso queira usar o bot
|
||||
// const botInfo = await BotIsOnQueue('botqueue')
|
||||
const botInfo = {isOnQueue: false, botQueueId: 0, userIdBot: 0}
|
||||
const botInfo = { isOnQueue: false, botQueueId: 0, userIdBot: 0 }
|
||||
|
||||
if (botInfo.isOnQueue) {
|
||||
|
||||
|
@ -376,7 +376,7 @@ const handleMessage = async (
|
|||
msgContact = await wbot.getContactById(msg.to);
|
||||
} else {
|
||||
|
||||
msgContact = await msg.getContact();
|
||||
msgContact = await msg.getContact();
|
||||
|
||||
// console.log('-----msgContact TESTE MSG2: ', msgContact, ' | msg: ', msg)
|
||||
|
||||
|
@ -423,11 +423,11 @@ const handleMessage = async (
|
|||
unreadMessages,
|
||||
groupContact
|
||||
);
|
||||
|
||||
|
||||
// Para responder para o cliente pelo mesmo whatsapp que ele enviou a mensagen
|
||||
if (wbot.id != ticket.whatsappId) {
|
||||
|
||||
console.log('>>> entrou wbot.id: ', wbot.id, ' | ',ticket.whatsappId)
|
||||
console.log('>>> entrou wbot.id: ', wbot.id, ' | ', ticket.whatsappId)
|
||||
|
||||
await ticket.update({ whatsappId: wbot.id });
|
||||
}
|
||||
|
@ -455,10 +455,10 @@ const handleMessage = async (
|
|||
|
||||
|
||||
// O bot interage com o cliente e encaminha o atendimento para fila de atendende quando o usuário escolhe a opção falar com atendente
|
||||
|
||||
|
||||
//Habilitar esse caso queira usar o bot
|
||||
// const botInfo = await BotIsOnQueue('botqueue')
|
||||
const botInfo = {isOnQueue: false, botQueueId: 0, userIdBot: 0}
|
||||
const botInfo = { isOnQueue: false, botQueueId: 0, userIdBot: 0 }
|
||||
|
||||
if (botInfo.isOnQueue && !msg.fromMe && ticket.userId == botInfo.userIdBot) {
|
||||
|
||||
|
@ -769,26 +769,26 @@ const handleMessage = async (
|
|||
logger.error(`Error handling whatsapp message: Err: ${err}`);
|
||||
|
||||
//Solução para contornar erro de sessão
|
||||
if ((`${err}`).includes("Evaluation failed: r")) {
|
||||
if ((`${err}`).includes("Evaluation failed: r")) {
|
||||
|
||||
const sourcePath = path.join(__dirname,`../../../.wwebjs_auth/sessions`)
|
||||
const sourcePath = path.join(__dirname, `../../../.wwebjs_auth/sessions`)
|
||||
|
||||
let log = new Date(new Date() + 'UTC');
|
||||
const dateToday = splitDateTime(new Date(format(new Date(), 'yyyy-MM-dd HH:mm:ss', { locale: ptBR })))
|
||||
|
||||
const whatsapp = await ShowWhatsAppService(wbot.id!);
|
||||
const whatsapp = await ShowWhatsAppService(wbot.id!);
|
||||
|
||||
if (whatsapp.status == 'CONNECTED') {
|
||||
|
||||
console.log('wbotMessageListener.ts - ENTROU NO RESTORE...')
|
||||
|
||||
console.log('wbotMessageListener.ts - ENTROU NO RESTORE...')
|
||||
|
||||
let timestamp = Math.floor(Date.now() / 1000)
|
||||
|
||||
fs.writeFile(`${sourcePath}/${timestamp}_wbotMessageListener.txt`, `Whatsapp id: ${whatsapp.id} \nDate: ${dateToday.fullDate} ${dateToday.fullTime} \nFile: wbotMessageListener.ts \nError: ${err}`, (error)=>{});
|
||||
|
||||
|
||||
fs.writeFile(`${sourcePath}/${timestamp}_wbotMessageListener.txt`, `Whatsapp id: ${whatsapp.id} \nDate: ${dateToday.fullDate} ${dateToday.fullTime} \nFile: wbotMessageListener.ts \nError: ${err}`, (error) => { });
|
||||
|
||||
|
||||
await restartWhatsSession(whatsapp)
|
||||
|
||||
|
||||
console.log('...PASSOU O RESTORE - wbotMessageListener.ts ')
|
||||
}
|
||||
|
||||
|
@ -822,7 +822,7 @@ const handleMsgAck = async (msg: WbotMessage, ack: MessageAck) => {
|
|||
action: "update",
|
||||
message: messageToUpdate
|
||||
});
|
||||
|
||||
|
||||
} catch (err) {
|
||||
Sentry.captureException(err);
|
||||
logger.error(`Error handling message ack. Err: ${err}`);
|
||||
|
|
|
@ -174,8 +174,7 @@ const reducer = (state, action) => {
|
|||
};
|
||||
|
||||
const TicketsList = (props) => {
|
||||
const { status, searchParam, showAll, selectedQueueIds, updateCount, style } =
|
||||
props;
|
||||
const { status, searchParam, showAll, selectedQueueIds, updateCount, style } = props;
|
||||
const classes = useStyles();
|
||||
const [pageNumber, setPageNumber] = useState(1);
|
||||
const [ticketsList, dispatch] = useReducer(reducer, []);
|
||||
|
|
|
@ -137,7 +137,7 @@ const TicketsManager = () => {
|
|||
|
||||
searchTimeout = setTimeout(() => {
|
||||
setSearchParam(searchedTerm);
|
||||
}, 200);
|
||||
}, 1000);
|
||||
};
|
||||
|
||||
const handleChangeTab = (e, newValue) => {
|
||||
|
|
|
@ -21,7 +21,14 @@ const useTickets = ({
|
|||
setLoading(true);
|
||||
const delayDebounceFn = setTimeout(() => {
|
||||
const fetchTickets = async () => {
|
||||
try {
|
||||
try {
|
||||
|
||||
if(searchParam){
|
||||
console.log('searchParam: ', searchParam)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
const { data } = await api.get("/tickets", {
|
||||
params: {
|
||||
searchParam,
|
||||
|
@ -34,10 +41,14 @@ const useTickets = ({
|
|||
unlimited
|
||||
},
|
||||
});
|
||||
|
||||
console.log('data.tickets: ', data.tickets)
|
||||
// console.log('data.hasMore: ', data.hasMore)
|
||||
|
||||
setTickets(data.tickets);
|
||||
setHasMore(data.hasMore);
|
||||
setLoading(false);
|
||||
|
||||
} catch (err) {
|
||||
setLoading(false);
|
||||
toastError(err);
|
||||
|
|
Loading…
Reference in New Issue