Build a blog with Areto Node.js framework

Comment model

The Comment class inherited from the Comment of the blog frontend.

Comment model

You can edit comment's status in the admin module. To do this, add the status validation of the range of values to inherited rules.

modules/admin/models/Comment.js

'use strict';
const Base = require('../../../models/Comment');
module.exports = class Comment extends Base { 
  static getConstants () {
    return {
      RULES: this.RULES.concat([
        ['status', 'range', {range: ['pending','approved','rejected']}]
      ])
    };
  }
  // place methods here
};
module.exports.init(module);
const Article = require('./Article');

The findBySearch method finds the comments containing your search text in the comment's content, author's name or email.

modules/admin/models/Comment.js

...
static findBySearch (text) {
  let query = this.find();
  if (text) {
    query.where(['OR', ['LIKE', 'content', `%${text}%`], {'name': text}, {'email': text}]);
  }
  return query;
}
...

The relArticle relation finds article related to a comment.

modules/admin/models/Comment.js

...
relArticle () {
  return this.hasOne(Article, [Article.PK, 'articleId']);
}
...