Person info now handles optional credits query parameter
This commit is contained in:
@@ -1,23 +1,49 @@
|
|||||||
const configuration = require('src/config/configuration').getInstance();
|
const configuration = require("src/config/configuration").getInstance();
|
||||||
const TMDB = require('src/tmdb/tmdb');
|
const TMDB = require("src/tmdb/tmdb");
|
||||||
const tmdb = new TMDB(configuration.get('tmdb', 'apiKey'));
|
const tmdb = new TMDB(configuration.get("tmdb", "apiKey"));
|
||||||
|
|
||||||
|
function handleError(error, res) {
|
||||||
|
const { status, message } = error;
|
||||||
|
|
||||||
|
if (status && message) {
|
||||||
|
res.status(status).send({ success: false, message });
|
||||||
|
} else {
|
||||||
|
console.log("caught personinfo controller error", error);
|
||||||
|
res.status(500).send({
|
||||||
|
message: "An unexpected error occured while requesting person info."
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controller: Retrieve information for a person
|
* Controller: Retrieve information for a person
|
||||||
* @param {Request} req http request variable
|
* @param {Request} req http request variable
|
||||||
* @param {Response} res
|
* @param {Response} res
|
||||||
* @returns {Callback}
|
* @returns {Callback}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function personInfoController(req, res) {
|
async function personInfoController(req, res) {
|
||||||
const personId = req.params.id;
|
const personId = req.params.id;
|
||||||
|
let { credits } = req.query;
|
||||||
|
arguments;
|
||||||
|
|
||||||
|
credits && credits.toLowerCase() === "true"
|
||||||
|
? (credits = true)
|
||||||
|
: (credits = false);
|
||||||
|
|
||||||
tmdb.personInfo(personId)
|
let tmdbQueue = [tmdb.personInfo(personId)];
|
||||||
.then(person => res.send(person.createJsonResponse()))
|
if (credits) tmdbQueue.push(tmdb.personCredits(personId));
|
||||||
.catch(error => {
|
|
||||||
res.status(404).send({ success: false, message: error.message });
|
try {
|
||||||
});
|
const [Person, Credits] = await Promise.all(tmdbQueue);
|
||||||
|
|
||||||
|
const person = Person.createJsonResponse();
|
||||||
|
if (credits) person.credits = Credits.createJsonResponse();
|
||||||
|
|
||||||
|
return res.send(person);
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error, res);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = personInfoController;
|
module.exports = personInfoController;
|
||||||
|
|||||||
Reference in New Issue
Block a user