From 1c8625a8a00c16cf4b6cbbea41635c728f40d373 Mon Sep 17 00:00:00 2001 From: idoctnef Date: Fri, 7 Oct 2016 19:43:53 +0200 Subject: [PATCH] travels send only future dates, when delete travel returns all travels json --- README.md | 11 ++++++--- controllers/travelController.js | 11 ++++++--- controllers/userController.js | 44 ++++++++++++++++++++++++--------- 3 files changed, 47 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index ac32813..4a14efc 100644 --- a/README.md +++ b/README.md @@ -37,10 +37,12 @@ frontend app code: https://github.com/idoctnef/collectivecarApp -user unoffer car to a travel --> done -user unoffer car to a askingpackage --> done -comment publication(car, travel, package) --> done --valorating users system +-valorating users system --> done --passed dates not shown from server --don't allow to add travels with passed date +-passed dates not shown from server --> done +-don't allow to add travels with passed date (on frontend and backend) + +-acabar de fer robust quan esborres un travel -GUI admin page @@ -51,6 +53,9 @@ frontend app code: https://github.com/idoctnef/collectivecarApp -web page (webapp) --> (de moment es pot penjar la app en versió web tal qual, que es podrà fer servir des d'un navegador com si fós la app) + +-es veu el telèfon dels users? +-com evitem q algú xungu es registri a la app i vegi els viatges i info dels users? ``` diff --git a/controllers/travelController.js b/controllers/travelController.js index 770b68c..796c988 100644 --- a/controllers/travelController.js +++ b/controllers/travelController.js @@ -9,8 +9,8 @@ var commentModel = mongoose.model('commentModel'); //GET exports.findAllTravels = function(req, res) { - - travelModel.find(function(err, travels) { + //get travels with futures dates ($gte - greater than and equal than) + travelModel.find({date: {$gte: new Date()}}, function(err, travels) { if(err) res.send(500, err.message); res.status(200).jsonp(travels); @@ -104,8 +104,11 @@ exports.deleteTravel = function(req, res) { travelModel.findById(req.params.id, function(err, travel) { travel.remove(function(err) { if(err) return res.send(500, err.message); - res.status(200).jsonp(req.params.id); - console.log('DELETE /traves/' + req.params.id); + + travelModel.find(function(err, travels) { + if(err) res.send(500, err.message); + res.status(200).jsonp(travels); + }); }) }); }; diff --git a/controllers/userController.js b/controllers/userController.js index f914fd0..8f7aa0b 100644 --- a/controllers/userController.js +++ b/controllers/userController.js @@ -89,21 +89,41 @@ exports.addUser = function(req, res) { /* fav */ exports.addFav = function(req, res) { userModel.findById(req.params.userId, function(err, user){ - var fav = { - userId: req.body.userId, - username: req.body.username, - avatar: req.body.avatar - }; - user.favs.push(fav); - - user.save(function(err, user) { - if(err) return res.send(500, err.message); - //res.status(200).jsonp(travel); + + // first search if user have already said like + var favRepeated=false; + for(var i=0; i