<commit_before>crypto = require 'crypto'
_ = require 'underscore'

Singleton = require 'singleton'
Riak = require "#{__dirname}/../db/riak"
TimeEntry = require "#{__dirname}/../models/time_entry"

class TimeEntriesController extends Singleton
  bucket: 'time_entries'
  idGen: ()->
    sha = crypto.createHash 'sha1'
    _.each arguments, (d)->
      sha.update JSON.stringify d
    sha.digest 'hex'

  create: (time_entry, callback)->
    if time_entry.userId and time_entry.projectId
      id = @idGen time_entry

      handler = (err, obj, meta) ->
        if err
          callback err
        else
          te = new TimeEntry obj
          te.id = id
          callback null, te

      console.log id, @bucket
      Riak.getClient().save @bucket, id, time_entry,
        {
          index:
            userId: time_entry.userId
            projectId: time_entry.projectId
        }, handler

module.exports = TimeEntriesController.get()<commit_msg>Send back the original time entry<commit_after>crypto = require 'crypto'
_ = require 'underscore'

Singleton = require 'singleton'
Riak = require "#{__dirname}/../db/riak"
TimeEntry = require "#{__dirname}/../models/time_entry"

class TimeEntriesController extends Singleton
  bucket: 'time_entries'
  idGen: ()->
    sha = crypto.createHash 'sha1'
    _.each arguments, (d)->
      sha.update JSON.stringify d
    sha.digest 'hex'

  create: (time_entry, callback)->
    if time_entry.userId and time_entry.projectId
      time_entry.id = @idGen time_entry

      handler = (err, obj, meta) ->
        console.log err, obj, meta
        if err
          callback err
        else
          callback null, time_entry

      Riak.getClient().save @bucket, time_entry.id, time_entry,
        {
          index:
            userId: time_entry.userId
            projectId: time_entry.projectId
        }, handler

module.exports = TimeEntriesController.get()
{'fraction_non_alphanumeric': 0.10633839706652698, 'fraction_numerical': 0.0010476689366160294, 'mean_word_length': 2.4854014598540144, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '6062760', 'n_tokens_mistral': 572, 'n_tokens_neox': 567, 'n_words': 149}