Criação dos arquivos reportRoutes.ts, ReportController.ts, ShowTicketReport.ts no backend para geração de relatórios de atendimento. Estádo parcial do relatóri

pull/1/head
adriano 2022-01-15 15:32:46 -03:00
parent 2eed62f753
commit a9d48b543d
8 changed files with 194 additions and 13 deletions

View File

@ -6,8 +6,6 @@ import cors from "cors";
import cookieParser from "cookie-parser"; import cookieParser from "cookie-parser";
import * as Sentry from "@sentry/node"; import * as Sentry from "@sentry/node";
console.log('dddddddddddddddddddddddddddd')
import "./database"; import "./database";
import uploadConfig from "./config/upload"; import uploadConfig from "./config/upload";
import AppError from "./errors/AppError"; import AppError from "./errors/AppError";
@ -42,4 +40,5 @@ app.use(async (err: Error, req: Request, res: Response, _: NextFunction) => {
return res.status(500).json({ error: "Internal server error" }); return res.status(500).json({ error: "Internal server error" });
}); });
export default app; export default app;

View File

@ -0,0 +1,30 @@
//relatorio
import { Request, Response } from "express";
import AppError from "../errors/AppError";
import ShowTicketReport from "../services/TicketServices/ShowTicketReport";
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 reportAll = async (req: Request, res: Response): Promise<Response> => {
const test = await ShowTicketReport();
return res.status(200).json(test);
};*/

View File

@ -77,11 +77,14 @@ export const store = async (req: Request, res: Response): Promise<Response> => {
return res.status(200).json(ticket); return res.status(200).json(ticket);
}; };
export const show = async (req: Request, res: Response): Promise<Response> => { export const show = async (req: Request, res: Response): Promise<Response> => {
const { ticketId } = req.params; const { ticketId } = req.params;
const contact = await ShowTicketService(ticketId); const contact = await ShowTicketService(ticketId);
//console.log('------- contact: ',JSON.stringify(contact))
return res.status(200).json(contact); return res.status(200).json(contact);
}; };

View File

@ -10,11 +10,11 @@ import messageRoutes from "./messageRoutes";
import whatsappSessionRoutes from "./whatsappSessionRoutes"; import whatsappSessionRoutes from "./whatsappSessionRoutes";
import queueRoutes from "./queueRoutes"; import queueRoutes from "./queueRoutes";
import quickAnswerRoutes from "./quickAnswerRoutes"; import quickAnswerRoutes from "./quickAnswerRoutes";
import reportRoutes from "./reportRoutes";
const routes = Router(); const routes = Router();
routes.use(userRoutes); routes.use(userRoutes);
routes.use("/auth", authRoutes); routes.use("/auth", authRoutes);
routes.use(settingRoutes); routes.use(settingRoutes);
@ -26,4 +26,7 @@ routes.use(whatsappSessionRoutes);
routes.use(queueRoutes); routes.use(queueRoutes);
routes.use(quickAnswerRoutes); routes.use(quickAnswerRoutes);
routes.use(reportRoutes);
export default routes; export default routes;

View File

@ -0,0 +1,14 @@
//relatorio
import express from "express";
import isAuth from "../middleware/isAuth";
import * as ReportController from "../controllers/ReportController";
const reportRoutes = express.Router();
reportRoutes.get("/reports/:userId", /*isAuth,*/ ReportController.reportUser);
//reportRoutes.get("/reports", /*isAuth,*/ ReportController.reportAll);
export default reportRoutes;

View File

@ -6,7 +6,6 @@ import * as TicketController from "../controllers/TicketController";
const ticketRoutes = express.Router(); const ticketRoutes = express.Router();
ticketRoutes.get("/tickets", isAuth, TicketController.index); ticketRoutes.get("/tickets", isAuth, TicketController.index);
ticketRoutes.get("/tickets/:ticketId", isAuth, TicketController.show); ticketRoutes.get("/tickets/:ticketId", isAuth, TicketController.show);

View File

@ -0,0 +1,133 @@
import Ticket from "../../models/Ticket";
import AppError from "../../errors/AppError";
import Contact from "../../models/Contact";
import User from "../../models/User";
import Queue from "../../models/Queue";
import Message from "../../models/Message";
import { userInfo } from "os";
//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', 'mediaUrl','createdAt'],
order: [
['createdAt', 'ASC']
]
},
{
model: Contact,
required:true,
attributes: ['name', 'number']
},
{
model: User,
required:true,
attributes: ['name', 'email']
},
{
model: Queue,
required:true,
attributes: ['name']
},
],
});
/*const ticket = await Message.findAll({
//raw: true,
where:{''},
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;
};
// 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;