Browse Source

travels send only future dates, when delete travel returns all travels json

master
idoctnef 8 years ago
parent
commit
1c8625a8a0
3 changed files with 47 additions and 19 deletions
  1. +8
    -3
      README.md
  2. +7
    -4
      controllers/travelController.js
  3. +32
    -12
      controllers/userController.js

+ 8
- 3
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?
```

+ 7
- 4
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);
});
})
});
};

+ 32
- 12
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<user.favs.length; i++)
{
if(user.favs[i].username==req.body.username)
{
favRepeated=true;
}
}
console.log("favRepeated: " + favRepeated);
if(favRepeated==false)
{
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);
userModel.find(function(err, users) {
if(err) res.send(500, err.message);
res.status(200).jsonp(users);
});
});
}else{
userModel.find(function(err, users) {
if(err) res.send(500, err.message);
if(err) res.send(500, err.message);
res.status(200).jsonp(users);
});
});
}
});
};
exports.doUnfav = function(req, res) {

Loading…
Cancel
Save