Merge branch 'testeA'

pull/1/head
adriano 2022-01-26 00:38:36 -03:00
commit 09cbd542d2
5 changed files with 81 additions and 88 deletions

View File

@ -9,7 +9,7 @@ const reportRoutes = express.Router();
//reportRoutes.get("/reports/:userId", /*isAuth,*/ ReportController.reportUser);
reportRoutes.get("/reports", /*isAuth,*/ ReportController.reportUserByDateStartDateEnd);
reportRoutes.get("/reports", /*isAuth,*/ ReportController.reportUserByDateStartDateEnd);
//reportRoutes.get("/reports", /*isAuth,*/ ReportController.reportAll);

View File

@ -7,37 +7,58 @@ import Queue from "../../models/Queue";
import Message from "../../models/Message";
import { userInfo } from "os";
import { Op } from "sequelize";
import { Op, where } from "sequelize";
import { Sequelize } from "sequelize";
import moment from 'moment';
import { startOfDay, endOfDay, parseISO, getDate} from "date-fns";
import { string } from "yup/lib/locale";
//Report by user, startDate, endDate
const ShowTicketReport = async (id: string | number, startDate: string, endDate: string): Promise<Ticket[]> => {
let where_clause = {}
const ticket = await Ticket.findAll({
where: {
userid: id,
//createdAt: {
// [Op.between]: [+new Date('2022-01-24').toISOString(), +new Date().toISOString()]
//},
if(id=='0'){
where_clause = {
createdAt: {
[Op.gte]: startDate+' 00:00:00.000000',
[Op.lte]: endDate +' 23:59:59.999999'
}
},
}
}
else{
where_clause = {
userid: id,
createdAt: {
[Op.gte]: startDate+' 00:00:00.000000',
[Op.lte]: endDate +' 23:59:59.999999'
},
}
}
},
const ticket = await Ticket.findAll({
where: where_clause ,
//attributes: ['id', 'status', 'createdAt', 'updatedAt'],
attributes: ['id', 'status', [Sequelize.fn("DATE_FORMAT",Sequelize.col("Ticket.createdAt"),"%d/%m/%Y %H:%i:%s"),"createdAt"],
[Sequelize.fn("DATE_FORMAT",Sequelize.col("Ticket.updatedAt"),"%d/%m/%Y %H:%i:%s"),"updatedAt"]],
attributes: ['id', 'status', 'createdAt', 'updatedAt'],
include: [
{
model: Message,
required:true,
separate: true,
attributes: ['body', 'read', 'mediaType','fromMe', 'mediaUrl','createdAt'],
// attributes: ['body', 'read', 'mediaType','fromMe', 'mediaUrl','createdAt'],
attributes: ['body', 'read', 'mediaType','fromMe', 'mediaUrl', [Sequelize.fn("DATE_FORMAT",Sequelize.col("createdAt"),"%d/%m/%Y %H:%i:%s"),"createdAt"]],
order: [
['createdAt', 'ASC']
]

View File

@ -8,15 +8,11 @@ import React from 'react';
const MTable = (props) => {
const [selectedRow, setSelectedRow] = useState(null);
console.log('rederizou....................: ',props.data)
const [selectedRow, setSelectedRow] = useState(null);
const dataLoad = props.data.map((dt) => { return { ...dt }});
const columnsLoad = props.columns.map((column) => { return { ...column }});
console.log('dataLoad....................: ',dataLoad)
console.log('columnsLoad....................: ',columnsLoad)
const columnsLoad = props.columns.map((column) => { return { ...column }});
useEffect(() => {
@ -29,7 +25,8 @@ const MTable = (props) => {
<MaterialTable
title='Relatorio'
columns={columnsLoad}
data={dataLoad}
data={dataLoad}
onRowClick={(evt, selectedRow) => {
@ -47,7 +44,9 @@ const MTable = (props) => {
options={{
search: true,
selection: false,
paging: false,
paging: false,
padding: 'dense',
//loadingType: 'linear',
searchFieldStyle: {
width: 300,
},

View File

@ -6,75 +6,46 @@ import DialogActions from '@mui/material/DialogActions';
import DataGridTable from '../Table';
import MTable from "../MTable";
//let columns = [{ title: 'Chat', field: 'messages.body' },];
// { title: 'Atendente', field: 'user.name' },
const columns = [
{ field: 'id',
title: 'ID',
width: 50,
sortable: false},
let columns = [
{
field: 'fromMe',
title: 'user/client',
type: 'bool',
width: 100,
flex: 1,
editable: false,
sortable: false
},
{
field: 'body',
title: 'message',
type: 'string',
//width: 150,
flex: 1,
editable: false,
sortable: false
title: 'Atendente/Cliente',
field: 'fromMe',
},
/* {
field: 'mediaType',
headerName: 'media type',
//width: 110,
flex: 1,
editable: false,
},
{
field: 'mediaUrl',
headerName: 'media url',
type: 'string',
//width: 110,
flex: 1,
editable: false,
},
{
field: 'read',
headerName: 'tead',
type: 'bool',
//width: 110,
flex: 1,
editable: false,
},*/
{
field: 'createdAt',
title: 'created at',
type: 'dateTime',
//width: 110,
flex: 1,
editable: false,
sortable: false
}
title: 'Mensagem',
field: 'body',
cellStyle: {whiteSpace: 'nowrap'},
},
{ title: 'Criado', field: 'createdAt' }
/*cellStyle: {
backgroundColor: '#039be5',
color: '#FFF'
},
headerStyle: {
backgroundColor: '#039be5',
fontSize: 12
}*/
]
];
const Modal = (props) => {
const [open, setOpen] = React.useState(true);
const [scroll, setScroll] = React.useState('paper');
const dataChat = props.data.map((dt) => {
return {
'fromMe': dt.fromMe ? 'Atendente' : 'Cliente',
'body': dt.body,
'createdAt': dt.createdAt
}
});
const handleClose = () => {
setOpen(false);
};
@ -104,7 +75,7 @@ const Modal = (props) => {
aria-describedby="scroll-dialog-description"
>
<MTable data={props.data} columns={columns} />
<MTable data={dataChat} columns={columns} />
<DialogActions>
<Button onClick={handleClose}>Ok</Button>

View File

@ -176,14 +176,15 @@ const Report = () => {
const [query, dispatchQ] = useReducer(reducerQ, [])
useEffect(() => {
dispatch({ type: "RESET" });
dispatch({ type: "RESET" });
dispatchQ({ type: "RESET" })
setPageNumber(1);
}, [searchParam]);
useEffect(() => {
setLoading(true);
setLoading(true);
const delayDebounceFn = setTimeout(() => {
const fetchUsers = async () => {
@ -191,7 +192,7 @@ const Report = () => {
const { data } = await api.get("/users/", {
params: { searchParam, pageNumber },
});
dispatch({ type: "LOAD_USERS", payload: data.users });
setHasMore(data.hasMore);
setLoading(false);
@ -216,9 +217,9 @@ const Report = () => {
const fetchQueries = async () => {
try {
const dataQuery = await api.get("/reports/", {params: {userId, startDate, endDate },});
console.log('fffffffffffffffffffff query: ', dataQuery.data)
const dataQuery = await api.get("/reports/", {params: {userId, startDate, endDate },});
dispatchQ({ type: "RESET" })
dispatchQ({ type: "LOAD_QUERY", payload: dataQuery.data });
setLoading(false);
@ -272,8 +273,9 @@ console.log('XXXXXXXXX: ', query)
return (
<MainContainer>
<Box sx={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)' }}>
<Item><SelectField func={textFieldSelectUser} currencies={users.map((obj)=>{