<commit_before>const config = require('../../../knexfile').intweb
const knex = require('knex')(config)
const dateFormatter = require('../date-formatter')
const tasksEnum = require('../../constants/tasks-enum')
const insertClaimEvent = require('./insert-claim-event')
const insertTaskSendClaimNotification = require('./insert-task-send-claim-notification')
const log = require('../log')

module.exports = function (claimId, claimNote) {
  return knex('Claim').where('ClaimId', claimId)
    .join('Eligibility', 'Claim.EligibilityId', '=', 'Eligibility.EligibilityId')
    .first('Eligibility.EligibilityId', 'Eligibility.Reference')
    .then(function (result) {
      var eligibilityId = result.EligibilityId
      var reference = result.Reference
      var caseworker = result.caseworker
      var decision = result.decision
      var note = claimNote
      var nomisCheck = result.nomisCheck
      var dwpCheck = result.dwpCheck
      var visitConfirmationCheck = result.visitConfirmationCheck
      var rejectionReasonId = result.rejectionReasonId

      return Promise.all([updateClaim(claimId, note),
        insertClaimEventForNote(reference, eligibilityId, claimId, decision, note, caseworker),
        sendClaimNotification(reference, eligibilityId, claimId, decision)])
    })
}

function updateClaim (claimId, note) {
  var updateObject = {}

  updateObject = {
    'Note': note,
    'LastUpdated': dateFormatter.now().toDate()
  }

  if (updateObject.Note.length > 250) {
    updateObject.Note = updateObject.Note.substring(0, 250)
  }

  return knex('Claim').where('ClaimId', claimId).update(updateObject).then(
    log.info('Claim ID ' + claimId + ' note added: ' + updateObject.Note)
  )
}

function insertClaimEventForNote (reference, eligibilityId, claimId, decision, note, caseworker) {
  const event = `CLAIM-NOTE`
  return insertClaimEvent(reference, eligibilityId, claimId, event, null, note, 'Note', false)
}

function sendClaimNotification (reference, eligibilityId, claimId, decision) {
  var notificationType
  
  notificationType = tasksEnum.REQUEST_INFORMATION_CLAIM_NOTIFICATION
  
  return insertTaskSendClaimNotification(notificationType, reference, eligibilityId, claimId)
}
<commit_msg>Making note internal<commit_after>const config = require('../../../knexfile').intweb
const knex = require('knex')(config)
const dateFormatter = require('../date-formatter')
const tasksEnum = require('../../constants/tasks-enum')
const insertClaimEvent = require('./insert-claim-event')
const insertTaskSendClaimNotification = require('./insert-task-send-claim-notification')
const log = require('../log')

module.exports = function (claimId, claimNote) {
  return knex('Claim').where('ClaimId', claimId)
    .join('Eligibility', 'Claim.EligibilityId', '=', 'Eligibility.EligibilityId')
    .first('Eligibility.EligibilityId', 'Eligibility.Reference')
    .then(function (result) {
      var eligibilityId = result.EligibilityId
      var reference = result.Reference
      var caseworker = result.caseworker
      var decision = result.decision
      var note = claimNote
      var nomisCheck = result.nomisCheck
      var dwpCheck = result.dwpCheck
      var visitConfirmationCheck = result.visitConfirmationCheck
      var rejectionReasonId = result.rejectionReasonId

      return Promise.all([updateClaim(claimId, note),
        insertClaimEventForNote(reference, eligibilityId, claimId, decision, note, caseworker),
        sendClaimNotification(reference, eligibilityId, claimId, decision)])
    })
}

function updateClaim (claimId, note) {
  var updateObject = {}

  updateObject = {
    'Note': note,
    'LastUpdated': dateFormatter.now().toDate()
  }

  if (updateObject.Note.length > 250) {
    updateObject.Note = updateObject.Note.substring(0, 250)
  }

  return knex('Claim').where('ClaimId', claimId).update(updateObject).then(
    log.info('Claim ID ' + claimId + ' note added: ' + updateObject.Note)
  )
}

function insertClaimEventForNote (reference, eligibilityId, claimId, decision, note, caseworker) {
  const event = `CLAIM-NOTE`
  return insertClaimEvent(reference, eligibilityId, claimId, event, null, note, 'Note', true)
}

function sendClaimNotification (reference, eligibilityId, claimId, decision) {
  var notificationType
  
  notificationType = tasksEnum.REQUEST_INFORMATION_CLAIM_NOTIFICATION
  
  return insertTaskSendClaimNotification(notificationType, reference, eligibilityId, claimId)
}

{'fraction_non_alphanumeric': 0.12117117117117117, 'fraction_numerical': 0.003153153153153153, 'mean_word_length': 4.5721455457967375, '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': '341302', 'n_tokens_mistral': 1306, 'n_tokens_neox': 1240, 'n_words': 274}