|
|
@@ -16,7 +16,8 @@ module.exports = function(crowi) {
|
|
|
|
|
|
, pageEvent = crowi.event('page')
|
|
|
|
|
|
- , pageSchema;
|
|
|
+ , pageSchema
|
|
|
+ , Comment = crowi.model('Comment');
|
|
|
|
|
|
function isPortalPath(path) {
|
|
|
if (path.match(/.*\/$/)) {
|
|
|
@@ -305,18 +306,19 @@ module.exports = function(crowi) {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
- pageSchema.statics.updateCommentCount = function (page, num)
|
|
|
+ pageSchema.statics.updateCommentCount = function (pageId)
|
|
|
{
|
|
|
var self = this;
|
|
|
-
|
|
|
- return new Promise(function(resolve, reject) {
|
|
|
- self.update({_id: page}, {commentCount: num}, {}, function(err, data) {
|
|
|
+ var Comment = crowi.model("Comment");
|
|
|
+ return Comment.countCommentByPageId(pageId)
|
|
|
+ .then(function(count) {
|
|
|
+ self.update({_id: pageId}, {commentCount: count}, {}, function(err, data) {
|
|
|
if (err) {
|
|
|
debug('Update commentCount Error', err);
|
|
|
- return reject(err);
|
|
|
+ throw err;
|
|
|
}
|
|
|
|
|
|
- return resolve(data);
|
|
|
+ return data;
|
|
|
});
|
|
|
});
|
|
|
};
|