Merge branch 'testeA'

pull/1/head
adriano 2022-01-26 21:33:36 -03:00
commit d038631045
5 changed files with 39 additions and 201 deletions

View File

@ -10,28 +10,15 @@ type IndexQuery = {
startDate: string;
endDate: string;
};
/*export const reportUser = async (req: Request, res: Response): Promise<Response> => {
const { userId } = req.params;
console.log('******* Estrou no report: ', userId)
const test = await ShowTicketReport(userId);
return res.status(200).json(test);
};*/
export const reportUserByDateStartDateEnd = async (req: Request, res: Response): Promise<Response> => {
const { userId, startDate, endDate } = req.query as IndexQuery
if (req.user.profile !== "master" && req.user.profile !== "admin") {
throw new AppError("ERR_NO_PERMISSION", 403);
}
console.log('******* Estrou no report')
console.log('******* userId: ', userId)
console.log('******* startDate: ', startDate)
console.log('******* endDate: ', endDate)
const { userId, startDate, endDate } = req.query as IndexQuery
const data_query = await ShowTicketReport(userId, startDate, endDate);
@ -39,14 +26,7 @@ export const reportUserByDateStartDateEnd = async (req: Request, res: Response):
};
/*export const reportAll = async (req: Request, res: Response): Promise<Response> => {
const test = await ShowTicketReport();
return res.status(200).json(test);
};*/

View File

@ -5,12 +5,8 @@ import isAuth from "../middleware/isAuth";
import * as ReportController from "../controllers/ReportController";
const reportRoutes = express.Router();
const reportRoutes = express.Router();
//reportRoutes.get("/reports/:userId", /*isAuth,*/ ReportController.reportUser);
reportRoutes.get("/reports", /*isAuth,*/ ReportController.reportUserByDateStartDateEnd);
//reportRoutes.get("/reports", /*isAuth,*/ ReportController.reportAll);
reportRoutes.get("/reports", isAuth, ReportController.reportUserByDateStartDateEnd);
export default reportRoutes;

View File

@ -78,90 +78,14 @@ const ShowTicketReport = async (id: string | number, startDate: string, endDate:
],
});
/*//Report by user
const ShowTicketReport = async (id: string | number): Promise<Ticket[]> => {
const ticket = await Ticket.findAll({
where: {userid: id} ,
attributes: ['id', 'status', 'createdAt', 'updatedAt'],
include: [
{
model: Message,
required:true,
separate: true,
attributes: ['body', 'read', 'mediaType','fromMe', 'mediaUrl','createdAt'],
order: [
['createdAt', 'ASC']
]
},
{
model: Contact,
attributes: ['name', 'number']
},
{
model: User,
attributes: ['name', 'email']
},
{
model: Queue,
attributes: ['name']
},
],
}); */
});
if (!ticket) {
throw new AppError("ERR_NO_TICKET_FOUND", 404);
}
return ticket;
};
// Report all
/*const ShowTicketReport = async (): Promise<Message[]> => {
const ticket = await Message.findAll({
//raw: true,
attributes: ['body', 'createdAt', 'ticketId'],
include: [
{
model: Ticket,
attributes: ['contactid', 'userid', 'queueid', 'status'],
include:[
{
model: Contact,
attributes: ['name', 'number']
},
{
model: User,
attributes: ['name', 'email']
},
{
model: Queue,
attributes: ['name']
}
],
},
],
order:
['ticketId', 'createdAt']
});
if (!ticket) {
throw new AppError("ERR_NO_TICKET_FOUND", 404);
}
return ticket;
};*/
};
export default ShowTicketReport;

View File

@ -1,9 +1,6 @@
import React, { useState, useEffect, useReducer} from "react";
import React, { useState, useEffect, useReducer, useContext} from "react";
import MainContainer from "../../components/MainContainer";
import api from "../../services/api";
import api from "../../services/api";
import SelectField from "../../components/Report/SelectField";
import { data } from '../../components/Report/MTable/data';
import DatePicker1 from '../../components/Report/DatePicker'
@ -12,7 +9,8 @@ import { Button } from "@material-ui/core";
import MTable from "../../components/Report/MTable";
import PropTypes from 'prop-types';
import Box from '@mui/material/Box';
import { AuthContext } from "../../context/Auth/AuthContext";
import { Can } from "../../components/Can";
const reducerQ = (state, action) =>{
@ -157,22 +155,19 @@ let columnsData = [
const Report = () => {
const { user: userA } = useContext(AuthContext);
//--------
const [searchParam, setSearchParam] = useState("");
const [loading, setLoading] = useState(false);
const [hasMore, setHasMore] = useState(false);
const [pageNumber, setPageNumber] = useState(1);
const [users, dispatch] = useReducer(reducer, []);
const [columns, setColums] = useState([])
const [users, dispatch] = useReducer(reducer, []);
const [columns, setColums] = useState([])
const [startDate, setDatePicker1] = useState(new Date())
const [endDate, setDatePicker2] = useState(new Date())
const [userId, setUser] = useState(null)
const [userId, setUser] = useState(null)
const [query, dispatchQ] = useReducer(reducerQ, [])
useEffect(() => {
@ -260,28 +255,24 @@ function handleQuery (){
console.log('startDate: ', startDate)
console.log('endDate: ', endDate)
console.log('userid: ', userId)
/* if(tot == 3){
setColums(columns1)
} */
console.log('userid: ', userId)
}
console.log('XXXXXXXXX: ', query)
return (
return (
<MainContainer>
<Can
role={userA.profile}
perform="ticket-report:show"
yes={() => (
<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)=>{
return {'value': obj.id, 'label': obj.name}
})}/></Item>
})}/></Item>
<Item><DatePicker1 func={datePicker1Value} title={'Data inicio'}/></Item>
<Item><DatePicker2 func={datePicker2Value} title={'Data fim'}/></Item>
@ -295,71 +286,19 @@ console.log('XXXXXXXXX: ', query)
<Box sx={{
display: 'grid',
}}>
<Item sx={{ gridColumn: '1', gridRow: 'span 1' }}>
<Item sx={{ gridColumn: '1', gridRow: 'span 1' }}>
<MTable data={query}
columns={columnsData}
hasChild={true}
table_title={'Relatório de atendimento por atendentes'}/>
table_title={'Relatório de atendimento por atendentes'}/>
</Item>
</Box>
{/* <MainHeader>
<Title>{i18n.t("users.title")}</Title>
<MainHeaderButtonsWrapper>
</MainHeaderButtonsWrapper>
</MainHeader>
<Paper
className={classes.mainPaper}
variant="outlined"
onScroll={handleScroll}
>
<Table size="small">
<TableHead>
<TableRow>
<TableCell align="center">{i18n.t("users.table.name")}</TableCell>
<TableCell align="center">
{i18n.t("users.table.email")}
</TableCell>
<TableCell align="center">
{i18n.t("users.table.profile")}
</TableCell>
<TableCell align="center">
{i18n.t("users.table.actions")}
</TableCell>
</TableRow>
</TableHead>
<TableBody>
<>
{users.map((user) => (
<TableRow key={user.id}>
<TableCell align="center">{user.name}</TableCell>
<TableCell align="center">{user.email}</TableCell>
<TableCell align="center">{user.profile}</TableCell>
<TableCell align="center">
</TableCell>
</TableRow>
))}
{loading && <TableRowSkeleton columns={4} />}
</>
</TableBody>
</Table>
</Paper>*/}
</Box>
</MainContainer>
)}
/>
)
};

View File

@ -11,11 +11,11 @@ const rules = {
"user-modal:editQueues",
"ticket-options:deleteTicket",
"contacts-page:deleteContact",
"connections-view:show",
"dashboard-view:show",
"queues-view:show",
"user-view:show",
"user-view:show",
"ticket-report:show",
],
},
@ -28,17 +28,16 @@ const rules = {
"user-modal:editQueues",
"ticket-options:deleteTicket",
"contacts-page:deleteContact",
"connections-view:show",
"dashboard-view:show",
"queues-view:show",
"user-view:show",
"settings-view:show",
"btn-add-user",
"icon-remove-user",
"btn-add-whatsapp",
"btn-remove-whatsapp",
"btn-remove-whatsapp",
"ticket-report:show",
],
},
};