changed ticket update route to typescript

This commit is contained in:
canove
2020-09-19 21:10:12 -03:00
parent 1d0bbda00d
commit f221fef32d
3 changed files with 67 additions and 27 deletions

View File

@@ -0,0 +1,36 @@
import AppError from "../../errors/AppError";
import Ticket from "../../models/Ticket";
interface TicketData {
status?: string;
userId?: number;
}
interface Request {
ticketData: TicketData;
ticketId: string;
}
const UpdateTicketService = async ({
ticketData,
ticketId
}: Request): Promise<Ticket> => {
const { status, userId } = ticketData;
const ticket = await Ticket.findOne({
where: { id: ticketId }
});
if (!ticket) {
throw new AppError("No ticket found with this ID.", 404);
}
await ticket.update({
status,
userId
});
return ticket;
};
export default UpdateTicketService;