Skip to content

Instantly share code, notes, and snippets.

@6ewis
Created April 12, 2016 17:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 6ewis/a2403779cd5dd7446585599c3a2e7540 to your computer and use it in GitHub Desktop.
Save 6ewis/a2403779cd5dd7446585599c3a2e7540 to your computer and use it in GitHub Desktop.
import R from 'ramda';
export default (data) => {
let serializeNullValue = value => (value === 'null' ? null : value);
let serializeEntityType = entity_type => {
switch (entity_type) {
case 'I': return 'Individual';
case 'C': return 'Company';
}
};
let addRegisteredAddress = (object) =>
R.assoc('concatenated_registered_address',
String.raw`${object.regaddr_line_1 || ''}
${object.regaddr_line_2 || ''}
${object.regaddr_line_3 || ''}
${object.regaddr_line_4 || ''}
${object.regaddr_locality || ''}
${object.regaddr_region || ''}
${object.regaddr_postal_code || ''}
${object.regaddr_country_name || ''}
`)(object);
let addMailingAddress = (object) =>
R.assoc('concatenated_mailing_address',
String.raw`${object.mailaddr_line_1 || ''}
${object.mailaddr_line_2 || ''}
${object.mailaddr_line_3 || ''}
${object.mailaddr_line_4 || ''}
${object.mailaddr_locality || ''}
${object.mailaddr_region || ''}
${object.mailaddr_postal_code || ''}
${object.mailaddr_country_name || ''}
`)(object);
let addDividendAddress = (object) =>
R.assoc('concatenated_dividend_address',
String.raw`${object.divaddr_line_1 || ''}
${object.divaddr_line_2 || ''}
${object.divaddr_line_3 || ''}
${object.divaddr_line_4 || ''}
${object.divaddr_locality || ''}
${object.divaddr_region || ''}
${object.divaddr_postal_code || ''}
${object.divaddr_country_name || ''}
`)(object);
let updateEntityType = R.evolve({
'entity_type': serializeEntityType
});
let objectUpdater = R.compose(addMailingAddress, addDividendAddress, addRegisteredAddress, R.map(serializeNullValue), updateEntityType);
return R.map(objectUpdater, data);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment