Ateração no pageNumber para evitar valores numericos vazios

pull/21/head
adriano 2022-12-20 21:28:41 -03:00
parent 397c18d80f
commit 2c8a901af3
4 changed files with 27 additions and 8 deletions

View File

@ -14,7 +14,7 @@ import GetProfilePicUrl from "../services/WbotServices/GetProfilePicUrl";
import AppError from "../errors/AppError";
import { searchContactCache, insertContactsCache } from '../helpers/ContactsCache'
import { searchContactCache, insertContactsCache, escapeCharCache } from '../helpers/ContactsCache'
import { off } from "process";
@ -39,15 +39,23 @@ interface ContactData {
export const index = async (req: Request, res: Response): Promise<Response> => {
let { searchParam, pageNumber } = req.query as IndexQuery;
console.log('PAGE NUMBER CONTACT: ', pageNumber)
if (pageNumber.trim().length == 0 || pageNumber === undefined) {
pageNumber = '1'
}
// TEST DEL
if (searchParam && searchParam.trim().length > 0 && process.env.CACHE) {
try {
console.log('QUERY CONTACTS FROM CACHE SEARCH PARAM: ', searchParam)
const offset = 20 * (+pageNumber - 1);
searchParam = searchParam.replace(/\s+/g, ' ').trim().toLowerCase();
console.log('QUERY CONTACTS FROM CACHE SEARCH PARAM: ', searchParam)
const data = await searchContactCache(searchParam, offset, 20)
if (data) {
@ -191,10 +199,10 @@ export const contacsBulkInsertOnQueue = async (req: Request, res: Response): Pro
file: file
}
});
if (process.env.CACHE && contacts_inserted) {
await insertContactsCache(contacts_inserted)
}

View File

@ -143,13 +143,15 @@ async function searchContactCache(search: string, offset: number, limit: number)
const removeExtraSpace = (str: string) => {
str = str.replace(/^\s+/g, '')
// str = str.replace(/^\s+/g, '')
return str.replace(/\s+/g, ' ')
}
const escapeCharCache = (str: string) => {
str = str.replace(/\s+/g,' ').trim().toLowerCase();
const pattern = /[\'|\"|\.|\,|\;|\<|\>|\{|\}|\[|\]|\"|\'|\=|\~|\*|\:|\#|\+|\^|\$|\@|\%|\!|\&|\)|\(|/|\-|\\)]/g; // no match, use replace function.
let newStr = str.replace(pattern, (t1) => `\\${t1}`);

View File

@ -53,13 +53,22 @@ const ListTicketsService = async ({
let whereCondition: Filterable["where"] = { [Op.or]: [{ userId }, { status: "pending" }], queueId: { [Op.or]: [queueIds, null] } };
console.log('PAGE NUMBER TICKET: ', pageNumber)
if (pageNumber.trim().length == 0) {
pageNumber = '1'
}
if (searchParam && searchParam.trim().length > 0 && process.env.CACHE) {
try {
const offset = 40 * (+pageNumber - 1);
console.log('QUERY TICKET SEARCH PARAM FROM CACHE: ', searchParam)
searchParam = searchParam.replace(/\s+/g, ' ').trim().toLowerCase();
console.log('QUERY TICKET SEARCH PARAM FROM CACHE: ', searchParam)
let tickets: any = await searchTicketCache(searchParam, offset, 40);

View File

@ -38,7 +38,7 @@ const SendWhatsAppMessage = async ({
quotedMsg
}: Request): Promise<WbotMessage> => {
var timetaken = "####### Time taken to send message";
var timetaken = `######################################## TicketId: ${ticket.id} => Time taken to send the message`;
console.time(timetaken)