mirror of
https://github.com/arnaucube/thoughts.git
synced 2026-02-06 19:26:47 +01:00
web: get all thoughts, user page
This commit is contained in:
@@ -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);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user