CSV eport all em desenvolvimento

pull/20/head
adriano 2022-08-16 16:40:59 -03:00
parent 579cb680fb
commit fe66707827
2 changed files with 20 additions and 6 deletions

View File

@ -229,7 +229,21 @@ export const reportMessagesUserByDateStartDateEnd = async (req: Request, res: Re
const { userId, startDate, endDate } = req.query as IndexQuery
const data_query_messages = await ShowMessageReport(userId, startDate, endDate);
let data_query_messages = await ShowMessageReport(userId, startDate, endDate);
for (var i = 0; i < data_query_messages.length; i++) {
if (data_query_messages[i].fromMe) {
data_query_messages[i].fromMe = 'Atendente'
}
else {
data_query_messages[i].fromMe = 'Cliente'
}
data_query_messages[i].id = (i+1)
console.log('data_query_messages: ', data_query_messages[i])
}
return res.status(200).json(data_query_messages);

View File

@ -17,7 +17,7 @@ import { string } from "yup/lib/locale";
import Whatsapp from "../../models/Whatsapp";
//Report by user, startDate, endDate
const ShowMessageReport = async (id: string | number, startDate: string, endDate: string): Promise<Message[]> => {
const ShowMessageReport = async (id: string | number, startDate: string, endDate: string): Promise<any[]> => {
let where_clause_user = {}
@ -51,7 +51,7 @@ const ShowMessageReport = async (id: string | number, startDate: string, endDate
const messages = await Message.findAll({
where: where_clause ,
raw: true,
attributes: ['id', 'body', 'read', 'mediaType','fromMe', 'mediaUrl', [Sequelize.fn("DATE_FORMAT",Sequelize.col("Message.createdAt"),"%d/%m/%Y %H:%i:%s"),"createdAt"]],
include: [