diff --git a/controllers/eventController.js b/controllers/eventController.js index e11b10b..34bb021 100644 --- a/controllers/eventController.js +++ b/controllers/eventController.js @@ -210,3 +210,21 @@ exports.getEventsByCategory = function(req, res) { res.status(200).jsonp(events); }); }; + +exports.getEventsByDay = function(req, res) { + var dayRequested= new Date(req.params.day); + eventModel.find({ + date: { + $gte: dayRequested + } + }) + .lean() + .populate('user', 'username img shortDescription') + .sort('date') + .limit(pageSize) + .skip(pageSize * Number(req.query.page)) + .exec(function (err, events) { + if (err) return res.send(500, err.message); + res.status(200).jsonp(events); + }); +}; diff --git a/server.js b/server.js index f4f555e..458097a 100644 --- a/server.js +++ b/server.js @@ -67,6 +67,8 @@ apiRoutes.route('/events/following') .post(eventCtrl.getEventsByFollowingArray); apiRoutes.route('/events/category/:category') .get(eventCtrl.getEventsByCategory); +apiRoutes.route('/events/day/:day') + .get(eventCtrl.getEventsByDay); apiRoutes.route('/categoriesList') .get(eventCtrl.getCategoriesList);