This repository was archived by the owner on Aug 30, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +3
-20
lines changed Expand file tree Collapse file tree 2 files changed +3
-20
lines changed Original file line number Diff line number Diff line change @@ -88,7 +88,7 @@ exports.list = function(req, res) {
88
88
* Article middleware
89
89
*/
90
90
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 ) {
92
92
if ( err ) return next ( err ) ;
93
93
if ( ! article ) return next ( new Error ( 'Failed to load article ' + id ) ) ;
94
94
req . article = article ;
Original file line number Diff line number Diff line change @@ -17,7 +17,8 @@ var ArticleSchema = new Schema({
17
17
title : {
18
18
type : String ,
19
19
default : '' ,
20
- trim : true
20
+ trim : true ,
21
+ required : 'Title cannot be blank'
21
22
} ,
22
23
content : {
23
24
type : String ,
@@ -30,22 +31,4 @@ var ArticleSchema = new Schema({
30
31
}
31
32
} ) ;
32
33
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
-
51
34
mongoose . model ( 'Article' , ArticleSchema ) ;
You can’t perform that action at this time.
0 commit comments