Last active
December 14, 2018 01:31
-
-
Save yosvelquintero/57dd7645e50e3612b8e9e62fa161b256 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
const getPhotoFromProfile = profile => { | |
try { | |
return profile.Photographs[0].URLS[0]; | |
} catch (err) { | |
return '/images/placeholder.jpg'; // default to placeholder image | |
} | |
}; | |
const getFullNameFromProfile = profile => `${profile.Christian_Name} ${profile.Surname}`; | |
export default function parseUserData(authApiData, profileApiData, notificationsApiData) { | |
const profile = profileApiData.Profiles[0]; | |
const notifications = Object.entries(notificationsApiData.data).map(([id, notification]) => ({ | |
id, | |
dateTime: new Date(Number(notification.timestamp) * 1000), // date from server was seconds since epoch, not milliseconds | |
name: getFullNameFromProfile(notification.user), | |
photoUrl: getPhotoFromProfile(notification.user), | |
message: notification.message, | |
premiumMember: notification.user.Enhanced === 'True', // honestly, who does this? | |
})); | |
return { | |
jwt: authApiData.jwt, | |
id: authApiData.userId.toString(), // IDs should always be strings | |
name: getFullNameFromProfile(profile), | |
photoUrl: getPhotoFromProfile(profile), | |
notifications: notifications, // notifications array should always exist, even if empty | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment