Get a request item by id and type

This commit is contained in:
2019-06-28 19:21:54 +02:00
parent ac027a97d6
commit 9f1badc1b1
3 changed files with 40 additions and 1 deletions

View File

@@ -20,7 +20,7 @@ class RequestRepository {
downloaded: '(select status from requests where id is request.id and type is request.type limit 1)',
// deluge: '(select status from deluge_torrent where id is request.id and type is request.type limit 1)',
// fetchAllFilterStatus: 'select * from request where '
read: 'select * from request where id is ? and type is ?'
read: 'select id, title, year, type, status, requested_by, ip, date, user_agent from requests where id is ? and type is ?'
};
}
@@ -96,6 +96,22 @@ class RequestRepository {
});
}
/**
* Get request item by id
* @param {String} id
* @param {String} type
* @returns {Promise}
*/
getRequestByIdAndType(id, type) {
console.log('id & type', id, type)
return Promise.resolve()
.then(() => this.database.get(this.queries.read, [id, type]))
.then(row => {
assert(row, 'Could not find request item with that id and type')
return JSON.stringify(row)
})
}
/**
* Fetch all requests with optional sort and filter params
* @param {String} what we are sorting by

View File

@@ -102,6 +102,7 @@ router.post('/v1/plex/hook', require('./controllers/plex/hookDump.js'));
*/
router.get('/v2/request', require('./controllers/request/fetchAllRequests.js'));
router.get('/v2/request/:id', require('./controllers/request/getRequest.js'));
router.post('/v2/request', require('./controllers/request/requestTmdbId.js'));
router.get('/v1/plex/requests/all', require('./controllers/plex/fetchRequested.js'));
router.put('/v1/plex/request/:requestId', mustBeAuthenticated, require('./controllers/plex/updateRequested.js'));

View File

@@ -0,0 +1,22 @@
const RequestRepository = require('src/request/request');
const request = new RequestRepository();
/**
* Controller: Get requested item by tmdb id and type
* @param {Request} req http request variable
* @param {Response} res
* @returns {Callback}
*/
function fetchAllRequests(req, res) {
const id = req.params.id;
const { type } = req.query;
Promise.resolve()
.then(() => request.getRequestByIdAndType(id, type))
.then((result) => res.send(result))
.catch((error) => {
res.status(404).send({ success: false, error: error.message });
});
}
module.exports = fetchAllRequests;