Forked from misshula/gist:66ac1f77dc674a971918cae9f49c727b
Last active
April 19, 2017 20:08
-
-
Save earobinson/92987175178050a632223be0478f229b to your computer and use it in GitHub Desktop.
:slug or :id ORRRRRR :slugOrId
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
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