fix: Correct search queries in the report and fix bugs in WhatsApp template sending
parent
c4eda756eb
commit
8ca5b4503a
|
@ -97,7 +97,7 @@ export const store = async (req: Request, res: Response): Promise<Response> => {
|
|||
}
|
||||
|
||||
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;
|
||||
|
||||
|
@ -110,9 +110,10 @@ export const store = async (req: Request, res: Response): Promise<Response> => {
|
|||
}
|
||||
};
|
||||
|
||||
console.log("TEMPLATE: ", template);
|
||||
|
||||
sendWhatsAppMessageOfficialAPI(ticket, body, null, template);
|
||||
|
||||
console.log("TEMPLATE: ", template);
|
||||
return res.send();
|
||||
}
|
||||
} catch (error: any) {
|
||||
|
|
|
@ -68,6 +68,8 @@ export const reportUserByDateStartDateEnd = async (
|
|||
queueId
|
||||
);
|
||||
|
||||
// return res.status(200).json({ tickets:[], count:0, hasMore:false, queues:[] });
|
||||
|
||||
const { tickets, count, hasMore } = await ShowTicketReport({
|
||||
userId,
|
||||
startDate,
|
||||
|
|
|
@ -40,18 +40,26 @@ const ShowTicketReport = async ({
|
|||
createdOrUpdated = "created",
|
||||
queueId
|
||||
}: Request): Promise<Response> => {
|
||||
let where_clause = {};
|
||||
let where_clause: any = {};
|
||||
// let where_clause_msg: any = {};
|
||||
|
||||
if (userId == "0") {
|
||||
if (createdOrUpdated == "updated") {
|
||||
if (userId !== "0") {
|
||||
where_clause.userid = userId;
|
||||
}
|
||||
|
||||
if (createdOrUpdated === "updated") {
|
||||
where_clause = {
|
||||
...where_clause,
|
||||
updatedAt: {
|
||||
[Op.gte]: startDate + " 00:00:00.000000",
|
||||
[Op.lte]: endDate + " 23:59:59.999999"
|
||||
}
|
||||
};
|
||||
} else if (createdOrUpdated == "created") {
|
||||
}
|
||||
|
||||
if (createdOrUpdated === "created") {
|
||||
where_clause = {
|
||||
...where_clause,
|
||||
createdAt: {
|
||||
[Op.gte]: startDate + " 00:00:00.000000",
|
||||
[Op.lte]: endDate + " 23:59:59.999999"
|
||||
|
@ -59,27 +67,10 @@ const ShowTicketReport = async ({
|
|||
};
|
||||
}
|
||||
|
||||
let { userid, ...where_clause_msg } = where_clause;
|
||||
|
||||
if (queueId) {
|
||||
where_clause = { ...where_clause, queueId };
|
||||
}
|
||||
} else {
|
||||
if (createdOrUpdated == "updated") {
|
||||
where_clause = {
|
||||
userid: userId,
|
||||
updatedAt: {
|
||||
[Op.gte]: startDate + " 00:00:00.000000",
|
||||
[Op.lte]: endDate + " 23:59:59.999999"
|
||||
}
|
||||
};
|
||||
} else if (createdOrUpdated == "created") {
|
||||
where_clause = {
|
||||
userid: userId,
|
||||
createdAt: {
|
||||
[Op.gte]: startDate + " 00:00:00.000000",
|
||||
[Op.lte]: endDate + " 23:59:59.999999"
|
||||
}
|
||||
};
|
||||
}
|
||||
where_clause.queueId = queueId;
|
||||
}
|
||||
|
||||
const limit = 40;
|
||||
|
@ -89,7 +80,6 @@ const ShowTicketReport = async ({
|
|||
where: where_clause,
|
||||
limit,
|
||||
offset,
|
||||
//attributes: ['id', 'status', 'createdAt', 'updatedAt'],
|
||||
|
||||
attributes: [
|
||||
"id",
|
||||
|
@ -118,8 +108,7 @@ const ShowTicketReport = async ({
|
|||
model: Message,
|
||||
required: true,
|
||||
separate: true,
|
||||
|
||||
// attributes: ['body', 'read', 'mediaType','fromMe', 'mediaUrl','createdAt'],
|
||||
where: where_clause_msg ,
|
||||
|
||||
attributes: [
|
||||
"body",
|
||||
|
@ -136,7 +125,6 @@ const ShowTicketReport = async ({
|
|||
"createdAt"
|
||||
]
|
||||
],
|
||||
|
||||
order: [["createdAt", "ASC"]]
|
||||
},
|
||||
{
|
||||
|
@ -156,7 +144,6 @@ const ShowTicketReport = async ({
|
|||
attributes: ["name"]
|
||||
}
|
||||
],
|
||||
|
||||
order: [["updatedAt", "DESC"]]
|
||||
});
|
||||
|
||||
|
|
|
@ -350,6 +350,8 @@ const MessageInput = ({ ticketStatus }) => {
|
|||
|
||||
try {
|
||||
|
||||
console.log('kkkkkkkkkkkkkkkkkkk message: ', message)
|
||||
|
||||
const { data } = await api.post(`/messages/${ticketId}`, message)
|
||||
setParams(null)
|
||||
if (data && data?.data && Array.isArray(data.data)) {
|
||||
|
@ -371,7 +373,11 @@ const MessageInput = ({ ticketStatus }) => {
|
|||
|
||||
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
|
||||
|
||||
|
|
|
@ -16,6 +16,8 @@ const ModalTemplate = ({ templates, modal_header, func }) => {
|
|||
|
||||
templates = [{}, ...templates]
|
||||
|
||||
// console.log('TEMPLATES: ', templates)
|
||||
|
||||
const [open, setOpen] = useState(true)
|
||||
const [scroll, /*setScroll*/] = useState('body')
|
||||
const [templateId, setTemplateId] = useState(null)
|
||||
|
@ -34,7 +36,25 @@ const ModalTemplate = ({ templates, modal_header, func }) => {
|
|||
const handleChatEnd = () => {
|
||||
|
||||
console.log('PARAMS TO SEND TO MESSAGE INPUT: ', 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)
|
||||
}
|
||||
|
||||
|
@ -127,7 +147,9 @@ const ModalTemplate = ({ templates, modal_header, func }) => {
|
|||
|
||||
useEffect(() => {
|
||||
console.log('---------> PARAMS: ', params)
|
||||
}, [params])
|
||||
console.log('---------> templateComponents: ', templateComponents)
|
||||
|
||||
}, [params, templateComponents])
|
||||
|
||||
const dinamicTextField = (replicateItems, func, type, text, language) => {
|
||||
|
||||
|
@ -204,7 +226,7 @@ const ModalTemplate = ({ templates, modal_header, func }) => {
|
|||
{text &&
|
||||
<div style={{ margin: 0, padding: 0, 'marginBottom': '15px' }}>
|
||||
<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>}
|
||||
{buttons && <div>{buttons.map((b) => {
|
||||
const { type, text, url } = b
|
||||
|
|
|
@ -515,6 +515,7 @@ const Report = () => {
|
|||
identifier: 'csv'
|
||||
},
|
||||
query_params: {
|
||||
queueId: queueId,
|
||||
userId: userId,
|
||||
startDate: startDate,
|
||||
endDate: endDate
|
||||
|
|
Loading…
Reference in New Issue