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) {
|
if (countTest == 0) {
|
||||||
try {
|
try {
|
||||||
console.log(' Carregando usuárion no listUserId...')
|
console.log(' Carregando usuarios no listUserId...')
|
||||||
listUserId = await ListUserParamiterService({ profile: 'user' })
|
listUserId = await ListUserParamiterService({ profile: 'user' })
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
@ -16,4 +16,4 @@ StartAllWhatsAppsSessions();
|
||||||
gracefulShutdown(server);
|
gracefulShutdown(server);
|
||||||
|
|
||||||
startSchedulingMonitor(5000)
|
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";
|
import { splitDateTime } from "../../helpers/SplitDateTime";
|
||||||
const dateToday = splitDateTime(new Date(format(new Date(), 'yyyy-MM-dd HH:mm:ss', { locale: ptBR })))
|
const dateToday = splitDateTime(new Date(format(new Date(), 'yyyy-MM-dd HH:mm:ss', { locale: ptBR })))
|
||||||
|
|
||||||
|
import ListTicketServiceCache from "./ListTicketServiceCache"
|
||||||
|
|
||||||
|
|
||||||
interface Request {
|
interface Request {
|
||||||
searchParam?: string;
|
searchParam?: string;
|
||||||
|
@ -48,6 +50,11 @@ const ListTicketsService = async ({
|
||||||
let includeCondition: Includeable[];
|
let includeCondition: Includeable[];
|
||||||
|
|
||||||
|
|
||||||
|
// test del
|
||||||
|
// const test = await ListTicketServiceCache()
|
||||||
|
// console.log('TEST:\n', test)
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
includeCondition = [
|
includeCondition = [
|
||||||
{
|
{
|
||||||
|
@ -90,7 +97,7 @@ const ListTicketsService = async ({
|
||||||
|
|
||||||
//othavio
|
//othavio
|
||||||
|
|
||||||
console.log('sanitizedSearchParam:'+ sanitizedSearchParam, ' | sanitizedSearchParam.length: ',sanitizedSearchParam.length)
|
console.log('sanitizedSearchParam:'+ sanitizedSearchParam, ' | date: ',date)
|
||||||
|
|
||||||
// includeCondition = [
|
// includeCondition = [
|
||||||
// ...includeCondition,
|
// ...includeCondition,
|
||||||
|
@ -144,6 +151,9 @@ const ListTicketsService = async ({
|
||||||
const limit = unlimited === 'true' ? 100000 : 40;
|
const limit = unlimited === 'true' ? 100000 : 40;
|
||||||
const offset = limit * (+pageNumber - 1);
|
const offset = limit * (+pageNumber - 1);
|
||||||
|
|
||||||
|
|
||||||
|
// console.log('whereCondition: ', JSON.stringify(whereCondition))
|
||||||
|
|
||||||
const { count, rows: tickets } = await Ticket.findAndCountAll({
|
const { count, rows: tickets } = await Ticket.findAndCountAll({
|
||||||
where: whereCondition,
|
where: whereCondition,
|
||||||
include: includeCondition,
|
include: includeCondition,
|
||||||
|
@ -155,6 +165,8 @@ const ListTicketsService = async ({
|
||||||
|
|
||||||
const hasMore = count > offset + tickets.length;
|
const hasMore = count > offset + tickets.length;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
tickets,
|
tickets,
|
||||||
count,
|
count,
|
||||||
|
|
|
@ -42,7 +42,7 @@ const ShowTicketReport = async ({
|
||||||
|
|
||||||
if(userId=='0'){
|
if(userId=='0'){
|
||||||
where_clause = {
|
where_clause = {
|
||||||
createdAt: {
|
updatedAt: {
|
||||||
[Op.gte]: startDate+' 00:00:00.000000',
|
[Op.gte]: startDate+' 00:00:00.000000',
|
||||||
[Op.lte]: endDate +' 23:59:59.999999'
|
[Op.lte]: endDate +' 23:59:59.999999'
|
||||||
},
|
},
|
||||||
|
@ -51,7 +51,7 @@ const ShowTicketReport = async ({
|
||||||
else{
|
else{
|
||||||
where_clause = {
|
where_clause = {
|
||||||
userid: userId,
|
userid: userId,
|
||||||
createdAt: {
|
updatedAt: {
|
||||||
[Op.gte]: startDate+' 00:00:00.000000',
|
[Op.gte]: startDate+' 00:00:00.000000',
|
||||||
[Op.lte]: endDate +' 23:59:59.999999'
|
[Op.lte]: endDate +' 23:59:59.999999'
|
||||||
},
|
},
|
||||||
|
|
|
@ -59,15 +59,7 @@ const SendWhatsAppMessage = async ({
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const sentMessage = await wbot.sendMessage(
|
const sentMessage = await wbot.sendMessage(`${ticket.contact.number}@${ticket.isGroup ? "g" : "c"}.us`, body, { quotedMessageId: quotedMsgSerializedId, linkPreview: false });
|
||||||
`${ticket.contact.number}@${ticket.isGroup ? "g" : "c"}.us`,
|
|
||||||
body,
|
|
||||||
{
|
|
||||||
quotedMessageId: quotedMsgSerializedId,
|
|
||||||
linkPreview: false
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
await ticket.update({ lastMessage: body });
|
await ticket.update({ lastMessage: body });
|
||||||
return sentMessage;
|
return sentMessage;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
|
@ -188,7 +188,7 @@ const verifyQueue = async (
|
||||||
|
|
||||||
//Habilitar esse caso queira usar o bot
|
//Habilitar esse caso queira usar o bot
|
||||||
// const botInfo = await BotIsOnQueue('botqueue')
|
// const botInfo = await BotIsOnQueue('botqueue')
|
||||||
const botInfo = {isOnQueue: false, botQueueId: 0, userIdBot: 0}
|
const botInfo = { isOnQueue: false, botQueueId: 0, userIdBot: 0 }
|
||||||
|
|
||||||
if (botInfo.isOnQueue) {
|
if (botInfo.isOnQueue) {
|
||||||
|
|
||||||
|
@ -427,7 +427,7 @@ const handleMessage = async (
|
||||||
// Para responder para o cliente pelo mesmo whatsapp que ele enviou a mensagen
|
// Para responder para o cliente pelo mesmo whatsapp que ele enviou a mensagen
|
||||||
if (wbot.id != ticket.whatsappId) {
|
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 });
|
await ticket.update({ whatsappId: wbot.id });
|
||||||
}
|
}
|
||||||
|
@ -458,7 +458,7 @@ const handleMessage = async (
|
||||||
|
|
||||||
//Habilitar esse caso queira usar o bot
|
//Habilitar esse caso queira usar o bot
|
||||||
// const botInfo = await BotIsOnQueue('botqueue')
|
// 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) {
|
if (botInfo.isOnQueue && !msg.fromMe && ticket.userId == botInfo.userIdBot) {
|
||||||
|
|
||||||
|
@ -771,7 +771,7 @@ const handleMessage = async (
|
||||||
//Solução para contornar erro de sessão
|
//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');
|
let log = new Date(new Date() + 'UTC');
|
||||||
const dateToday = splitDateTime(new Date(format(new Date(), 'yyyy-MM-dd HH:mm:ss', { locale: ptBR })))
|
const dateToday = splitDateTime(new Date(format(new Date(), 'yyyy-MM-dd HH:mm:ss', { locale: ptBR })))
|
||||||
|
@ -784,7 +784,7 @@ const handleMessage = async (
|
||||||
|
|
||||||
let timestamp = Math.floor(Date.now() / 1000)
|
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)
|
await restartWhatsSession(whatsapp)
|
||||||
|
|
|
@ -174,8 +174,7 @@ const reducer = (state, action) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const TicketsList = (props) => {
|
const TicketsList = (props) => {
|
||||||
const { status, searchParam, showAll, selectedQueueIds, updateCount, style } =
|
const { status, searchParam, showAll, selectedQueueIds, updateCount, style } = props;
|
||||||
props;
|
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const [pageNumber, setPageNumber] = useState(1);
|
const [pageNumber, setPageNumber] = useState(1);
|
||||||
const [ticketsList, dispatch] = useReducer(reducer, []);
|
const [ticketsList, dispatch] = useReducer(reducer, []);
|
||||||
|
|
|
@ -137,7 +137,7 @@ const TicketsManager = () => {
|
||||||
|
|
||||||
searchTimeout = setTimeout(() => {
|
searchTimeout = setTimeout(() => {
|
||||||
setSearchParam(searchedTerm);
|
setSearchParam(searchedTerm);
|
||||||
}, 200);
|
}, 1000);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleChangeTab = (e, newValue) => {
|
const handleChangeTab = (e, newValue) => {
|
||||||
|
|
|
@ -22,6 +22,13 @@ const useTickets = ({
|
||||||
const delayDebounceFn = setTimeout(() => {
|
const delayDebounceFn = setTimeout(() => {
|
||||||
const fetchTickets = async () => {
|
const fetchTickets = async () => {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
if(searchParam){
|
||||||
|
console.log('searchParam: ', searchParam)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const { data } = await api.get("/tickets", {
|
const { data } = await api.get("/tickets", {
|
||||||
params: {
|
params: {
|
||||||
searchParam,
|
searchParam,
|
||||||
|
@ -35,9 +42,13 @@ const useTickets = ({
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log('data.tickets: ', data.tickets)
|
||||||
|
// console.log('data.hasMore: ', data.hasMore)
|
||||||
|
|
||||||
setTickets(data.tickets);
|
setTickets(data.tickets);
|
||||||
setHasMore(data.hasMore);
|
setHasMore(data.hasMore);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
toastError(err);
|
toastError(err);
|
||||||
|
|
Loading…
Reference in New Issue