@ -0,0 +1,95 @@ |
|||
//File: controllers/projectController.js
|
|||
var mongoose = require('mongoose'); |
|||
var projectModel = mongoose.model('projectModel'); |
|||
|
|||
var userModel = mongoose.model('userModel'); |
|||
|
|||
//GET
|
|||
exports.findAllProjects = function(req, res) { |
|||
|
|||
projectModel.find(function(err, projects) { |
|||
if(err) res.send(500, err.message); |
|||
|
|||
res.status(200).jsonp(projects); |
|||
}); |
|||
|
|||
|
|||
}; |
|||
|
|||
//GET
|
|||
exports.findById = function(req, res) { |
|||
projectModel.findById(req.params.id, function(err, project) { |
|||
if(err) return res.send(500, err.message); |
|||
|
|||
console.log('GET /project/' + req.params.id); |
|||
res.status(200).jsonp(project); |
|||
}); |
|||
}; |
|||
|
|||
exports.findAllProjectsFromUsername = function(req, res) { |
|||
projectModel.find({ |
|||
owner: req.params.username |
|||
}, function(err, projects) { |
|||
|
|||
if (err) throw err; |
|||
|
|||
if (!projects) { |
|||
res.json({ success: false, message: 'no projects for user' }); |
|||
} else if (projects) { |
|||
console.log(projects); |
|||
// return the information including token as JSON
|
|||
res.jsonp(projects); |
|||
|
|||
|
|||
} |
|||
|
|||
}); |
|||
}; |
|||
|
|||
exports.addProject = function(req, res) { |
|||
console.log('POST new project, title: ' + req.body.title); |
|||
var project = new projectModel({ |
|||
title: req.body.title, |
|||
description: req.body.description, |
|||
icon: req.body.icon, |
|||
users: req.body.users, |
|||
chart: req.body.chart, |
|||
dateCreation: req.body.dateCreation, |
|||
github: req.body.github, |
|||
refnum: req.body.refnum |
|||
}); |
|||
|
|||
project.save(function(err, project) { |
|||
if(err) return res.send(500, err.message); |
|||
res.status(200).jsonp(project); |
|||
}); |
|||
}; |
|||
|
|||
//PUT
|
|||
exports.updateProject = function(req, res) { |
|||
ActivityModel.findById(req.params.id, function(err, tvshow) { |
|||
tvshow.title = req.body.petId; |
|||
tvshow.year = req.body.year; |
|||
tvshow.country = req.body.country; |
|||
tvshow.poster = req.body.poster; |
|||
tvshow.seasons = req.body.seasons; |
|||
tvshow.genre = req.body.genre; |
|||
tvshow.summary = req.body.summary; |
|||
|
|||
tvshow.save(function(err) { |
|||
if(err) return res.send(500, err.message); |
|||
res.status(200).jsonp(tvshow); |
|||
}); |
|||
}); |
|||
}; |
|||
|
|||
//DELETE
|
|||
exports.deleteProject = function(req, res) { |
|||
ActivityModel.findById(req.params.id, function(err, activity) { |
|||
activity.remove(function(err) { |
|||
if(err) return res.send(500, err.message); |
|||
res.status(200).jsonp(req.params.id); |
|||
console.log('DELETE /activities/' + req.params.id); |
|||
}) |
|||
}); |
|||
}; |
@ -1,102 +0,0 @@ |
|||
//File: controllers/travelController.js
|
|||
var mongoose = require('mongoose'); |
|||
var travelModel = mongoose.model('travelModel'); |
|||
|
|||
var userModel = mongoose.model('userModel'); |
|||
|
|||
//GET
|
|||
exports.findAllTravels = function(req, res) { |
|||
|
|||
travelModel.find(function(err, travels) { |
|||
if(err) res.send(500, err.message); |
|||
|
|||
res.status(200).jsonp(travels); |
|||
}); |
|||
|
|||
|
|||
}; |
|||
|
|||
//GET
|
|||
exports.findById = function(req, res) { |
|||
travelModel.findById(req.params.id, function(err, travel) { |
|||
if(err) return res.send(500, err.message); |
|||
|
|||
console.log('GET /travel/' + req.params.id); |
|||
res.status(200).jsonp(travel); |
|||
}); |
|||
}; |
|||
|
|||
exports.findAllTravelsFromUsername = function(req, res) { |
|||
travelModel.find({ |
|||
owner: req.params.username |
|||
}, function(err, travels) { |
|||
|
|||
if (err) throw err; |
|||
|
|||
if (!travels) { |
|||
res.json({ success: false, message: 'no travels for user' }); |
|||
} else if (travels) { |
|||
console.log(travels); |
|||
// return the information including token as JSON
|
|||
res.jsonp(travels); |
|||
|
|||
|
|||
} |
|||
|
|||
}); |
|||
}; |
|||
|
|||
exports.addTravel = function(req, res) { |
|||
console.log('POST new travel, title: ' + req.body.title); |
|||
var travel = new travelModel({ |
|||
title: req.body.title, |
|||
description: req.body.description, |
|||
owner: req.body.owner, |
|||
from: req.body.from, |
|||
to: req.body.to, |
|||
date: req.body.date, |
|||
periodic: req.body.periodic, |
|||
generateddate: req.body.generateddate, |
|||
seats: req.body.seats, |
|||
package: req.body.package, |
|||
icon: req.body.icon, |
|||
phone: req.body.phone, |
|||
telegram: req.body.telegram, |
|||
collectivized: req.body.collectivized, |
|||
modality: req.body.modality |
|||
}); |
|||
|
|||
travel.save(function(err, travel) { |
|||
if(err) return res.send(500, err.message); |
|||
res.status(200).jsonp(travel); |
|||
}); |
|||
}; |
|||
|
|||
//PUT
|
|||
exports.updateTravel = function(req, res) { |
|||
ActivityModel.findById(req.params.id, function(err, tvshow) { |
|||
tvshow.title = req.body.petId; |
|||
tvshow.year = req.body.year; |
|||
tvshow.country = req.body.country; |
|||
tvshow.poster = req.body.poster; |
|||
tvshow.seasons = req.body.seasons; |
|||
tvshow.genre = req.body.genre; |
|||
tvshow.summary = req.body.summary; |
|||
|
|||
tvshow.save(function(err) { |
|||
if(err) return res.send(500, err.message); |
|||
res.status(200).jsonp(tvshow); |
|||
}); |
|||
}); |
|||
}; |
|||
|
|||
//DELETE
|
|||
exports.deleteTravel = function(req, res) { |
|||
ActivityModel.findById(req.params.id, function(err, activity) { |
|||
activity.remove(function(err) { |
|||
if(err) return res.send(500, err.message); |
|||
res.status(200).jsonp(req.params.id); |
|||
console.log('DELETE /activities/' + req.params.id); |
|||
}) |
|||
}); |
|||
}; |
@ -0,0 +1,18 @@ |
|||
var mongoose = require('mongoose'), |
|||
Schema = mongoose.Schema; |
|||
|
|||
|
|||
var travelSchema = new Schema({ |
|||
title: { type: String }, |
|||
description: { type: String }, |
|||
icon: { type: String }, |
|||
users: { type: String }, |
|||
chart: { type: String }, |
|||
dateCreation: { type: Date }, |
|||
github: { type: String }, |
|||
refnum: { type: String } |
|||
}) |
|||
module.exports = mongoose.model('projectModel', travelSchema); |
|||
|
|||
|
|||
//modality can be: offering, asking, package
|
@ -1,25 +0,0 @@ |
|||
var mongoose = require('mongoose'), |
|||
Schema = mongoose.Schema; |
|||
|
|||
|
|||
var travelSchema = new Schema({ |
|||
title: { type: String }, |
|||
description: { type: String }, |
|||
owner: { type: String }, |
|||
from: { type: String }, |
|||
to: { type: String }, |
|||
date: { type: Date }, |
|||
periodic: { type: Boolean }, |
|||
generateddate: { type: Date }, |
|||
seats: { type: Number }, |
|||
package: { type: Boolean }, |
|||
icon: { type: String }, |
|||
phone: { type: Number }, |
|||
telegram: { type: String }, |
|||
collectivized: { type: Boolean }, |
|||
modality: { type: String } //if is an offering travel or asking for travel
|
|||
}) |
|||
module.exports = mongoose.model('travelModel', travelSchema); |
|||
|
|||
|
|||
//modality can be: offering, asking, package
|