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; +};