function nestRelatedResources({ resourceDataMapping, data }) {
    const resource = resourceDataMapping.resource
    const obj = resourceDataMapping.object

    if (resource.relationships) {
      // for each relationship, add the relationship to the plain javascript object
      Object.keys(resource.relationships).forEach((relationshipName) => {
        const relationship = resource.relationships[relationshipName].data

        if (Array.isArray(relationship)) {
          obj[relationshipName] = relationship.map((relationshipResource, index) => {
            const relationshipType = relationshipResource.type
            let relatedObj = { id: obj[relationshipName][index].id }

            if (data[relationshipType]) {
              const tempRelatedObj = data[relationshipType].find(d => d.id === obj[relationshipName][index].id)

              if (tempRelatedObj) {
                relatedObj = tempRelatedObj
              }
            }

            return relatedObj
          })
        } else {
          const relationshipType = relationship.type

          if (data[relationshipType]) {
            const relatedObj = data[relationshipType].find(d => d.id === obj[relationshipName].id)

            if (relatedObj) {
              obj[relationshipName] = relatedObj
            }
          }
        }
      })
    }
  }
/**
   * Nest related resources as defined by the json-api relationships
   * @param  {Object} args
   * @param  {Object} args.resourceDataMapping - An object that maps a resource to a raw data object
   * @param  {Object} args.data - An object where each key is the name of a data type and each value is an array of raw data objects
   */
Nest related resources as defined by the json-api relationships
@param  {Object} args
@param  {Object} args.resourceDataMapping - An object that maps a resource to a raw data object
@param  {Object} args.data - An object where each key is the name of a data type and each value is an array of raw data objects
Nest related resources as defined by the json - api relationships @param { Object } args @param { Object } args . resourceDataMapping - An object that maps a resource to a raw data object @param { Object } args . data - An object where each key is the name of a data type and each value is an array of raw data objects
function nestRelatedResources({ resourceDataMapping, data }) {
    const resource = resourceDataMapping.resource
    const obj = resourceDataMapping.object
    if (resource.relationships) {
      Object.keys(resource.relationships).forEach((relationshipName) => {
        const relationship = resource.relationships[relationshipName].data
        if (Array.isArray(relationship)) {
          obj[relationshipName] = relationship.map((relationshipResource, index) => {
            const relationshipType = relationshipResource.type
            let relatedObj = { id: obj[relationshipName][index].id }
            if (data[relationshipType]) {
              const tempRelatedObj = data[relationshipType].find(d => d.id === obj[relationshipName][index].id)
              if (tempRelatedObj) {
                relatedObj = tempRelatedObj
              }
            }
            return relatedObj
          })
        } else {
          const relationshipType = relationship.type
          if (data[relationshipType]) {
            const relatedObj = data[relationshipType].find(d => d.id === obj[relationshipName].id)
            if (relatedObj) {
              obj[relationshipName] = relatedObj
            }
          }
        }
      })
    }
  }
function nestRelatedResources ( { resourceDataMapping , data } ) { const resource = resourceDataMapping . resource const obj = resourceDataMapping . object if ( resource . relationships ) { Object . keys ( resource . relationships ) . forEach ( ( relationshipName ) => { const relationship = resource . relationships [ relationshipName ] . data if ( Array . isArray ( relationship ) ) { obj [ relationshipName ] = relationship . map ( ( relationshipResource , index ) => { const relationshipType = relationshipResource . type let relatedObj = { id : obj [ relationshipName ] [ index ] . id } if ( data [ relationshipType ] ) { const tempRelatedObj = data [ relationshipType ] . find ( d => d . id === obj [ relationshipName ] [ index ] . id ) if ( tempRelatedObj ) { relatedObj = tempRelatedObj } } return relatedObj } ) } else { const relationshipType = relationship . type if ( data [ relationshipType ] ) { const relatedObj = data [ relationshipType ] . find ( d => d . id === obj [ relationshipName ] . id ) if ( relatedObj ) { obj [ relationshipName ] = relatedObj } } } } ) } }
Nest related resources as defined by the json-api relationships
 @param  {Object} args
 @param  {Object} args.resourceDataMapping - An object that maps a resource to a raw data object
 @param  {Object} args.data - An object where each key is the name of a data type and each value is an array of raw data objects
Nest related resources as defined by the json - api relationships @param { Object } args @param { Object } args . resourceDataMapping - An object that maps a resource to a raw data object @param { Object } args . data - An object where each key is the name of a data type and each value is an array of raw data objects
// for each relationship, add the relationship to the plain javascript object