Browse Source

get categoriesList, and populate on getEventsByFollowingArray and getEventsByCategory

master
arnaucode 7 years ago
parent
commit
0f88e29e92
2 changed files with 31 additions and 0 deletions
  1. +29
    -0
      controllers/eventController.js
  2. +2
    -0
      server.js

+ 29
- 0
controllers/eventController.js

@ -9,6 +9,30 @@ var eventModel = mongoose.model('eventModel');
var pageSize=config.pageSize; 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) { exports.getAllEvents = function(req, res) {
eventModel.find({ eventModel.find({
date: {$gte: new Date()}, date: {$gte: new Date()},
@ -71,6 +95,7 @@ exports.addEvent = function(req, res) {
date: req.body.date, date: req.body.date,
categories: req.body.categories, categories: req.body.categories,
generateddate: Date(), generateddate: Date(),
location: req.body.location,
user: user._id user: user._id
}); });
@ -154,6 +179,8 @@ exports.getEventsByFollowingArray = function(req, res) {
date: {$gte: new Date()}, date: {$gte: new Date()},
'username': req.body.users 'username': req.body.users
}) })
.lean()
.populate('user', 'username img shortDescription')
.sort('date') .sort('date')
.limit(pageSize) .limit(pageSize)
.skip(pageSize * Number(req.query.page)) .skip(pageSize * Number(req.query.page))
@ -173,6 +200,8 @@ exports.getEventsByCategory = function(req, res) {
date: {$gte: new Date()}, date: {$gte: new Date()},
'categories.name': req.params.category 'categories.name': req.params.category
}) })
.lean()
.populate('user', 'username img shortDescription')
.sort('date') .sort('date')
.limit(pageSize) .limit(pageSize)
.skip(pageSize * Number(req.query.page)) .skip(pageSize * Number(req.query.page))

+ 2
- 0
server.js

@ -68,6 +68,8 @@ apiRoutes.route('/events/following')
apiRoutes.route('/events/category/:category') apiRoutes.route('/events/category/:category')
.get(eventCtrl.getEventsByCategory); .get(eventCtrl.getEventsByCategory);
apiRoutes.route('/categoriesList')
.get(eventCtrl.getCategoriesList);
// route middleware to verify a token // route middleware to verify a token
apiRoutes.use(function(req, res, next) { apiRoutes.use(function(req, res, next) {
// check header or url parameters or post parameters for token // check header or url parameters or post parameters for token

Loading…
Cancel
Save