Created
September 29, 2015 04:30
-
-
Save ORESoftware/1512b3f0d20dc8afb181 to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* 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