From 8bd48f2434379c541c3cf86b58140544ee1d19a5 Mon Sep 17 00:00:00 2001 From: DrMint <29893320+DrMint@users.noreply.github.com> Date: Sun, 10 Mar 2024 18:22:02 +0100 Subject: [PATCH] Not include empty folders on the root level --- src/collections/Folders/endpoints/rootEndpoint.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/collections/Folders/endpoints/rootEndpoint.ts b/src/collections/Folders/endpoints/rootEndpoint.ts index 3ffd030..609b425 100644 --- a/src/collections/Folders/endpoints/rootEndpoint.ts +++ b/src/collections/Folders/endpoints/rootEndpoint.ts @@ -1,11 +1,10 @@ import payload from "payload"; import { Collections } from "../../../constants"; -import { EndpointFolderPreview } from "../../../sdk"; +import { Folder } from "../../../types/collections"; import { CollectionEndpoint } from "../../../types/payload"; import { isPayloadType } from "../../../utils/asserts"; import { convertFolderToPreview } from "./getBySlugEndpoint"; - export const getRootFoldersEndpoint: CollectionEndpoint = { method: "get", path: "/root", @@ -40,8 +39,14 @@ export const getRootFoldersEndpoint: CollectionEndpoint = { return; } - const result = folders.filter(isPayloadType).map(convertFolderToPreview); + const result = folders.filter(isPayloadType).filter(isEmptyFolder).map(convertFolderToPreview); res.status(200).json(result); }, }; + +const isEmptyFolder = ({ sections, files }: Folder): boolean => { + if (sections && sections.length > 0) return true; + if (files && files.length > 0) return true; + return false; +};