normalizeRelations: Return empty array as fallback

This commit is contained in:
Gustav Hansen 2022-09-07 19:14:14 +02:00
parent 6d1642d713
commit 3e90c71ead

View File

@ -6,16 +6,12 @@ export const normalizeRelations = (
relations, relations,
{ modifiedData = {}, shouldAddLink = false, mainFieldName, targetModel } { modifiedData = {}, shouldAddLink = false, mainFieldName, targetModel }
) => { ) => {
// TODO
if (!relations?.data?.pages) {
return relations;
}
return { return {
...relations, ...relations,
data: { data: {
pages: relations.data.pages pages:
.map((page) => [ relations?.data?.pages
?.map((page) => [
...[...page.results, ...(modifiedData?.connect ?? [])] ...[...page.results, ...(modifiedData?.connect ?? [])]
.map((relation) => { .map((relation) => {
const nextRelation = { ...relation }; const nextRelation = { ...relation };
@ -42,8 +38,8 @@ export const normalizeRelations = (
}) })
.filter(Boolean), .filter(Boolean),
]) ])
.filter((page) => page.length > 0) ?.filter((page) => page.length > 0)
.reverse(), ?.reverse() ?? [],
}, },
}; };
}; };