<commit_before>const familyMembersPromises = require('./familymembers.promises')
const modelConstants = require('./modelconstants')
const logger = require('winston')

const retrievePersonPhoneNumbersPromise = (data) => {
  logger.log('debug', '___familymembers_retrievePersonPhoneNumbersPromise', data)
  return familyMembersPromises.findFromNameFamilyPromise(data.person, data.familyId)
    .then(familyMembers => {
      if (familyMembers.length === 0) {
        logger.log('debug', 'no result')
        data.errorMessage = modelConstants.errorTypes.personNotFound
        throw data
      }
      data.phoneNumbers = familyMembers.map(familyMember => {
        return familyMember.phoneNumber
      })
      return data
    }, (error) => {
      data.errorMessage = modelConstants.errorTypes.generalError
      data.systemError = error
      throw data
    })
}

const retrievePersonFromPhoneNumberPromise = (data) => {
  logger.log('debug', '___familymembers_retrievePersonFromPhoneNumberPromise', data)
  return familyMembersPromises.findFromPhoneNumberPromise(data.fromPhoneNumber)
    .then(familyMembers => {
      if (familyMembers.length === 0) {
        logger.log('debug', 'phone number not found')
        data.errorMessage = modelConstants.errorTypes.personNotFound
        throw data
      }
      const foundPerson = familyMembers[0]
      data.fromPerson = foundPerson.name
      data.familyId = foundPerson.familyId
      data.timezone = foundPerson.timeZone || 'America/New_York'
      return data
    }, (error) => {
      data.errorMessage = modelConstants.errorTypes.generalError
      data.systemError = error
      throw data
    })
}

const updateFamilyMemberVerificationNumberPromise = (data) => {
  return familyMembersPromises.updateFamilyMemberVerificationNumberPromise(data.userId, data.fromPhoneNumber)
}

const saveNewFamilyMemberPromise = (data) => {
  logger.log('debug', '___familymembers_saveNewFamilyMemberPromise', data)
  const familyMember = {
    // userId
    familyId: data.familyId,
    name: data.name,
    description: data.description,
    phoneNumber: data.phonerNumber,
    timeZone: data.timeZone || 'America/New_York',
    verificationNumber: data.verificationNumber
  }
  return familyMembersPromises.saveNewFamilyMemberPromise(familyMember)
    .then(familyMember => {
      return data
    }, (error) => {
      data.errorMessage = modelConstants.errorTypes.generalError
      data.systemError = error
      throw data
    })
}
<commit_msg>add logging<commit_after>const familyMembersPromises = require('./familymembers.promises')
const modelConstants = require('./modelconstants')
const logger = require('winston')

const retrievePersonPhoneNumbersPromise = (data) => {
  logger.log('debug', '___familymembers_retrievePersonPhoneNumbersPromise', data)
  return familyMembersPromises.findFromNameFamilyPromise(data.person, data.familyId)
    .then(familyMembers => {
      if (familyMembers.length === 0) {
        logger.log('debug', 'no result')
        data.errorMessage = modelConstants.errorTypes.personNotFound
        throw data
      }
      data.phoneNumbers = familyMembers.map(familyMember => {
        return familyMember.phoneNumber
      })
      return data
    }, (error) => {
      data.errorMessage = modelConstants.errorTypes.generalError
      data.systemError = error
      throw data
    })
}

const retrievePersonFromPhoneNumberPromise = (data) => {
  logger.log('info', '___familymembers_retrievePersonFromPhoneNumberPromise', data)
  return familyMembersPromises.findFromPhoneNumberPromise(data.fromPhoneNumber)
    .then(familyMembers => {
      if (familyMembers.length === 0) {
        logger.log('debug', 'phone number not found')
        data.errorMessage = modelConstants.errorTypes.personNotFound
        throw data
      }
      const foundPerson = familyMembers[0]
      data.fromPerson = foundPerson.name
      data.familyId = foundPerson.familyId
      data.timezone = foundPerson.timeZone || 'America/New_York'
      return data
    }, (error) => {
      data.errorMessage = modelConstants.errorTypes.generalError
      data.systemError = error
      throw data
    })
}

const updateFamilyMemberVerificationNumberPromise = (data) => {
  logger.log('info', '___familymembers_updateFamilyMemberVerificationNumberPromise', data)
  return familyMembersPromises.updateFamilyMemberVerificationNumberPromise(data.userId, data.fromPhoneNumber)
}

const saveNewFamilyMemberPromise = (data) => {
  logger.log('info', '___familymembers_saveNewFamilyMemberPromise', data)
  const familyMember = {
    // userId
    familyId: data.familyId,
    name: data.name,
    description: data.description,
    phoneNumber: data.phonerNumber,
    timeZone: data.timeZone || 'America/New_York',
    verificationNumber: data.verificationNumber
  }
  return familyMembersPromises.saveNewFamilyMemberPromise(familyMember)
    .then(familyMember => {
      return data
    }, (error) => {
      data.errorMessage = modelConstants.errorTypes.generalError
      data.systemError = error
      throw data
    })
}

{'fraction_non_alphanumeric': 0.1006896551724138, 'fraction_numerical': 0.0011822660098522167, 'mean_word_length': 3.8250950570342206, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, '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': '4701931', 'n_tokens_mistral': 1404, 'n_tokens_neox': 1366, 'n_words': 248}