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";
@ -41,5 +39,6 @@ app.use(async (err: Error, req: Request, res: Response, _: NextFunction) => {
logger.error(err); logger.error(err);
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

@ -3,7 +3,7 @@ import { getIO } from "../libs/socket";
import CreateTicketService from "../services/TicketServices/CreateTicketService"; import CreateTicketService from "../services/TicketServices/CreateTicketService";
import DeleteTicketService from "../services/TicketServices/DeleteTicketService"; import DeleteTicketService from "../services/TicketServices/DeleteTicketService";
import ListTicketsService from "../services/TicketServices/ListTicketsService"; import ListTicketsService from "../services/TicketServices/ListTicketsService";
import ShowTicketService from "../services/TicketServices/ShowTicketService"; import ShowTicketService from "../services/TicketServices/ShowTicketService";
import UpdateTicketService from "../services/TicketServices/UpdateTicketService"; import UpdateTicketService from "../services/TicketServices/UpdateTicketService";
import SendWhatsAppMessage from "../services/WbotServices/SendWhatsAppMessage"; import SendWhatsAppMessage from "../services/WbotServices/SendWhatsAppMessage";
@ -76,12 +76,15 @@ 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

@ -31,8 +31,8 @@ export const index = async (req: Request, res: Response): Promise<Response> => {
if(user.profile!=='master'){ if(user.profile!=='master'){
auxUsers.push(user) auxUsers.push(user)
} }
} }
return res.json({ users: auxUsers, count, hasMore }); return res.json({ users: auxUsers, count, hasMore });
} }

View File

@ -4,26 +4,29 @@ import userRoutes from "./userRoutes";
import authRoutes from "./authRoutes"; import authRoutes from "./authRoutes";
import settingRoutes from "./settingRoutes"; import settingRoutes from "./settingRoutes";
import contactRoutes from "./contactRoutes"; import contactRoutes from "./contactRoutes";
import ticketRoutes from "./ticketRoutes"; import ticketRoutes from "./ticketRoutes";
import whatsappRoutes from "./whatsappRoutes"; import whatsappRoutes from "./whatsappRoutes";
import messageRoutes from "./messageRoutes"; 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);
routes.use(contactRoutes); routes.use(contactRoutes);
routes.use(ticketRoutes); routes.use(ticketRoutes);
routes.use(whatsappRoutes); routes.use(whatsappRoutes);
routes.use(messageRoutes); routes.use(messageRoutes);
routes.use(whatsappSessionRoutes); 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

@ -3,11 +3,10 @@ import isAuth from "../middleware/isAuth";
import * as TicketController from "../controllers/TicketController"; 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;