Skip to content

Instantly share code, notes, and snippets.

@yosvelquintero
Last active December 14, 2018 01:31
Show Gist options
  • Save yosvelquintero/57dd7645e50e3612b8e9e62fa161b256 to your computer and use it in GitHub Desktop.
Save yosvelquintero/57dd7645e50e3612b8e9e62fa161b256 to your computer and use it in GitHub Desktop.
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