Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Commit

Permalink
Added semicolons to server code for consistency and general formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Oley committed Aug 16, 2013
1 parent d7c04a8 commit 82ef533
Show file tree
Hide file tree
Showing 10 changed files with 263 additions and 282 deletions.
69 changes: 35 additions & 34 deletions app/controllers/articles.js
Original file line number Diff line number Diff line change
@@ -1,70 +1,71 @@
/**
* Module dependencies.
*/

var mongoose = require('mongoose')
, async = require('async')
, Article = mongoose.model('Article')
, _ = require('underscore')
var mongoose = require('mongoose'),
async = require('async'),
Article = mongoose.model('Article'),
_ = require('underscore');


/**
* Find article by id
*/

exports.article = function(req, res, next, id){
var User = mongoose.model('User')
var User = mongoose.model('User');

Article.load(id, function (err, article) {
if (err) return next(err)
if (!article) return next(new Error('Failed to load article ' + id))
req.article = article
next()
})
}
if (err) return next(err);
if (!article) return next(new Error('Failed to load article ' + id));
req.article = article;
next();
});
};

/**
* Create a article
*/
exports.create = function (req, res) {
var article = new Article(req.body)
article.user = req.user
article.save()
res.jsonp(article)
}
var article = new Article(req.body);

article.user = req.user;
article.save();
res.jsonp(article);
};

/**
* Update a article
*/
exports.update = function(req, res){
var article = req.article
article = _.extend(article, req.body)
var article = req.article;

article = _.extend(article, req.body);

article.save(function(err) {
res.jsonp(article)
})
}
res.jsonp(article);
});
};

/**
* Delete an article
*/
exports.destroy = function(req, res){
var article = req.article
var article = req.article;

article.remove(function(err){
if (err) {
res.render('error', {status: 500});
} else {
res.jsonp(article);
}
})
}
res.render('error', {status: 500});
} else {
res.jsonp(article);
}
});
};

/**
* Show an article
*/
exports.show = function(req, res){
res.jsonp(req.article);
}
};

/**
* List of Articles
Expand All @@ -73,8 +74,8 @@ exports.all = function(req, res){
Article.find().sort('-created').populate('user').exec(function(err, articles) {
if (err) {
res.render('error', {status: 500});
} else {
res.jsonp(articles);
} else {
res.jsonp(articles);
}
});
}
};
11 changes: 5 additions & 6 deletions app/controllers/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
/**
* Module dependencies.
*/

var mongoose = require('mongoose')
, async = require('async')
, _ = require('underscore')
var mongoose = require('mongoose'),
async = require('async'),
_ = require('underscore');


exports.render = function(req, res){
res.render('index', {
user: req.user ? JSON.stringify(req.user) : "null"
})
}
});
};
76 changes: 36 additions & 40 deletions app/controllers/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,104 +2,100 @@
/**
* Module dependencies.
*/

var mongoose = require('mongoose')
, User = mongoose.model('User')
var mongoose = require('mongoose'),
User = mongoose.model('User');

//exports.signin = function (req, res) {}

/**
* Auth callback
*/

exports.authCallback = function (req, res, next) {
res.redirect('/')
}
res.redirect('/');
};

/**
* Show login form
*/

exports.signin = function (req, res) {
res.render('users/signin', {
title: 'Signin',
message: req.flash('error')
})
}
});
};

/**
* Show sign up form
*/

exports.signup = function (req, res) {
res.render('users/signup', {
title: 'Sign up',
user: new User()
})
}
});
};

/**
* Logout
*/

exports.signout = function (req, res) {
req.logout()
res.redirect('/')
}
req.logout();
res.redirect('/');
};

/**
* Session
*/

exports.session = function (req, res) {
res.redirect('/')
}
res.redirect('/');
};

/**
* Create user
*/

exports.create = function (req, res) {
var user = new User(req.body)
user.provider = 'local'
var user = new User(req.body);

user.provider = 'local';
user.save(function (err) {
if (err) {
return res.render('users/signup', { errors: err.errors, user: user })
return res.render('users/signup', { errors: err.errors, user: user });
}
req.logIn(user, function(err) {
if (err) return next(err)
return res.redirect('/')
})
})
}
if (err) return next(err);
return res.redirect('/');
});
});
};

/**
* Show profile
*/

exports.show = function (req, res) {
var user = req.profile
var user = req.profile;

res.render('users/show', {
title: user.name,
user: user
})
}
});
};

/**
* Send User
*/
exports.me = function (req, res) {
res.jsonp(req.user || null);
}
};

/**
* Find user by id
*/

exports.user = function (req, res, next, id) {
User
.findOne({ _id : id })
.exec(function (err, user) {
if (err) return next(err)
if (!user) return next(new Error('Failed to load User ' + id))
req.profile = user
next()
})
}
if (err) return next(err);
if (!user) return next(new Error('Failed to load User ' + id));
req.profile = user;
next();
});
};
12 changes: 5 additions & 7 deletions app/models/article.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
/**
* Module dependencies.
*/
var mongoose = require('mongoose')
, env = process.env.NODE_ENV || 'development'
, config = require('../../config/config')[env]
, Schema = mongoose.Schema;
var mongoose = require('mongoose'),
env = process.env.NODE_ENV || 'development',
config = require('../../config/config')[env],
Schema = mongoose.Schema;


/**
* Article Schema
*/

var ArticleSchema = new Schema({
created: {type : Date, default : Date.now},
title: {type: String, default: '', trim : true},
content: {type: String, default: '', trim : true},
user: {type : Schema.ObjectId, ref : 'User'}
});


/**
* Statics
*/

ArticleSchema.statics = {
load: function (id, cb) {
this.findOne({ _id : id }).populate('user').exec(cb);
Expand Down
Loading

0 comments on commit 82ef533

Please sign in to comment.