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

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

View File

@ -10,14 +10,10 @@ const MTable = (props) => {
const [selectedRow, setSelectedRow] = useState(null); const [selectedRow, setSelectedRow] = useState(null);
console.log('rederizou....................: ',props.data)
const dataLoad = props.data.map((dt) => { return { ...dt }}); const dataLoad = props.data.map((dt) => { return { ...dt }});
const columnsLoad = props.columns.map((column) => { return { ...column }}); const columnsLoad = props.columns.map((column) => { return { ...column }});
console.log('dataLoad....................: ',dataLoad)
console.log('columnsLoad....................: ',columnsLoad)
useEffect(() => { useEffect(() => {
console.log(`You have clicked the button ${selectedRow} times`) console.log(`You have clicked the button ${selectedRow} times`)
@ -31,6 +27,7 @@ const MTable = (props) => {
columns={columnsLoad} columns={columnsLoad}
data={dataLoad} data={dataLoad}
onRowClick={(evt, selectedRow) => { onRowClick={(evt, selectedRow) => {
console.log(selectedRow.tableData.id); console.log(selectedRow.tableData.id);
@ -48,6 +45,8 @@ const MTable = (props) => {
search: true, search: true,
selection: false, selection: false,
paging: false, paging: false,
padding: 'dense',
//loadingType: 'linear',
searchFieldStyle: { searchFieldStyle: {
width: 300, width: 300,
}, },

View File

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

View File

@ -184,6 +184,7 @@ const Report = () => {
useEffect(() => { useEffect(() => {
setLoading(true); setLoading(true);
const delayDebounceFn = setTimeout(() => { const delayDebounceFn = setTimeout(() => {
const fetchUsers = async () => { const fetchUsers = async () => {
@ -216,9 +217,9 @@ const Report = () => {
const fetchQueries = async () => { const fetchQueries = async () => {
try { 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 }); dispatchQ({ type: "LOAD_QUERY", payload: dataQuery.data });
setLoading(false); setLoading(false);
@ -274,6 +275,7 @@ console.log('XXXXXXXXX: ', query)
<MainContainer> <MainContainer>
<Box sx={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)' }}> <Box sx={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)' }}>
<Item><SelectField func={textFieldSelectUser} currencies={users.map((obj)=>{ <Item><SelectField func={textFieldSelectUser} currencies={users.map((obj)=>{