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;
|
||||
|
@ -48,6 +50,11 @@ const ListTicketsService = async ({
|
|||
let includeCondition: Includeable[];
|
||||
|
||||
|
||||
// test del
|
||||
// const test = await ListTicketServiceCache()
|
||||
// console.log('TEST:\n', test)
|
||||
//
|
||||
|
||||
|
||||
includeCondition = [
|
||||
{
|
||||
|
@ -90,7 +97,7 @@ const ListTicketsService = async ({
|
|||
|
||||
//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) {
|
||||
|
||||
|
@ -427,7 +427,7 @@ const handleMessage = async (
|
|||
// 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 });
|
||||
}
|
||||
|
@ -458,7 +458,7 @@ const handleMessage = 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 && !msg.fromMe && ticket.userId == botInfo.userIdBot) {
|
||||
|
||||
|
@ -771,7 +771,7 @@ const handleMessage = async (
|
|||
//Solução para contornar erro de sessão
|
||||
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 })))
|
||||
|
@ -784,7 +784,7 @@ const handleMessage = async (
|
|||
|
||||
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)
|
||||
|
|
|
@ -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) => {
|
||||
|
|
|
@ -22,6 +22,13 @@ const useTickets = ({
|
|||
const delayDebounceFn = setTimeout(() => {
|
||||
const fetchTickets = async () => {
|
||||
try {
|
||||
|
||||
if(searchParam){
|
||||
console.log('searchParam: ', searchParam)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
const { data } = await api.get("/tickets", {
|
||||
params: {
|
||||
searchParam,
|
||||
|
@ -35,9 +42,13 @@ const useTickets = ({
|
|||
},
|
||||
});
|
||||
|
||||
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