|
|
@ -48,7 +48,7 @@ export default function register(factory: RouteRegisterFactory<MiddlewareMethod< |
|
|
|
/** |
|
|
|
* Fetch a user's active movie tickets |
|
|
|
*/ |
|
|
|
factory.get("/tickets/active", async (request, reply) => { |
|
|
|
factory.get("/active", async (request, reply) => { |
|
|
|
let user = request.middlewareParams.auth.user; |
|
|
|
let tickets = await user.activeMovieTickets(); |
|
|
|
let movies = await convertTicketsToMovies(tickets); |
|
|
@ -56,10 +56,38 @@ export default function register(factory: RouteRegisterFactory<MiddlewareMethod< |
|
|
|
return reply.send({ status: "Success", data: movies }); |
|
|
|
}); |
|
|
|
|
|
|
|
/** |
|
|
|
* Fetch a movie request |
|
|
|
*/ |
|
|
|
factory.get("/:id", async (request, reply) => { |
|
|
|
let id = parseInt((<any>request.params)["id"]); |
|
|
|
let ticket = await MovieTicket.findOne(id); |
|
|
|
if (ticket === undefined) { |
|
|
|
return respond(reply, Status.NotFound); |
|
|
|
} |
|
|
|
let movie = (await convertTicketsToMovies([ticket]))[0]; |
|
|
|
respond(reply, Status.Ok, movie); |
|
|
|
}); |
|
|
|
|
|
|
|
/** |
|
|
|
* Cancel an active request |
|
|
|
*/ |
|
|
|
factory.delete("/:id", async (request, reply) => { |
|
|
|
let user = request.middlewareParams.auth.user; |
|
|
|
let id = parseInt((<any>request.params)["id"]); |
|
|
|
let ticket = await MovieTicket.findOne(id, { where: { user: user.id } }); |
|
|
|
if (ticket === undefined) { |
|
|
|
return respond(reply, Status.NotFound); |
|
|
|
} |
|
|
|
ticket.isCanceled = true; |
|
|
|
await ticket.save(); |
|
|
|
respond(reply, Status.Ok); |
|
|
|
}); |
|
|
|
|
|
|
|
/** |
|
|
|
* Request a movie to download |
|
|
|
*/ |
|
|
|
factory.post("/create/tmdb/:tmdb_id", handleRequest([RequestTmdbMovieRequest], async (request, reply) => { |
|
|
|
factory.post("/create/:tmdb_id", handleRequest([RequestTmdbMovieRequest], async (request, reply) => { |
|
|
|
// Verify that the ID has not yet been requested
|
|
|
|
let tmdbId = (<any>request.params)["tmdb_id"]; |
|
|
|
if (0 != await MovieTicket.count({ where: { tmdbId, isCanceled: false } })) { |
|
|
|