From 7ae0ba5f1bee8e76fe1e5a812c3ece885a139efc Mon Sep 17 00:00:00 2001 From: arnaucode Date: Tue, 31 Jan 2017 16:37:51 +0100 Subject: [PATCH] implemented get user travels offering and travels joined --- controllers/userController.js | 26 ++++++++++++++++++++++++++ server.js | 3 +++ 2 files changed, 29 insertions(+) diff --git a/controllers/userController.js b/controllers/userController.js index 411f0d8..a5bea96 100644 --- a/controllers/userController.js +++ b/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() diff --git a/server.js b/server.js index 6b82482..8bd3c14 100755 --- a/server.js +++ b/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')