Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save earobinson/86ccf46e2f3d7ada683f638df70ce349 to your computer and use it in GitHub Desktop.
Save earobinson/86ccf46e2f3d7ada683f638df70ce349 to your computer and use it in GitHub Desktop.
:slug or :id ORRRRRR :slugOrId
exports.fetchRetailer = function(req, res, next) {
let queryParams = null;
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) {
ORRRRRRR
exports.fetchRetailer = function(req, res, next) {
let queryParams = null;
if (req.params.slugOrId) {
queryParams = {
$or: [
{ _id: req.params.slugOrId },
{ slug: decodeURIComponent(req.params.slugOrId.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