From 3480b90a7ac87abd5c9f997a69f1a14740cce7f6 Mon Sep 17 00:00:00 2001 From: arnaucode Date: Sat, 25 Feb 2017 00:14:10 +0100 Subject: [PATCH] events by day implemented, todo: calendar view to select a day --- controllers/eventController.js | 18 ++++++++++++++++++ server.js | 2 ++ 2 files changed, 20 insertions(+) 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);