Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save earobinson/92987175178050a632223be0478f229b to your computer and use it in GitHub Desktop.
Save earobinson/92987175178050a632223be0478f229b to your computer and use it in GitHub Desktop.
:slug or :id ORRRRRR :slugOrId
exports.fetchRetailer = function(req, res, next) {
const queryParams = {};
if (req.params.id) {
if (!validator.isMongoId(req.params.id.toString())) {
logger.error('`retailer.fetchBrand`: invalid retailer param, not a mongo id.', logger.context({
params: req.params
}));
return next({
code: 404,
status: 'No retailer found'
});
}
queryParams._id: req.params.id;
} else if (req.params.slug) {
queryParams.slug: decodeURIComponent(req.params.slug.trim().toLowerCase());
} else {
logger.error('`retailer.fetchBrand`: No retailer id or slug provided', logger.context({
params: req.params
}));
return next({
code: 400,
status: 'No retailer id or slug provided'
});
}
Retailer.findOne(queryParams, function(err, retailerModel) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment