From 0f88e29e925fa5d6745c407b515b8fac4e92e201 Mon Sep 17 00:00:00 2001 From: arnaucode Date: Fri, 24 Feb 2017 01:55:42 +0100 Subject: [PATCH] get categoriesList, and populate on getEventsByFollowingArray and getEventsByCategory --- controllers/eventController.js | 29 +++++++++++++++++++++++++++++ server.js | 2 ++ 2 files changed, 31 insertions(+) diff --git a/controllers/eventController.js b/controllers/eventController.js index b83695f..e11b10b 100644 --- a/controllers/eventController.js +++ b/controllers/eventController.js @@ -9,6 +9,30 @@ var eventModel = mongoose.model('eventModel'); var pageSize=config.pageSize; + +exports.getCategoriesList = function(req, res) { + var categoriesList=[ + { + name: "esport" + }, + { + name: "xerrada" + }, + { + name: "taller" + }, + { + name: "festa" + }, + { + name: "concert" + }, + { + name: "musica" + } + ] + res.status(200).jsonp(categoriesList); +}; exports.getAllEvents = function(req, res) { eventModel.find({ date: {$gte: new Date()}, @@ -71,6 +95,7 @@ exports.addEvent = function(req, res) { date: req.body.date, categories: req.body.categories, generateddate: Date(), + location: req.body.location, user: user._id }); @@ -154,6 +179,8 @@ exports.getEventsByFollowingArray = function(req, res) { date: {$gte: new Date()}, 'username': req.body.users }) + .lean() + .populate('user', 'username img shortDescription') .sort('date') .limit(pageSize) .skip(pageSize * Number(req.query.page)) @@ -173,6 +200,8 @@ exports.getEventsByCategory = function(req, res) { date: {$gte: new Date()}, 'categories.name': req.params.category }) + .lean() + .populate('user', 'username img shortDescription') .sort('date') .limit(pageSize) .skip(pageSize * Number(req.query.page)) diff --git a/server.js b/server.js index 85e815b..f4f555e 100644 --- a/server.js +++ b/server.js @@ -68,6 +68,8 @@ apiRoutes.route('/events/following') apiRoutes.route('/events/category/:category') .get(eventCtrl.getEventsByCategory); +apiRoutes.route('/categoriesList') + .get(eventCtrl.getCategoriesList); // route middleware to verify a token apiRoutes.use(function(req, res, next) { // check header or url parameters or post parameters for token