mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-19 20:29:17 +00:00
changed ticket update route to typescript
This commit is contained in:
36
backend/src/services/TicketServices/UpdateTicketService.ts
Normal file
36
backend/src/services/TicketServices/UpdateTicketService.ts
Normal 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;
|
||||
Reference in New Issue
Block a user