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
parent
2eed62f753
commit
a9d48b543d
|
@ -6,8 +6,6 @@ import cors from "cors";
|
|||
import cookieParser from "cookie-parser";
|
||||
import * as Sentry from "@sentry/node";
|
||||
|
||||
console.log('dddddddddddddddddddddddddddd')
|
||||
|
||||
import "./database";
|
||||
import uploadConfig from "./config/upload";
|
||||
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" });
|
||||
});
|
||||
|
||||
|
||||
export default app;
|
||||
|
|
|
@ -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);
|
||||
|
||||
};*/
|
||||
|
||||
|
||||
|
||||
|
|
@ -77,11 +77,14 @@ export const store = async (req: Request, res: Response): Promise<Response> => {
|
|||
return res.status(200).json(ticket);
|
||||
};
|
||||
|
||||
|
||||
export const show = async (req: Request, res: Response): Promise<Response> => {
|
||||
const { ticketId } = req.params;
|
||||
|
||||
const contact = await ShowTicketService(ticketId);
|
||||
|
||||
//console.log('------- contact: ',JSON.stringify(contact))
|
||||
|
||||
return res.status(200).json(contact);
|
||||
};
|
||||
|
||||
|
|
|
@ -10,11 +10,11 @@ import messageRoutes from "./messageRoutes";
|
|||
import whatsappSessionRoutes from "./whatsappSessionRoutes";
|
||||
import queueRoutes from "./queueRoutes";
|
||||
import quickAnswerRoutes from "./quickAnswerRoutes";
|
||||
import reportRoutes from "./reportRoutes";
|
||||
|
||||
const routes = Router();
|
||||
|
||||
|
||||
|
||||
routes.use(userRoutes);
|
||||
routes.use("/auth", authRoutes);
|
||||
routes.use(settingRoutes);
|
||||
|
@ -26,4 +26,7 @@ routes.use(whatsappSessionRoutes);
|
|||
routes.use(queueRoutes);
|
||||
routes.use(quickAnswerRoutes);
|
||||
|
||||
routes.use(reportRoutes);
|
||||
|
||||
|
||||
export default routes;
|
||||
|
|
|
@ -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;
|
|
@ -6,7 +6,6 @@ import * as TicketController from "../controllers/TicketController";
|
|||
const ticketRoutes = express.Router();
|
||||
|
||||
|
||||
|
||||
ticketRoutes.get("/tickets", isAuth, TicketController.index);
|
||||
|
||||
ticketRoutes.get("/tickets/:ticketId", isAuth, TicketController.show);
|
||||
|
|
|
@ -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;
|
Loading…
Reference in New Issue