Skip to content
This repository has been archived by the owner on Nov 22, 2022. It is now read-only.

Commit

Permalink
Fix relationships checking
Browse files Browse the repository at this point in the history
  • Loading branch information
aplegatt committed Aug 11, 2022
1 parent 1a9a4c2 commit 834c720
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/helpers/jsonApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const findDocument = <DocumentType extends JsonApiDocument>(

return (
(spreeSuccessResponse.included.find(
(includedObject) => includedObject.type === relationType.type && includedObject.id === relationType.id
(includedObject) => includedObject?.type === relationType?.type && includedObject?.id === relationType?.id
) as DocumentType) || null
)
}
Expand All @@ -26,9 +26,10 @@ const findRelationshipDocuments = <DocumentType extends JsonApiDocument>(
return []
}

const isRelationshipPresent = relationshipName in sourceDocument.relationships
const oneOrManyDocumentReferences = (sourceDocument.relationships[relationshipName] || {}).data

if (!oneOrManyDocumentReferences) {
if (!isRelationshipPresent) {
throw new DocumentRelationshipError(`Incorrect relationship ${relationshipName}.`)
}

Expand Down

0 comments on commit 834c720

Please sign in to comment.