<commit_before>'use strict';

const Q = require('q'),
    models = require('../models'),
    logger = require('../lib/logger'),
    moment = require('moment'),
    Address = models.Address,
    Branch = models.Branch,
    Group = models.Group,
    Member = models.Member,
    uuid = require('node-uuid'),
    messagingService = require('./messagingService'),
    branchService = require('./branchService');


function createHash() {
  return uuid.v4();
}

function save(member) {
  return Member.create.bind(Member)(member);
}

function handleError(message) {
    return function(error) {
        logger.error(message, { error: error.toString() });
        return models.Sequelize.Promise.reject(message);
    };
}

function setupNewMember(newMember) {
  return function (residentialAddress, postalAddress) {
    let residentialAddressId = residentialAddress ? residentialAddress[0].dataValues.id : null;
    let postalAddressId = postalAddress ? postalAddress[0].dataValues.id : null;

    return {
        id: createHash(),
        email: newMember.email,
        firstName: newMember.firstName,
        lastName: newMember.lastName,
        gender: newMember.gender,
        primaryPhoneNumber: newMember.primaryPhoneNumber,
        secondaryPhoneNumber: newMember.secondaryPhoneNumber,
        dateOfBirth: moment(newMember.dateOfBirth, 'DD/MM/YYYY').toDate(),
        membershipType: newMember.membershipType,
        memberSince: moment(),
        contactFirstName: newMember.contactFirstName,
        contactLastName: newMember.contactLastName,
        schoolType: newMember.schoolType,
        residentialAddressId: residentialAddressId,
        postalAddressId: postalAddressId,
        additionalInfo: newMember.additionalInfo
    };
  };
}

function logEvent(saveResult) {
    logger.info('[member-sign-up-event]', saveResult.dataValues);
}<commit_msg>Extracting basic member parsing<commit_after>'use strict';

const Q = require('q'),
    models = require('../models'),
    logger = require('../lib/logger'),
    moment = require('moment'),
    Address = models.Address,
    Branch = models.Branch,
    Group = models.Group,
    Member = models.Member,
    uuid = require('node-uuid'),
    messagingService = require('./messagingService'),
    branchService = require('./branchService');


function createHash() {
  return uuid.v4();
}

function save(member) {
  return Member.create.bind(Member)(member);
}

function handleError(message) {
    return function(error) {
        logger.error(message, { error: error.toString() });
        return models.Sequelize.Promise.reject(message);
    };
}

function parse(newMember, residentialAddress, postalAddress) {
    let residentialAddressId = residentialAddress ? residentialAddress[0].dataValues.id : null;
    let postalAddressId = postalAddress ? postalAddress[0].dataValues.id : null;

    return {
        id: createHash(),
        email: newMember.email,
        firstName: newMember.firstName,
        lastName: newMember.lastName,
        gender: newMember.gender,
        primaryPhoneNumber: newMember.primaryPhoneNumber,
        secondaryPhoneNumber: newMember.secondaryPhoneNumber,
        dateOfBirth: moment(newMember.dateOfBirth, 'DD/MM/YYYY').toDate(),
        membershipType: newMember.membershipType,
        contactFirstName: newMember.contactFirstName,
        contactLastName: newMember.contactLastName,
        schoolType: newMember.schoolType,
        residentialAddressId: residentialAddressId,
        postalAddressId: postalAddressId,
        additionalInfo: newMember.additionalInfo
    };
}

function setupNewMember(newMember) {
  return function (residentialAddress, postalAddress) {
    let memberToSave = parse(newMember, residentialAddress, postalAddress);

    return Object.assign({}, memberToSave, {id: createHash(), memberSince: moment()});
  };
}

function logEvent(saveResult) {
    logger.info('[member-sign-up-event]', saveResult.dataValues);
}
{'fraction_non_alphanumeric': 0.11793050976413898, 'fraction_numerical': 0.001521683996956632, 'mean_word_length': 3.7177033492822966, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1994351', 'n_tokens_mistral': 1093, 'n_tokens_neox': 1079, 'n_words': 209}