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

@ -11,27 +11,14 @@ type IndexQuery = {
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,13 +26,6 @@ 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

@ -7,10 +7,6 @@ import * as ReportController from "../controllers/ReportController";
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

@ -81,41 +81,6 @@ 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);
}
@ -123,45 +88,4 @@ const ShowTicketReport = async (id: string | number): Promise<Ticket[]> => {
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 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) =>{
@ -158,21 +156,18 @@ 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 [startDate, setDatePicker1] = useState(new Date())
const [endDate, setDatePicker2] = useState(new Date())
const [userId, setUser] = useState(null)
const [query, dispatchQ] = useReducer(reducerQ, [])
useEffect(() => {
@ -262,27 +257,23 @@ function handleQuery (){
console.log('endDate: ', endDate)
console.log('userid: ', userId)
/* if(tot == 3){
setColums(columns1)
} */
}
console.log('XXXXXXXXX: ', query)
return (
<MainContainer>
<Can
role={userA.profile}
perform="ticket-report:show"
yes={() => (
<MainContainer>
<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><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'}/>
</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>*/}
</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",
"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",
"ticket-report:show",
],
},
};