web: get all thoughts, user page

This commit is contained in:
nau
2016-07-17 20:44:45 +02:00
parent 1ba5d059e1
commit 0278360eeb
57 changed files with 284 additions and 6 deletions

View File

@@ -2,13 +2,53 @@
var mongoose = require('mongoose');
var thoughtModel = mongoose.model('thoughtModel');
var userModel = mongoose.model('userModel');
//GET - Return all tvshows in the DB
exports.findAllThoughts = function(req, res) {
thoughtModel.find(function(err, thoughts) {
if(err) res.send(500, err.message);
console.log('GET /thoughts');
res.status(200).jsonp(thoughts);
thoughtModel.find(function(err, thoughts) {
if(err) res.send(500, err.message);
console.log(thoughts.length);
thoughts=JSON.parse(JSON.stringify(thoughts));
thoughts.forEach(function(thought, index, array){
array=JSON.parse(JSON.stringify(array));
userModel.find({
username: thought.authorname
}, function(err, user) {
if (err) throw err;
if (!user) {
} else if (user) {
/*console.log(thought);
console.log(user);*/
array[index].usericon=user[0].icon;
console.log("icon: " + array[index].usericon);
//thought.set('icon', user.icon);
//console.log(thought);
}
if(index === array.length-1)
{
console.log('GET /thoughts');
console.log(array);
res.status(200).jsonp(array);
}
});
});
});
};

View File

@@ -22,7 +22,7 @@ exports.findAllUsers = function(req, res) {
//GET - Return a TVShow with specified ID
exports.findById = function(req, res) {
ActivityModel.findById(req.params.id, function(err, user) {
userModel.findById(req.params.id, function(err, user) {
if(err) return res.send(500, err.message);
console.log('GET /users/' + req.params.id);
@@ -30,6 +30,25 @@ exports.findById = function(req, res) {
});
};
exports.findUserByUsername = function(req, res) {
userModel.find({
username: req.params.username
}, function(err, user) {
if (err) throw err;
if (!user) {
res.json({ success: false, message: 'no user found' });
} else if (user) {
console.log(user);
// return the information including token as JSON
res.jsonp(user);
}
});
};
//POST - Insert a new TVShow in the DB
exports.addUser = function(req, res) {