mirror of
https://github.com/strapi/strapi.git
synced 2025-12-12 15:32:42 +00:00
normalizeRelations: Return empty array as fallback
This commit is contained in:
parent
6d1642d713
commit
3e90c71ead
@ -6,44 +6,40 @@ export const normalizeRelations = (
|
||||
relations,
|
||||
{ modifiedData = {}, shouldAddLink = false, mainFieldName, targetModel }
|
||||
) => {
|
||||
// TODO
|
||||
if (!relations?.data?.pages) {
|
||||
return relations;
|
||||
}
|
||||
|
||||
return {
|
||||
...relations,
|
||||
data: {
|
||||
pages: relations.data.pages
|
||||
.map((page) => [
|
||||
...[...page.results, ...(modifiedData?.connect ?? [])]
|
||||
.map((relation) => {
|
||||
const nextRelation = { ...relation };
|
||||
pages:
|
||||
relations?.data?.pages
|
||||
?.map((page) => [
|
||||
...[...page.results, ...(modifiedData?.connect ?? [])]
|
||||
.map((relation) => {
|
||||
const nextRelation = { ...relation };
|
||||
|
||||
if (modifiedData?.disconnect?.find((relation) => relation.id === nextRelation.id)) {
|
||||
return null;
|
||||
}
|
||||
if (modifiedData?.disconnect?.find((relation) => relation.id === nextRelation.id)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (shouldAddLink) {
|
||||
nextRelation.href = getRelationLink(targetModel, nextRelation.id);
|
||||
}
|
||||
if (shouldAddLink) {
|
||||
nextRelation.href = getRelationLink(targetModel, nextRelation.id);
|
||||
}
|
||||
|
||||
nextRelation.publicationState = false;
|
||||
nextRelation.publicationState = false;
|
||||
|
||||
if (nextRelation?.publishedAt !== undefined) {
|
||||
nextRelation.publicationState = nextRelation.publishedAt
|
||||
? PUBLICATION_STATES.PUBLISHED
|
||||
: PUBLICATION_STATES.DRAFT;
|
||||
}
|
||||
if (nextRelation?.publishedAt !== undefined) {
|
||||
nextRelation.publicationState = nextRelation.publishedAt
|
||||
? PUBLICATION_STATES.PUBLISHED
|
||||
: PUBLICATION_STATES.DRAFT;
|
||||
}
|
||||
|
||||
nextRelation.mainField = nextRelation[mainFieldName];
|
||||
nextRelation.mainField = nextRelation[mainFieldName];
|
||||
|
||||
return nextRelation;
|
||||
})
|
||||
.filter(Boolean),
|
||||
])
|
||||
.filter((page) => page.length > 0)
|
||||
.reverse(),
|
||||
return nextRelation;
|
||||
})
|
||||
.filter(Boolean),
|
||||
])
|
||||
?.filter((page) => page.length > 0)
|
||||
?.reverse() ?? [],
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user