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

Commit c11c428

Browse files
committed
Article Cleanup
1 parent 47561ce commit c11c428

File tree

2 files changed

+3
-20
lines changed

2 files changed

+3
-20
lines changed

app/controllers/articles.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ exports.list = function(req, res) {
8888
* Article middleware
8989
*/
9090
exports.articleByID = function(req, res, next, id) {
91-
Article.load(id, function(err, article) {
91+
Article.findById(id).populate('user', 'displayName').exec(function(err, article) {
9292
if (err) return next(err);
9393
if (!article) return next(new Error('Failed to load article ' + id));
9494
req.article = article;

app/models/article.js

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ var ArticleSchema = new Schema({
1717
title: {
1818
type: String,
1919
default: '',
20-
trim: true
20+
trim: true,
21+
required: 'Title cannot be blank'
2122
},
2223
content: {
2324
type: String,
@@ -30,22 +31,4 @@ var ArticleSchema = new Schema({
3031
}
3132
});
3233

33-
/**
34-
* Validations
35-
*/
36-
ArticleSchema.path('title').validate(function(title) {
37-
return title.length;
38-
}, 'Title cannot be blank');
39-
40-
/**
41-
* Statics
42-
*/
43-
ArticleSchema.statics = {
44-
load: function(id, cb) {
45-
this.findOne({
46-
_id: id
47-
}).populate('user', 'displayName').exec(cb);
48-
}
49-
};
50-
5134
mongoose.model('Article', ArticleSchema);

0 commit comments

Comments
 (0)