Renamed user history to search_history and fixed an issue where search history received the entire user object and not just the username

This commit is contained in:
2019-11-04 20:32:41 +01:00
parent 5d3a5dc8a4
commit acc26a2f09
4 changed files with 13 additions and 7 deletions

View File

@@ -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'
}
});
}
}