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) {
try {
console.log(' Carregando usuárion no listUserId...')
console.log(' Carregando usuarios no listUserId...')
listUserId = await ListUserParamiterService({ profile: 'user' })
} catch (error) {

View File

@ -16,4 +16,4 @@ StartAllWhatsAppsSessions();
gracefulShutdown(server);
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";
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,

View File

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

View File

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

View File

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

View File

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

View File

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