fix: Correct search queries in the report and fix bugs in WhatsApp template sending
parent
c4eda756eb
commit
8ca5b4503a
|
@ -76,7 +76,7 @@ export const store = async (req: Request, res: Response): Promise<Response> => {
|
||||||
|
|
||||||
let payloadComponents = [];
|
let payloadComponents = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (let i in params) {
|
for (let i in params) {
|
||||||
const { parameters, language, type } = params[i];
|
const { parameters, language, type } = params[i];
|
||||||
if (type == "BODY") {
|
if (type == "BODY") {
|
||||||
|
@ -97,7 +97,7 @@ export const store = async (req: Request, res: Response): Promise<Response> => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const name = params.find((p: any) => p?.template_name);
|
const name = params.find((p: any) => p?.template_name);
|
||||||
const { language }: any = params.find((p: any) => p?.language);
|
const { language }: any = params?.find((p: any) => p?.language) || 'pt_BR'
|
||||||
|
|
||||||
const { template_name } = name;
|
const { template_name } = name;
|
||||||
|
|
||||||
|
@ -110,9 +110,10 @@ export const store = async (req: Request, res: Response): Promise<Response> => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
console.log("TEMPLATE: ", template);
|
||||||
|
|
||||||
sendWhatsAppMessageOfficialAPI(ticket, body, null, template);
|
sendWhatsAppMessageOfficialAPI(ticket, body, null, template);
|
||||||
|
|
||||||
console.log("TEMPLATE: ", template);
|
|
||||||
return res.send();
|
return res.send();
|
||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
|
|
|
@ -68,6 +68,8 @@ export const reportUserByDateStartDateEnd = async (
|
||||||
queueId
|
queueId
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// return res.status(200).json({ tickets:[], count:0, hasMore:false, queues:[] });
|
||||||
|
|
||||||
const { tickets, count, hasMore } = await ShowTicketReport({
|
const { tickets, count, hasMore } = await ShowTicketReport({
|
||||||
userId,
|
userId,
|
||||||
startDate,
|
startDate,
|
||||||
|
|
|
@ -40,46 +40,37 @@ const ShowTicketReport = async ({
|
||||||
createdOrUpdated = "created",
|
createdOrUpdated = "created",
|
||||||
queueId
|
queueId
|
||||||
}: Request): Promise<Response> => {
|
}: Request): Promise<Response> => {
|
||||||
let where_clause = {};
|
let where_clause: any = {};
|
||||||
|
// let where_clause_msg: any = {};
|
||||||
|
|
||||||
if (userId == "0") {
|
if (userId !== "0") {
|
||||||
if (createdOrUpdated == "updated") {
|
where_clause.userid = userId;
|
||||||
where_clause = {
|
}
|
||||||
updatedAt: {
|
|
||||||
[Op.gte]: startDate + " 00:00:00.000000",
|
|
||||||
[Op.lte]: endDate + " 23:59:59.999999"
|
|
||||||
}
|
|
||||||
};
|
|
||||||
} else if (createdOrUpdated == "created") {
|
|
||||||
where_clause = {
|
|
||||||
createdAt: {
|
|
||||||
[Op.gte]: startDate + " 00:00:00.000000",
|
|
||||||
[Op.lte]: endDate + " 23:59:59.999999"
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (queueId) {
|
if (createdOrUpdated === "updated") {
|
||||||
where_clause = { ...where_clause, queueId };
|
where_clause = {
|
||||||
}
|
...where_clause,
|
||||||
} else {
|
updatedAt: {
|
||||||
if (createdOrUpdated == "updated") {
|
[Op.gte]: startDate + " 00:00:00.000000",
|
||||||
where_clause = {
|
[Op.lte]: endDate + " 23:59:59.999999"
|
||||||
userid: userId,
|
}
|
||||||
updatedAt: {
|
};
|
||||||
[Op.gte]: startDate + " 00:00:00.000000",
|
}
|
||||||
[Op.lte]: endDate + " 23:59:59.999999"
|
|
||||||
}
|
if (createdOrUpdated === "created") {
|
||||||
};
|
where_clause = {
|
||||||
} else if (createdOrUpdated == "created") {
|
...where_clause,
|
||||||
where_clause = {
|
createdAt: {
|
||||||
userid: userId,
|
[Op.gte]: startDate + " 00:00:00.000000",
|
||||||
createdAt: {
|
[Op.lte]: endDate + " 23:59:59.999999"
|
||||||
[Op.gte]: startDate + " 00:00:00.000000",
|
}
|
||||||
[Op.lte]: endDate + " 23:59:59.999999"
|
};
|
||||||
}
|
}
|
||||||
};
|
|
||||||
}
|
let { userid, ...where_clause_msg } = where_clause;
|
||||||
|
|
||||||
|
if (queueId) {
|
||||||
|
where_clause.queueId = queueId;
|
||||||
}
|
}
|
||||||
|
|
||||||
const limit = 40;
|
const limit = 40;
|
||||||
|
@ -89,7 +80,6 @@ const ShowTicketReport = async ({
|
||||||
where: where_clause,
|
where: where_clause,
|
||||||
limit,
|
limit,
|
||||||
offset,
|
offset,
|
||||||
//attributes: ['id', 'status', 'createdAt', 'updatedAt'],
|
|
||||||
|
|
||||||
attributes: [
|
attributes: [
|
||||||
"id",
|
"id",
|
||||||
|
@ -118,8 +108,7 @@ const ShowTicketReport = async ({
|
||||||
model: Message,
|
model: Message,
|
||||||
required: true,
|
required: true,
|
||||||
separate: true,
|
separate: true,
|
||||||
|
where: where_clause_msg ,
|
||||||
// attributes: ['body', 'read', 'mediaType','fromMe', 'mediaUrl','createdAt'],
|
|
||||||
|
|
||||||
attributes: [
|
attributes: [
|
||||||
"body",
|
"body",
|
||||||
|
@ -136,7 +125,6 @@ const ShowTicketReport = async ({
|
||||||
"createdAt"
|
"createdAt"
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
|
||||||
order: [["createdAt", "ASC"]]
|
order: [["createdAt", "ASC"]]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -155,11 +143,10 @@ const ShowTicketReport = async ({
|
||||||
model: Whatsapp,
|
model: Whatsapp,
|
||||||
attributes: ["name"]
|
attributes: ["name"]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
||||||
order: [["updatedAt", "DESC"]]
|
order: [["updatedAt", "DESC"]]
|
||||||
});
|
});
|
||||||
|
|
||||||
const hasMore = count > offset + tickets.length;
|
const hasMore = count > offset + tickets.length;
|
||||||
|
|
||||||
if (!tickets) {
|
if (!tickets) {
|
||||||
|
|
|
@ -350,6 +350,8 @@ const MessageInput = ({ ticketStatus }) => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
console.log('kkkkkkkkkkkkkkkkkkk message: ', message)
|
||||||
|
|
||||||
const { data } = await api.post(`/messages/${ticketId}`, message)
|
const { data } = await api.post(`/messages/${ticketId}`, message)
|
||||||
setParams(null)
|
setParams(null)
|
||||||
if (data && data?.data && Array.isArray(data.data)) {
|
if (data && data?.data && Array.isArray(data.data)) {
|
||||||
|
@ -371,7 +373,11 @@ const MessageInput = ({ ticketStatus }) => {
|
||||||
|
|
||||||
if (!params) return
|
if (!params) return
|
||||||
|
|
||||||
const body_params = params.find(p => p?.type === 'BODY')
|
const body_params = params?.find(p => p?.type === 'BODY')
|
||||||
|
|
||||||
|
console.log('------------> body_params: ', body_params)
|
||||||
|
|
||||||
|
if(!body_params) return
|
||||||
|
|
||||||
let { text } = body_params
|
let { text } = body_params
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
|
|
||||||
import React, { useState, useEffect, useRef, } from 'react'
|
import React, { useState, useEffect, useRef, } from 'react'
|
||||||
import Button from '@mui/material/Button'
|
import Button from '@mui/material/Button'
|
||||||
import Dialog from '@mui/material/Dialog'
|
import Dialog from '@mui/material/Dialog'
|
||||||
import DialogActions from '@mui/material/DialogActions'
|
import DialogActions from '@mui/material/DialogActions'
|
||||||
import DialogContent from '@mui/material/DialogContent'
|
import DialogContent from '@mui/material/DialogContent'
|
||||||
import DialogContentText from '@mui/material/DialogContentText'
|
import DialogContentText from '@mui/material/DialogContentText'
|
||||||
import DialogTitle from '@mui/material/DialogTitle'
|
import DialogTitle from '@mui/material/DialogTitle'
|
||||||
import SelectField from "../Report/SelectField"
|
import SelectField from "../Report/SelectField"
|
||||||
|
|
||||||
import TextField from '@mui/material/TextField'
|
import TextField from '@mui/material/TextField'
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,12 +16,14 @@ const ModalTemplate = ({ templates, modal_header, func }) => {
|
||||||
|
|
||||||
templates = [{}, ...templates]
|
templates = [{}, ...templates]
|
||||||
|
|
||||||
|
// console.log('TEMPLATES: ', templates)
|
||||||
|
|
||||||
const [open, setOpen] = useState(true)
|
const [open, setOpen] = useState(true)
|
||||||
const [scroll, /*setScroll*/] = useState('body')
|
const [scroll, /*setScroll*/] = useState('body')
|
||||||
const [templateId, setTemplateId] = useState(null)
|
const [templateId, setTemplateId] = useState(null)
|
||||||
const [templateComponents, setTemplateComponents] = useState(null)
|
const [templateComponents, setTemplateComponents] = useState(null)
|
||||||
const [language, setLanguage] = useState(null)
|
const [language, setLanguage] = useState(null)
|
||||||
const [params, setParams] = useState([])
|
const [params, setParams] = useState([])
|
||||||
|
|
||||||
const handleCancel = (event, reason) => {
|
const handleCancel = (event, reason) => {
|
||||||
|
|
||||||
|
@ -34,7 +36,25 @@ const ModalTemplate = ({ templates, modal_header, func }) => {
|
||||||
const handleChatEnd = () => {
|
const handleChatEnd = () => {
|
||||||
|
|
||||||
console.log('PARAMS TO SEND TO MESSAGE INPUT: ', params)
|
console.log('PARAMS TO SEND TO MESSAGE INPUT: ', params)
|
||||||
func(params)
|
console.log('templateComponents: ', templateComponents)
|
||||||
|
|
||||||
|
if (params && params.length === 1) {
|
||||||
|
|
||||||
|
const bodyObject = templateComponents.find(obj => obj?.type === 'BODY')
|
||||||
|
|
||||||
|
if (bodyObject) {
|
||||||
|
const { text } = bodyObject
|
||||||
|
func([...params, {
|
||||||
|
"type": "BODY",
|
||||||
|
"text": text,
|
||||||
|
"language": "pt_BR",
|
||||||
|
}])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
func(params)
|
||||||
|
}
|
||||||
|
|
||||||
setOpen(false)
|
setOpen(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,11 +120,11 @@ const ModalTemplate = ({ templates, modal_header, func }) => {
|
||||||
|
|
||||||
const handleTextChange = (value, index, type, text, language,) => {
|
const handleTextChange = (value, index, type, text, language,) => {
|
||||||
|
|
||||||
if (!params) return
|
if (!params) return
|
||||||
|
|
||||||
setParams((params) => {
|
setParams((params) => {
|
||||||
|
|
||||||
const _index = params.findIndex(({ type }) => type === 'BODY')
|
const _index = params.findIndex(({ type }) => type === 'BODY')
|
||||||
|
|
||||||
if (_index !== -1) {
|
if (_index !== -1) {
|
||||||
|
|
||||||
|
@ -127,7 +147,9 @@ const ModalTemplate = ({ templates, modal_header, func }) => {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log('---------> PARAMS: ', params)
|
console.log('---------> PARAMS: ', params)
|
||||||
}, [params])
|
console.log('---------> templateComponents: ', templateComponents)
|
||||||
|
|
||||||
|
}, [params, templateComponents])
|
||||||
|
|
||||||
const dinamicTextField = (replicateItems, func, type, text, language) => {
|
const dinamicTextField = (replicateItems, func, type, text, language) => {
|
||||||
|
|
||||||
|
@ -204,7 +226,7 @@ const ModalTemplate = ({ templates, modal_header, func }) => {
|
||||||
{text &&
|
{text &&
|
||||||
<div style={{ margin: 0, padding: 0, 'marginBottom': '15px' }}>
|
<div style={{ margin: 0, padding: 0, 'marginBottom': '15px' }}>
|
||||||
<p style={{ margin: 0, padding: 0, fontSize: 12 }}>{text}</p>
|
<p style={{ margin: 0, padding: 0, fontSize: 12 }}>{text}</p>
|
||||||
{type && (type === 'BODY') && dinamicTextField(body_params.length, handleTextChange, type, text, language)}
|
{type && (type === 'BODY') && body_params && dinamicTextField(body_params.length, handleTextChange, type, text, language)}
|
||||||
</div>}
|
</div>}
|
||||||
{buttons && <div>{buttons.map((b) => {
|
{buttons && <div>{buttons.map((b) => {
|
||||||
const { type, text, url } = b
|
const { type, text, url } = b
|
||||||
|
|
|
@ -419,11 +419,11 @@ const Report = () => {
|
||||||
|
|
||||||
|
|
||||||
// Get from report option
|
// Get from report option
|
||||||
const reportValue = (data) => {
|
const reportValue = (data) => {
|
||||||
if(data === '2'){
|
if (data === '2') {
|
||||||
setChecked(true)
|
setChecked(true)
|
||||||
}
|
}
|
||||||
setReport(data)
|
setReport(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -515,6 +515,7 @@ const Report = () => {
|
||||||
identifier: 'csv'
|
identifier: 'csv'
|
||||||
},
|
},
|
||||||
query_params: {
|
query_params: {
|
||||||
|
queueId: queueId,
|
||||||
userId: userId,
|
userId: userId,
|
||||||
startDate: startDate,
|
startDate: startDate,
|
||||||
endDate: endDate
|
endDate: endDate
|
||||||
|
@ -780,7 +781,7 @@ const Report = () => {
|
||||||
|
|
||||||
{reportOption === '1' &&
|
{reportOption === '1' &&
|
||||||
|
|
||||||
<>
|
<>
|
||||||
<MTable data={query}
|
<MTable data={query}
|
||||||
columns={userA.profile !== 'supervisor' ? columnsData : columnsDataSuper}
|
columns={userA.profile !== 'supervisor' ? columnsData : columnsDataSuper}
|
||||||
hasChild={true}
|
hasChild={true}
|
||||||
|
@ -788,7 +789,7 @@ const Report = () => {
|
||||||
|
|
||||||
handleScroll={handleScroll}
|
handleScroll={handleScroll}
|
||||||
|
|
||||||
table_title={i18n.t("reports.listTitles.title1_1")} />
|
table_title={i18n.t("reports.listTitles.title1_1")} />
|
||||||
</>
|
</>
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue