Browse Source

pagination added on getAllTravels

master
arnaucode 7 years ago
parent
commit
a29558b80e
2 changed files with 4 additions and 22 deletions
  1. +4
    -20
      controllers/travelController.js
  2. +0
    -2
      server.js

+ 4
- 20
controllers/travelController.js

@ -6,11 +6,13 @@ var travelModel = mongoose.model('travelModel');
var commentModel = mongoose.model('commentModel');
//GET
var pageSize=2;
exports.getAllTravels = function(req, res) {
//get travels with futures dates ($gte - greater than and equal than)
travelModel.find({date: {$gte: new Date()}})
.limit(Number(req.query.pageSize))
.skip(Number(req.query.pageSize) * Number(req.query.page))
.sort('date')
.limit(pageSize)
.skip(pageSize * Number(req.query.page))
.exec(function (err, travels) {
if (err) return res.send(500, err.message);
res.status(200).jsonp(travels);
@ -423,24 +425,6 @@ exports.leave = function(req, res) {
});
};
exports.getTravelsByUserId = function(req, res) {
travelModel.find({
user: req.params.userid
})
.lean()
.populate('joins', 'username avatar')
.populate('comments', 'comment user')
.exec(function (err, travels) {
if (err) return res.send(500, err.message);
if (!travels) {
res.json({success: false, message: 'travel not found.'});
} else if (travels) {
res.status(200).jsonp(travels);
}
});
};

+ 0
- 2
server.js

@ -131,8 +131,6 @@ apiRoutes.route('/travels/unjoin/:travelid')
.post(travelCtrl.unJoin);
apiRoutes.route('/travels/leave/:travelid')
.post(travelCtrl.leave);
apiRoutes.route('/travels/byuser/id/:userid')
.get(travelCtrl.getTravelsByUserId);
apiRoutes.route('/travels/declineJoin/:travelid')
.post(travelCtrl.declineJoin);
apiRoutes.route('/travels/acceptJoin/:travelid')

Loading…
Cancel
Save