Browse Source

implemented get user travels offering and travels joined

master
arnaucode 8 years ago
parent
commit
7ae0ba5f1b
2 changed files with 29 additions and 0 deletions
  1. +26
    -0
      controllers/userController.js
  2. +3
    -0
      server.js

+ 26
- 0
controllers/userController.js

@ -2,6 +2,7 @@
var mongoose = require('mongoose');
var userModel = mongoose.model('userModel');
var notificationModel = mongoose.model('notificationModel');
var travelModel = mongoose.model('travelModel');
/* */
@ -138,6 +139,31 @@ exports.getUserByToken = function (req, res) {
}
});
};
exports.getTravelsByUserId = function (req, res) {
travelModel.find(
{
user: req.params.userid
}
)
.lean()
.exec(function (err, travels) {
if (err) return res.send(500, err.message);
travelModel.find(
{
joins: req.params.userid
}
)
.lean()
.exec(function (err, joins) {
if (err) return res.send(500, err.message);
res.json({
travels: travels,
joins: joins
});
});
});
};
exports.getNotifications = function (req, res) {
userModel.findOne({'token': req.headers['x-access-token']})
.lean()

+ 3
- 0
server.js

@ -117,6 +117,9 @@ apiRoutes.route('/users/token')
apiRoutes.route('/users')//agafa l'user a partir del token
.put(userCtrl.updateUser)//no comprovat
.delete(userCtrl.deleteUser);
apiRoutes.route('/users/id/travels/:userid')
.get(userCtrl.getTravelsByUserId);
apiRoutes.route('/travels')
.post(travelCtrl.addTravel);
apiRoutes.route('/travels/id/modify/:travelid')

Loading…
Cancel
Save