From 9267c57e6ce7c46efbf27b8d8a96130d51f13714 Mon Sep 17 00:00:00 2001 From: Vigneshkumar Chinnachamy M Date: Tue, 17 Dec 2019 21:48:34 +0530 Subject: [PATCH] fix home country code trait --- src/routes/settings/helpers/settings.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/routes/settings/helpers/settings.js b/src/routes/settings/helpers/settings.js index d5ca1b074..7a242dc55 100644 --- a/src/routes/settings/helpers/settings.js +++ b/src/routes/settings/helpers/settings.js @@ -2,6 +2,7 @@ * Setting related helper methods */ import _ from 'lodash' +import ISOCountries from '../../../helpers/ISOCountries' // blank traits object which we can use if trait doesn't exist to create a new one export const blankTraits = { @@ -118,12 +119,21 @@ export const applyProfileSettingsToTraits = (traits, profileSettings) => { // define country similar to connect_info if not present for basic_info const country = _.get(trait, 'traits.data[0].country', profileSettings.country) + // Convert home country code from 3 digit numeric string to 3 letter alphabetical code. + // Numeric code is not supported by member service. + let homeCountryCode = _.get(trait, 'traits.data[0].homeCountryCode') + if (homeCountryCode && /^\d{3}$/.test(homeCountryCode)) { + const homeCountryISO = _.find(ISOCountries, c => c.numericString === homeCountryCode) + homeCountryCode = homeCountryISO && homeCountryISO.alpha3 + } + // update only if new values are defined const updatedProps = _.omitBy({ photoURL, firstName, lastName, country, + homeCountryCode, }, _.isUndefined) updatedTrait.traits = {