Browse Source

implemented get user travels offering and travels joined

master
arnaucode 7 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 mongoose = require('mongoose');
var userModel = mongoose.model('userModel'); var userModel = mongoose.model('userModel');
var notificationModel = mongoose.model('notificationModel'); 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) { exports.getNotifications = function (req, res) {
userModel.findOne({'token': req.headers['x-access-token']}) userModel.findOne({'token': req.headers['x-access-token']})
.lean() .lean()

+ 3
- 0
server.js

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

Loading…
Cancel
Save