diff --git a/seasoned_api/src/searchHistory/searchHistory.js b/seasoned_api/src/searchHistory/searchHistory.js index 4ebb899..c2d5a67 100644 --- a/seasoned_api/src/searchHistory/searchHistory.js +++ b/seasoned_api/src/searchHistory/searchHistory.js @@ -28,17 +28,23 @@ class SearchHistory { /** * Creates a new search entry in the database. - * @param {User} user a new user + * @param {String} username logged in user doing the search * @param {String} searchQuery the query the user searched for * @returns {Promise} */ - create(user, searchQuery) { - return Promise.resolve() - .then(() => this.database.run(this.queries.create, [searchQuery, user])) - .catch((error) => { + create(username, searchQuery) { + return this.database.run(this.queries.create, [searchQuery, username]) + .catch(error => { if (error.message.includes('FOREIGN')) { throw new Error('Could not create search history.'); } + + throw { + success: false, + status: 500, + message: 'An unexpected error occured', + source: 'database' + } }); } } diff --git a/seasoned_api/src/webserver/app.js b/seasoned_api/src/webserver/app.js index 0b0a57b..9f5ff24 100644 --- a/seasoned_api/src/webserver/app.js +++ b/seasoned_api/src/webserver/app.js @@ -53,7 +53,7 @@ app.use(function onError(err, req, res, next) { */ router.post('/v1/user', require('./controllers/user/register.js')); router.post('/v1/user/login', require('./controllers/user/login.js')); -router.get('/v1/user/history', mustBeAuthenticated, require('./controllers/user/history.js')); +router.get('/v1/user/search_history', mustBeAuthenticated, require('./controllers/user/search_history.js')); router.get('/v1/user/requests', mustBeAuthenticated, require('./controllers/user/requests.js')); router.post('/v1/user/authenticate', mustBeAuthenticated, require('./controllers/user/authenticatePlexAccount.js')); diff --git a/seasoned_api/src/webserver/controllers/search/multiSearch.js b/seasoned_api/src/webserver/controllers/search/multiSearch.js index 0f9b05f..f0a3810 100644 --- a/seasoned_api/src/webserver/controllers/search/multiSearch.js +++ b/seasoned_api/src/webserver/controllers/search/multiSearch.js @@ -24,7 +24,7 @@ function multiSearchController(req, res) { const { query, page } = req.query; if (user) { - searchHistory.create(user, query) + searchHistory.create(user.username, query) } return tmdb.multiSearch(query, page) diff --git a/seasoned_api/src/webserver/controllers/user/history.js b/seasoned_api/src/webserver/controllers/user/search_history.js similarity index 100% rename from seasoned_api/src/webserver/controllers/user/history.js rename to seasoned_api/src/webserver/controllers/user/search_history.js