Request id is now passed as body param. Database default timestamp value changed to epoch time.

This commit is contained in:
2018-11-09 22:13:00 +01:00
parent 0ac17d3d0a
commit 91d238de7c
3 changed files with 8 additions and 11 deletions

View File

@@ -41,7 +41,7 @@ CREATE TABLE IF NOT EXISTS request(
title text not null, title text not null,
year int not null, year int not null,
type char(10) not null, type char(10) not null,
date default current_timestamp date timestamp default (strftime('%s', 'now'))
); );

View File

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

View File

@@ -6,14 +6,14 @@ const cache = new Cache();
const tmdb = new TMDB(cache, configuration.get('tmdb', 'apiKey')); const tmdb = new TMDB(cache, configuration.get('tmdb', 'apiKey'));
const request = new RequestRepository(); const request = new RequestRepository();
const typeFunction = (type) => { const requestAsTmdb = (type, id) => {
if (type !== undefined) { if (type !== undefined) {
type = type.toLowerCase(); type = type.toLowerCase();
if (type === 'movie') { if (type === 'movie') {
return tmdb.movieInfo; return tmdb.movieInfo(id);
} else if (type === 'show') { } else if (type === 'show') {
return tmdb.showInfo; return tmdb.showInfo(id);
} else { } else {
throw new Error("Unprocessable Entity: Invalid type for body parameter 'type'. Allowed values: movie|show"); throw new Error("Unprocessable Entity: Invalid type for body parameter 'type'. Allowed values: movie|show");
} }
@@ -28,14 +28,11 @@ const typeFunction = (type) => {
* @returns {Callback} * @returns {Callback}
*/ */
function requestTmdbIdController(req, res) { function requestTmdbIdController(req, res) {
const requestId = req.params.id; const { id, type } = req.body;
const tmdbType = req.body.tmdbType;
Promise.resolve() Promise.resolve()
.then(() => typeFunction(tmdbType)) .then(() => requestAsTmdb(type, id))
// .then(() => checkType .then((requesAsTmdb) => request.addTmdb(requesAsTmdb))
.then(() => tmdb.movieInfo(requestId))
.then((movie) => request.addTmdb(movie))
.then(() => res.send({sucess: true, message: 'Request has been submitted.'})) .then(() => res.send({sucess: true, message: 'Request has been submitted.'}))
.catch((error) => { .catch((error) => {
res.status(404).send({ success: false, error: error.message }); res.status(404).send({ success: false, error: error.message });