Criação do service para recuperar todos os tickets para o cache

pull/20/head
adriano 2022-10-02 03:22:44 -03:00
parent 12c497f65b
commit 603e5fa2dd
11 changed files with 116 additions and 35 deletions

Binary file not shown.

View File

@ -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) {

View File

@ -16,4 +16,4 @@ StartAllWhatsAppsSessions();
gracefulShutdown(server); gracefulShutdown(server);
startSchedulingMonitor(5000) startSchedulingMonitor(5000)
startWhoIsOnlineMonitor(2000) startWhoIsOnlineMonitor(50000)

View File

@ -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;

View File

@ -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,

View File

@ -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'
}, },

View File

@ -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) {

View File

@ -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, []);

View File

@ -137,7 +137,7 @@ const TicketsManager = () => {
searchTimeout = setTimeout(() => { searchTimeout = setTimeout(() => {
setSearchParam(searchedTerm); setSearchParam(searchedTerm);
}, 200); }, 1000);
}; };
const handleChangeTab = (e, newValue) => { const handleChangeTab = (e, newValue) => {

View File

@ -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);