Browse Source

delete travel and join travel implemented

pull/2/head
nau 8 years ago
parent
commit
8e98c356a4
5 changed files with 61 additions and 5 deletions
  1. +37
    -0
      controllers/travelController.js
  2. +4
    -2
      controllers/userController.js
  3. +13
    -0
      models/joinModel.js
  4. +1
    -3
      models/travelModel.js
  5. +6
    -0
      server.js

+ 37
- 0
controllers/travelController.js

@ -4,6 +4,8 @@ var travelModel = mongoose.model('travelModel');
var userModel = mongoose.model('userModel'); var userModel = mongoose.model('userModel');
var joinModel = mongoose.model('joinModel');
//GET //GET
exports.findAllTravels = function(req, res) { exports.findAllTravels = function(req, res) {
@ -100,3 +102,38 @@ exports.deleteTravel = function(req, res) {
}) })
}); });
}; };
/* join */
exports.addJoin = function(req, res) {
var join = new joinModel({
travelId: req.body.travelId,
joinedUserId: req.body.joinedUserId,
joinedUsername: req.body.joinedUsername,
acceptedUserId: req.body.acceptedUserId,
comment: req.body.comment
});
join.save(function(err, join) {
if(err) return res.send(500, err.message);
res.status(200).jsonp(join);
});
};
exports.getJoinsByTravelId = function(req, res) {
joinModel.find({
travelId: req.params.travelId
}, function(err, joins) {
if (err) throw err;
if (!joins) {
res.json({ success: false, message: 'no joins for travelId' });
} else if (joins) {
// return the information including token as JSON
res.jsonp(joins);
}
});
};

+ 4
- 2
controllers/userController.js

@ -34,8 +34,9 @@ exports.findById = function(req, res) {
console.log('GET /users/' + req.params.id); console.log('GET /users/' + req.params.id);
//password deletion //password deletion
if(user!=null){
user.password=""; user.password="";
}
res.status(200).jsonp(user); res.status(200).jsonp(user);
}); });
}; };
@ -144,7 +145,8 @@ console.log(user);
success: true, success: true,
message: 'Enjoy your token!', message: 'Enjoy your token!',
token: token, token: token,
avatar: user.avatar
avatar: user.avatar,
userid: user._id
}); });
} }

+ 13
- 0
models/joinModel.js

@ -0,0 +1,13 @@
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
var joinSchema = new Schema({
travelId: { type: String },
joinedUserId: { type: String },
joinedUsername: { type: String },
acceptedUserId: { type: String },
comment: { type: String }
});
module.exports = mongoose.model('joinModel', joinSchema);

+ 1
- 3
models/travelModel.js

@ -17,9 +17,7 @@ var travelSchema = new Schema({
phone: { type: Number }, phone: { type: Number },
telegram: { type: String }, telegram: { type: String },
collectivized: { type: Boolean }, collectivized: { type: Boolean },
modality: { type: String }, //if is an offering travel or asking for travel
joinedusers: { type: String },
acceptedusers: { type: String }
modality: { type: String } //if is an offering travel or asking for travel
}) })
module.exports = mongoose.model('travelModel', travelSchema); module.exports = mongoose.model('travelModel', travelSchema);

+ 6
- 0
server.js

@ -30,6 +30,7 @@ var userMdl = require('./models/userModel')(app, mongoose);
var userCtrl = require('./controllers/userController'); var userCtrl = require('./controllers/userController');
var travelMdl = require('./models/travelModel')(app, mongoose); var travelMdl = require('./models/travelModel')(app, mongoose);
var joinMdl = require('./models/joinModel')(app, mongoose);
var travelCtrl = require('./controllers/travelController'); var travelCtrl = require('./controllers/travelController');
/*// Example Route /*// Example Route
@ -70,6 +71,8 @@ apiRoutes.route('/travels')
apiRoutes.route('/travels/:id') apiRoutes.route('/travels/:id')
.get(travelCtrl.findById); .get(travelCtrl.findById);
apiRoutes.route('/travels/join/:travelId')
.get(travelCtrl.getJoinsByTravelId);
// OJU AQUÏ TREC la verificació de token temporalment, per fer les proves des de l'app // OJU AQUÏ TREC la verificació de token temporalment, per fer les proves des de l'app
// route middleware to verify a token // route middleware to verify a token
@ -116,6 +119,9 @@ apiRoutes.route('/travels/:id')
.put(travelCtrl.updateTravel) .put(travelCtrl.updateTravel)
.delete(travelCtrl.deleteTravel); .delete(travelCtrl.deleteTravel);
apiRoutes.route('/travels/join/:id')
.post(travelCtrl.addJoin);
app.use('/api', apiRoutes); app.use('/api', apiRoutes);
// end of API routes ------------------------------------- // end of API routes -------------------------------------

Loading…
Cancel
Save