feat: add revlidation for loyalty page

This commit is contained in:
Christel Westerberg
2024-05-15 09:41:19 +02:00
parent a734ba848a
commit d651ea526c
8 changed files with 368 additions and 13 deletions

View File

@@ -53,3 +53,26 @@ export async function getContentTypeByPathName(
return PageTypeEnum.CurrentBlocksPage
}
}
/**
* Function to remove empty objects from a fetched content type.
* Used since Contentstack returns empty objects for all non
* queried in modular blocks.
*/
export function removeEmptyObjects<T>(obj: T): T {
const copy = obj as any
for (let key in copy) {
if (typeof copy[key] === "object" && copy[key] !== null) {
copy[key] = removeEmptyObjects(copy[key])
if (Object.keys(copy[key]).length === 0 && !Array.isArray(copy[key])) {
delete copy[key]
}
}
}
if (Array.isArray(copy)) {
return copy.filter((item) => item != null).map(removeEmptyObjects) as T
}
return copy as T
}