Created
April 28, 2018 02:40
-
-
Save jamesplease/bed66031c0e3a61c9a2babb572f87683 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Given a flat resource and its schema, returns a full resource. | |
export default function fullFromFlat({ resource, schema }) { | |
const attributes = Object.values(schema.attributes); | |
const metas = Object.values(schema.meta); | |
const newAttributes = {}; | |
attributes.map(attribute => { | |
if (resource[attribute]) { | |
newAttributes[attribute] = resource[attribute]; | |
} | |
}); | |
const newMeta = {}; | |
metas.map(meta => { | |
if (resource[meta]) { | |
newMeta[meta] = resource[meta]; | |
} | |
}); | |
return { | |
[schema.idAttribute]: resource[schema.idAttribute], | |
resourceType: schema.resourceType, | |
attributes: newAttributes, | |
meta: newMeta, | |
relationships: {}, | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment