<commit_before>var uuid = require('node-uuid')
  , models = require('../models');

exports.addModel = function(db) {
  function Comment(params) {
    console.log('new Comment(' + JSON.stringify(params) + ')')
    this.body = params.body
    this.postId = params.postId

    this.createdAt = parseInt(params.createdAt) ||  null

    // TODO: not implemented yet
    this.updatedAt = parseInt(params.updatedAt) ||  null

    // params to filter
    this.id = params.id

    this.userId = params.userId
    this.user = params.user
  }

  Comment.find = function(commentId, callback) {
    console.log('Comment.find("' + commentId + '")')
    db.hgetall('comment:' + commentId, function(err, attrs) {
      // TODO: check if we find a comment
      attrs.id = commentId
      var comment = new Comment(attrs)
      models.User.find(attrs.userId, function(user) {
        comment.user = user
        return callback(comment)
      })
    })
  }

  // TODO: commentId -> commentsId
  Comment.destroy = function(commentId, callback) {
    console.log('Comment.destroy("' + commentId + '")')
    db.del('comment:' + commentId, function(err, res) {
      callback(err, res)
    })
  }

  Comment.prototype = {
    save: function(callback) {
      var that = this
      // User us allowed to create a comment if and only if its
      // post is created and exists.
      db.exists('post:' + this.postId, function(err, res) {
        // post exists
        console.log("!!!")
        console.log(res)
        if (res == 1) { 
          that.createdAt = new Date().getTime()
          if (that.id === undefined) that.id = uuid.v4()
<commit_msg>Fixes typo.<commit_after>var uuid = require('node-uuid')
  , models = require('../models');

exports.addModel = function(db) {
  function Comment(params) {
    console.log('new Comment(' + JSON.stringify(params) + ')')
    this.body = params.body
    this.postId = params.postId

    this.createdAt = parseInt(params.createdAt) ||  null

    // TODO: not implemented yet
    this.updatedAt = parseInt(params.updatedAt) ||  null

    // params to filter
    this.id = params.id

    this.userId = params.userId
    this.user = params.user
  }

  Comment.find = function(commentId, callback) {
    console.log('Comment.find("' + commentId + '")')
    db.hgetall('comment:' + commentId, function(err, attrs) {
      // TODO: check if we find a comment
      attrs.id = commentId
      var comment = new Comment(attrs)
      models.User.find(attrs.userId, function(user) {
        comment.user = user
        return callback(comment)
      })
    })
  }

  // TODO: commentId -> commentsId
  Comment.destroy = function(commentId, callback) {
    console.log('Comment.destroy("' + commentId + '")')
    db.del('comment:' + commentId, function(err, res) {
      callback(err, res)
    })
  }

  Comment.prototype = {
    save: function(callback) {
      var that = this
      // User is allowed to create a comment if and only if its
      // post is created and exists.
      db.exists('post:' + this.postId, function(err, res) {
        // post exists
        console.log("!!!")
        console.log(res)
        if (res == 1) { 
          that.createdAt = new Date().getTime()
          if (that.id === undefined) that.id = uuid.v4()

{'fraction_non_alphanumeric': 0.14438994481912937, 'fraction_numerical': 0.001226241569589209, 'mean_word_length': 2.497320471596999, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4400487', 'n_tokens_mistral': 1004, 'n_tokens_neox': 1003, 'n_words': 239}