improvement: remove tickets logic from useTickets to improve notifications

This commit is contained in:
canove
2020-09-25 18:53:14 -03:00
parent c7d3807219
commit 5396837db4
10 changed files with 190 additions and 163 deletions

View File

@@ -12,10 +12,15 @@ interface Request {
ticketId: string;
}
interface Response {
ticket: Ticket;
oldStatus: string;
}
const UpdateTicketService = async ({
ticketData,
ticketId
}: Request): Promise<Ticket> => {
}: Request): Promise<Response> => {
const { status, userId } = ticketData;
const ticket = await Ticket.findOne({
@@ -33,12 +38,14 @@ const UpdateTicketService = async ({
throw new AppError("No ticket found with this ID.", 404);
}
const oldStatus = ticket.status;
await ticket.update({
status,
userId
});
return ticket;
return { ticket, oldStatus };
};
export default UpdateTicketService;