-
-
Save 6ewis/a2403779cd5dd7446585599c3a2e7540 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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