parseAndWriteAvatar: Do shallow copy before omit() call

Otherwise, we get all prototype props/functions, which we can't save in IndexedDB
This commit is contained in:
Scott Nonnenberg 2018-05-08 16:49:58 -07:00
parent 3bf8a8966a
commit d2293d9592

View file

@ -14,14 +14,18 @@ exports.parseAndWriteAvatar = upgradeAttachment => async (
) => {
const { message } = context;
const { avatar } = contact;
// This is to ensure that an omit() call doesn't pull in prototype props/methods
const contactShallowCopy = Object.assign({}, contact);
const contactWithUpdatedAvatar =
avatar && avatar.avatar
? Object.assign({}, contact, {
? Object.assign({}, contactShallowCopy, {
avatar: Object.assign({}, avatar, {
avatar: await upgradeAttachment(avatar.avatar, context),
}),
})
: omit(contact, ['avatar']);
: omit(contactShallowCopy, ['avatar']);
// eliminates empty numbers, emails, and addresses; adds type if not provided
const parsedContact = parseContact(contactWithUpdatedAvatar);