Skip to content

Instantly share code, notes, and snippets.

@ORESoftware
Created September 29, 2015 04:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ORESoftware/1512b3f0d20dc8afb181 to your computer and use it in GitHub Desktop.
Save ORESoftware/1512b3f0d20dc8afb181 to your computer and use it in GitHub Desktop.
/**
* Created by amills001c on 8/18/15.
*/
function getAll(Model, modelName, filterObject, req, res, next, cb) {
if (!Model) {
Model = req.site.models[modelName];
}
if (!Model) {
throw new Error('no model matched modelName --> ' + modelName);
}
filterObject = filterObject || {};
Model.get(function (err, Model) {
if (err) {
throw err;
}
Model.find(filterObject, function (err, items) {
if (err) {
res.json({error: err.toString()});
return next(err);
}
else {
res.json({success: items});
}
});
});
}
module.exports = getAll;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment