<commit_before>'use strict';

import _ from 'lodash';
import mongoose from 'mongoose';
import utils from '../../../configs/utils';
const Comment = mongoose.model('Comment');
const Topic = mongoose.model('Topic');
const Panel = mongoose.model('Panel');
const Core = mongoose.model('Core');

/**
 * Controller that process comment request.
 *
 * @author <NAME>
 * @module Konko/Posts/Controllers/Comment
 */
export default class CommentController {

  /**
   * @constructs
   */
  constructor() {}

  /**
   * Update Comment Schema so that it meets the limit config from Core settings.
   *
   * @param {Object} res - HTTP response.
   * @returns {Response} Response 500 if error exist.
   */
  static updateSchema(res) {
    return new Promise((resolve, reject) => {
      Core.find().then(cores => {
        let { post: { comment: { content } } } = cores[0];
        Comment.schema.path('content', {
          type: String,
          required: '{PATH} is required',
          minlength: content.min,
          maxlength: content.max,
        });
        resolve(cores[0]);
      }).catch(err => res.status(500).json({ message: err }));
    }).then(core => core);
  }

  /**
   * Get a comment then populates it, response as json.
   *
   * @param {Object} req - HTTP request.
   * @param {Object} res - HTTP response.
   * @static
   */
  static get({ comment }, res) {
    comment.populate('topic', '_id title panel').populate({
      path: 'author',
      select: '_id profile',
      populate: {
        path: 'profile',
        model: 'Profile',
        select: 'username avatar',
      },
    }, (err, comment) => {
      if (err) {
        return res.status(500).json({ message: err });
      }

      res.status(200).json(comment);
    });
  }

  /**
   * Query all comments of a topic then populates them, response as json.
   *
   * @param {Object} req - HTTP request.
   * @param {Object} res - HTTP response.
   * @static
   */
  static list({ sanitizeQuery, query, topic, payload }, res) {
    sanitizeQuery('page').toInt();

    let page = {};
    page.page = query.page || 1;
    page.size = payload.preference.commentListLimit;
    page.offset = (page.page - 1) * page.size;
    page.tid = topic._id;
    Comment.find({ topic: topic._id }, '-short', { skip: page.offset, limit: page.size })<commit_msg>inline return<commit_after>'use strict';

import _ from 'lodash';
import mongoose from 'mongoose';
import utils from '../../../configs/utils';
const Comment = mongoose.model('Comment');
const Topic = mongoose.model('Topic');
const Panel = mongoose.model('Panel');
const Core = mongoose.model('Core');

/**
 * Controller that process comment request.
 *
 * @author <NAME>
 * @module Konko/Posts/Controllers/Comment
 */
export default class CommentController {

  /**
   * @constructs
   */
  constructor() {}

  /**
   * Update Comment Schema so that it meets the limit config from Core settings.
   *
   * @param {Object} res - HTTP response.
   * @returns {Response} Response 500 if error exist.
   */
  static updateSchema(res) {
    return new Promise((resolve, reject) => {
      Core.find().then(cores => {
        let { post: { comment: { content } } } = cores[0];
        Comment.schema.path('content', {
          type: String,
          required: '{PATH} is required',
          minlength: content.min,
          maxlength: content.max,
        });
        resolve(cores[0]);
      }).catch(err => res.status(500).json({ message: err }));
    }).then(core => core);
  }

  /**
   * Get a comment then populates it, response as json.
   *
   * @param {Object} req - HTTP request.
   * @param {Object} res - HTTP response.
   * @static
   */
  static get({ comment }, res) {
    comment.populate('topic', '_id title panel').populate({
      path: 'author',
      select: '_id profile',
      populate: {
        path: 'profile',
        model: 'Profile',
        select: 'username avatar',
      },
    }, (err, comment) => {
      return err ? res.status(500).json({ message: err }) : res.status(200).json(comment);
    });
  }

  /**
   * Query all comments of a topic then populates them, response as json.
   *
   * @param {Object} req - HTTP request.
   * @param {Object} res - HTTP response.
   * @static
   */
  static list({ sanitizeQuery, query, topic, payload }, res) {
    sanitizeQuery('page').toInt();

    let page = {};
    page.page = query.page || 1;
    page.size = payload.preference.commentListLimit;
    page.offset = (page.page - 1) * page.size;
    page.tid = topic._id;
    Comment.find({ topic: topic._id }, '-short', { skip: page.offset, limit: page.size })
{'fraction_non_alphanumeric': 0.15997395268070327, 'fraction_numerical': 0.006945951812459301, 'mean_word_length': 2.588785046728972, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5561043', 'n_tokens_mistral': 1422, 'n_tokens_neox': 1398, 'n_words': 394}