Fixed issue where the user was not being saved alongside the request. Also fixed what the list of requests are sorted by.

This commit is contained in:
2018-03-07 15:35:55 +01:00
parent ab2d3c6756
commit 453727db1b
2 changed files with 4 additions and 4 deletions

View File

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

View File

@@ -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(() => {