From 453727db1bcc580dd47b86820089d16f6838df34 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Wed, 7 Mar 2018 15:35:55 +0100 Subject: [PATCH] Fixed issue where the user was not being saved alongside the request. Also fixed what the list of requests are sorted by. --- seasoned_api/src/plex/requestRepository.js | 6 +++--- .../src/webserver/controllers/plex/submitRequest.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/seasoned_api/src/plex/requestRepository.js b/seasoned_api/src/plex/requestRepository.js index 1958bb9..8b2d344 100644 --- a/seasoned_api/src/plex/requestRepository.js +++ b/seasoned_api/src/plex/requestRepository.js @@ -16,8 +16,8 @@ class RequestRepository { constructor(cache, database) { this.database = database || establishedDatabase; this.queries = { - insertRequest: "INSERT INTO requests VALUES (?, ?, ?, ?, ?, ?, ?, CURRENT_DATE, 'requested', ?, ?)", - fetchRequestedItems: 'SELECT * FROM requests ORDER BY requested_by ASC', + insertRequest: "INSERT INTO requests VALUES (?, ?, ?, ?, ?, ?, ?, DEFAULT, DEFAULT, ?, ?)", + fetchRequestedItems: 'SELECT * FROM requests ORDER BY date ASC', fetchRequestedItemsByStatus: 'SELECT * FROM requests WHERE status IS ? AND type LIKE ?', updateRequestedById: 'UPDATE requests SET status = ? WHERE id is ? AND type is ?', checkIfIdRequested: 'SELECT * FROM requests WHERE id IS ? AND type IS ?', @@ -68,7 +68,7 @@ class RequestRepository { tmdb.lookup(identifier, type).then((movie) => { if (user === 'false') { user = 'NULL'; } // Add request to database - this.database.run(this.queries.insertRequest, [movie.id, movie.title, movie.year, movie.poster_path, movie.background_path, user, ip, user_agent, movie.type]); + this.database.run(this.queries.insertRequest, [movie.id, movie.title, movie.year, movie.poster_path, movie.background_path, user.username, ip, user_agent, movie.type]); }); } diff --git a/seasoned_api/src/webserver/controllers/plex/submitRequest.js b/seasoned_api/src/webserver/controllers/plex/submitRequest.js index 6afb085..8f95d3a 100644 --- a/seasoned_api/src/webserver/controllers/plex/submitRequest.js +++ b/seasoned_api/src/webserver/controllers/plex/submitRequest.js @@ -15,7 +15,7 @@ function submitRequestController(req, res) { const type = req.query.type; const ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress; const user_agent = req.headers['user-agent']; - const user = req.headers.loggedinuser; + const user = req.headers.loggedInUser; requestRepository.sendRequest(id, type, ip, user_agent, user) .then(() => {