134 lines
2.6 KiB
TypeScript
134 lines
2.6 KiB
TypeScript
|
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;
|