Not include empty folders on the root level

This commit is contained in:
DrMint 2024-03-10 18:22:02 +01:00
parent ae0ccedd43
commit 8bd48f2434
1 changed files with 8 additions and 3 deletions

View File

@ -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<EndpointFolderPreview>(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;
};