Skip to content

Instantly share code, notes, and snippets.

@Colour-Full
Created March 18, 2018 20:04
Show Gist options
  • Save Colour-Full/76e8e4db91c3ce883a13208e471b508c to your computer and use it in GitHub Desktop.
Save Colour-Full/76e8e4db91c3ce883a13208e471b508c to your computer and use it in GitHub Desktop.
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