Comment model

The Comment class inherited from the Comment of 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.

module/admin/model/Comment.js

const Base = require('../../../model/Comment');

module.exports = class Comment extends Base {

  static getConstants () {
    return {
      RULES: this.RULES.concat([
        ['status', 'range', {range: [
          this.STATUS_PENDING,
          this.STATUS_APPROVED,
          this.STATUS_REJECTED
        ]}]
      ]),
      ATTR_VALUE_LABELS: {
        'status': {
          [this.STATUS_PENDING]: 'Pending',
          [this.STATUS_APPROVED]: 'Approved',
          [this.STATUS_REJECTED]: 'Rejected'
        }
      }
    };
  }
  // place methods here
};
module.exports.init(module);

const Article = require('./Article');

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

module/admin/model/Comment.js

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

The relArticle relation finds article related to a comment.

module/admin/model/Comment.js

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