Created
March 18, 2018 20:04
-
-
Save Colour-Full/76e8e4db91c3ce883a13208e471b508c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var keystone = require('keystone'); | |
/** | |
* List Recipe | |
*/ | |
// Getting our recipe model | |
var Recipe = keystone.list('Recipe'); | |
// Creating the API end point | |
exports.list = function (req, res) { | |
// Querying the data this works similarly to the Mongo db.collection.find() method | |
Recipe.model.find(function (err, items) { | |
// Make sure we are handling errors | |
if (err) return res.apiError('database error', err); | |
res.apiResponse({ | |
// Filter recipe by | |
recipe: items, | |
}); | |
// Using express req.query we can limit the number of recipes returned by setting a limit property in the link | |
// This is handy if we want to speed up loading times once our recipe collection grows | |
}).limit(Number(req.query.limit)); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment