Browse Source

update travel works

master
arnaucode 6 years ago
parent
commit
daa70d2ae1
3 changed files with 1026 additions and 14 deletions
  1. +21
    -13
      controllers/travelController.js
  2. +1004
    -0
      package-lock.json
  3. +1
    -1
      server.js

+ 21
- 13
controllers/travelController.js

@ -82,19 +82,27 @@ exports.updateTravel = function(req, res) {
userModel.findOne({'token': req.headers['x-access-token']})
.exec(function(err, user){
if (err) return res.send(500, err.message);
console.log(travel);
travelModel.findOne({_id: travel._id})
.lean()
.populate('travels', 'title from to date')
.exec(function (err, travel) {
if (err) return res.send(500, err.message);
if (!travel) {
res.json({success: false, message: 'travel not found.'});
} else if (travel) {
res.status(200).jsonp(travel);
}
});
// search if the travel exist for that user
travelModel.findOne({_id: req.body._id, user: user._id})
.exec(function(err, travel){
if (!travel) {
res.send(500, 'travel not found.');
} else if (travel) {
// now update travel
travelModel.update({
_id: req.body._id, user: user._id
}, req.body,
function(err, travel) {
if (err) {
res.send(500, 'travel not found.');
}
console.log(travel);
res.status(200).jsonp(travel);
});
}
});
});
};

+ 1004
- 0
package-lock.json
File diff suppressed because it is too large
View File


+ 1
- 1
server.js

@ -150,7 +150,7 @@ apiRoutes.route('/users/id/travels/:userid')
apiRoutes.route('/travels')
.post(travelCtrl.addTravel);
apiRoutes.route('/travels/id/modify/:travelid')
.put(travelCtrl.updateTravel)//no comprovat
.put(travelCtrl.updateTravel)
.delete(travelCtrl.deleteTravel);
apiRoutes.route('/travels/join/:travelid')
.post(travelCtrl.addJoinPetition);

Loading…
Cancel
Save