@@ -17,6 +17,7 @@ ArticleProvider.prototype.getCollection= function(callback) {
17
17
} ) ;
18
18
} ;
19
19
20
+ // find all blog posts in database
20
21
ArticleProvider . prototype . findAll = function ( callback ) {
21
22
this . getCollection ( function ( error , article_collection ) {
22
23
if ( error ) callback ( error )
@@ -29,7 +30,7 @@ ArticleProvider.prototype.findAll = function(callback) {
29
30
} ) ;
30
31
} ;
31
32
32
-
33
+ // find a blog post in the database by its object ID
33
34
ArticleProvider . prototype . findById = function ( id , callback ) {
34
35
this . getCollection ( function ( error , article_collection ) {
35
36
if ( error ) callback ( error )
@@ -42,6 +43,7 @@ ArticleProvider.prototype.findById = function(id, callback) {
42
43
} ) ;
43
44
} ;
44
45
46
+ // save a (new) blog post
45
47
ArticleProvider . prototype . save = function ( articles , callback ) {
46
48
this . getCollection ( function ( error , article_collection ) {
47
49
if ( error ) callback ( error )
@@ -67,6 +69,31 @@ ArticleProvider.prototype.save = function(articles, callback) {
67
69
} ) ;
68
70
} ;
69
71
72
+ // update a blog post
73
+ ArticleProvider . prototype . update = function ( articleId , articles , callback ) {
74
+ this . getCollection ( function ( error , article_collection ) {
75
+ if ( error ) callback ( error ) ;
76
+ else {
77
+ for ( var i = 0 ; i < articles . length ; i ++ ) {
78
+ article = articles [ i ] ;
79
+ text_to_replace = articles [ i ] . body ;
80
+ var paragraphs = article . body . split ( '\r\n\r\n' ) ;
81
+ article . body = paragraphs ;
82
+ }
83
+
84
+ article_collection . update (
85
+ { _id : article_collection . db . bson_serializer . ObjectID . createFromHexString ( articleId ) } ,
86
+ articles ,
87
+ function ( error , articles ) {
88
+ if ( error ) callback ( error ) ;
89
+ else callback ( null , articles )
90
+ } ) ;
91
+ }
92
+ } ) ;
93
+ } ;
94
+ ///////////////////////////////////////////////////////////////////////////////////////////////
95
+
96
+ // remove a blog post from the database
70
97
ArticleProvider . prototype . delete = function ( articleId , callback ) {
71
98
this . getCollection ( function ( error , article_collection ) {
72
99
if ( error ) callback ( error ) ;
0 commit comments