|
|
@ -1,6 +1,6 @@ |
|
|
|
import { IpcClient as SeekerIpc } from "@autoplex-api/seeker"; |
|
|
|
import { MovieInfo, MovieTicket } from "@autoplex/database"; |
|
|
|
import { handleRequest, RouteRegisterFactory, MiddlewareMethod } from "@autoplex/webserver"; |
|
|
|
import { handleRequest, RouteRegisterFactory, MiddlewareMethod, Status, respond } from "@autoplex/webserver"; |
|
|
|
import Application from "../../../Application"; |
|
|
|
import MovieSearch from "../../MovieSearch"; |
|
|
|
import { auth } from "../middleware/auth"; |
|
|
@ -27,7 +27,7 @@ export default function register(factory: RouteRegisterFactory<MiddlewareMethod< |
|
|
|
let query = <string>(<any>request.query)["query"]; |
|
|
|
let year = parseInt((<any>request.query)["year"]) || undefined; |
|
|
|
let results = await app.service<MovieSearch>("Movie Search").search(query, year); |
|
|
|
reply.send({ status: "Success", data: results }); |
|
|
|
respond(reply, Status.Ok, results); |
|
|
|
}); |
|
|
|
|
|
|
|
/** |
|
|
@ -36,12 +36,10 @@ export default function register(factory: RouteRegisterFactory<MiddlewareMethod< |
|
|
|
factory.get("/movie/details/:id", async (request, reply) => { |
|
|
|
let id = parseInt((<any>request.params)["id"]); |
|
|
|
if (id.toString() !== (<any>request.params)["id"].trim()) { |
|
|
|
reply.status(400); |
|
|
|
reply.send({ "status": "Bad request" }); |
|
|
|
return; |
|
|
|
return respond(reply, Status.BadRequest); |
|
|
|
} |
|
|
|
let results = await app.service<MovieSearch>("Movie Search").details(id); |
|
|
|
reply.send({ status: "Success", data: results}); |
|
|
|
respond(reply, Status.Ok, results); |
|
|
|
}); |
|
|
|
|
|
|
|
// Movie Request ---------------------------------------------------------------------------
|
|
|
@ -54,7 +52,7 @@ export default function register(factory: RouteRegisterFactory<MiddlewareMethod< |
|
|
|
let user = request.middlewareParams.auth.user; |
|
|
|
let tickets = await user.activeMovieTickets(); |
|
|
|
let movies = await convertTicketsToMovies(tickets); |
|
|
|
console.log(movies) |
|
|
|
respond(reply, Status.Ok, movies); |
|
|
|
return reply.send({ status: "Success", data: movies }); |
|
|
|
}); |
|
|
|
|
|
|
@ -65,16 +63,11 @@ export default function register(factory: RouteRegisterFactory<MiddlewareMethod< |
|
|
|
// 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 } })) { |
|
|
|
reply.status(409); |
|
|
|
reply.send({ status: "Conflict" }); |
|
|
|
return; |
|
|
|
return respond(reply, Status.Conflict); |
|
|
|
} |
|
|
|
// Verify that the IMDb ID exists
|
|
|
|
let movie = await app.service<MovieSearch>("Movie Search").details(tmdbId); |
|
|
|
if (!movie) { // @TODO This isn't correct I don't think
|
|
|
|
reply.status(404); |
|
|
|
reply.send({ satus: "Not found" }); |
|
|
|
return; |
|
|
|
if (!movie) { |
|
|
|
return respond(reply, Status.NotFound); |
|
|
|
} |
|
|
|
// Create the movie request ticket
|
|
|
|
let user = request.middlewareParams.auth.user; |
|
|
@ -99,57 +92,8 @@ export default function register(factory: RouteRegisterFactory<MiddlewareMethod< |
|
|
|
await ticket.save(); |
|
|
|
|
|
|
|
app.service<SeekerIpc>("Seeker").notifyMovieRequested(ticket.id); |
|
|
|
return reply.send({ status: "Success", data: { ticket_id: ticket.id }}); |
|
|
|
respond(reply, Status.Ok, { ticketId: ticket.id }); |
|
|
|
})); |
|
|
|
|
|
|
|
/** |
|
|
|
* Request a movie to download |
|
|
|
*/ |
|
|
|
// factory.get("/create/imdb/:imdb_id", handleRequest([RequestImdbMovieRequest], async (request, reply) => {
|
|
|
|
// // Verify that the ID has not yet been requested
|
|
|
|
// let imdbId = (<any>request.params)["imdb_id"];
|
|
|
|
// let title = (<any>request.query)["title"] || null;
|
|
|
|
// // let year = // Scrape IMDb to find out...
|
|
|
|
// if (0 != await MovieTicket.count({imdbId})) {
|
|
|
|
// reply.status(409);
|
|
|
|
// reply.send({ status: "Conflict" });
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
// // Verify that the IMDb ID exists
|
|
|
|
// if (!await app.service<MovieSearch>("Movie Search").verifyImdbId(imdbId)) {
|
|
|
|
// reply.status(404);
|
|
|
|
// reply.send({ satus: "Not found" });
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
// // Create the movie request ticket
|
|
|
|
// let user = request.middlewareParams.auth.user;
|
|
|
|
// // let ticket = await MovieTicket.requestImdb(user, imdbId, title, year);
|
|
|
|
// return reply.send({ status: "Success", data: { ticket_id: ticket.id }});
|
|
|
|
// }));
|
|
|
|
|
|
|
|
/** |
|
|
|
* Remove/cancel a request |
|
|
|
*/ |
|
|
|
// factory.get("/cancel/:ticket_id", async (request, reply) => {
|
|
|
|
// // Verify that the ticket exists
|
|
|
|
// let ticketId = parseInt((<any>request.params)["ticket_id"]);
|
|
|
|
// if (ticketId === NaN) {
|
|
|
|
// reply.status(400);
|
|
|
|
// reply.send({ status: "Bad request" });
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
// let user = request.middlewareParams.auth.user;
|
|
|
|
// let ticket = await MovieTicket.findOne({ id: ticketId, user});
|
|
|
|
// if (ticket === ) {
|
|
|
|
// reply.status(404);
|
|
|
|
// reply.send({ status: "Not found" });
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
// // Create the movie request ticket
|
|
|
|
// let user =
|
|
|
|
// let ticket = await MovieTicket.requestTmdb(user, tmdbId, movieDetails);
|
|
|
|
// return reply.send({ status: "Success", data: { ticket_id: ticket.id }});
|
|
|
|
// });
|
|
|
|
}); |
|
|
|
}); |
|
|
|
} |