I've got small app for storing list of episodes. I've got table Serie, Seasons and table Episode. Table Seasons got field "serie" which is of type ObjectId of Serie. Now I've got select list with list of Serie items, when I pick one item from dropdown the method getSeasons is triggered but I'm getting 400 Bad Request error.
My files:
app.route('/serie/:serieId/seasons')
.get(seasons.seasonsList);
exports.seasonsList = function(req, res, id) {
Season.find({'serie': id}).exec(function(err, series) {
if (err) {
return res.status(400).send({
message: errorHandler.getErrorMessage(err)
});
} else {
res.jsonp(series);
}
});
};
var Seasons = $resource('/serie/:serieId/seasons', {serieId: '@id'});
Seasons.get({'serieId': $scope.serie}, function (data) {
console.dir(data);
});
But despite I've route set I'm getting 400 bad request... Why is that?
I want to achive the same thing like when I type this in mongo:
db.seasons.find({'serie': new ObjectId('SerieId')})
The problem was parameters. The solution to problem is to change seasonsList method to get parameter from reqest like this:
exports.seasonsList = function(req, res) {
Season.find({'serie': req.params.serieId}).exec(function(err, series) {
if (err) {
return res.status(400).send({
message: errorHandler.getErrorMessage(err)
});
} else {
res.jsonp(series);
}
});
};