Not include empty folders on the root level
This commit is contained in:
parent
ae0ccedd43
commit
8bd48f2434
|
@ -1,11 +1,10 @@
|
||||||
import payload from "payload";
|
import payload from "payload";
|
||||||
import { Collections } from "../../../constants";
|
import { Collections } from "../../../constants";
|
||||||
import { EndpointFolderPreview } from "../../../sdk";
|
import { Folder } from "../../../types/collections";
|
||||||
import { CollectionEndpoint } from "../../../types/payload";
|
import { CollectionEndpoint } from "../../../types/payload";
|
||||||
import { isPayloadType } from "../../../utils/asserts";
|
import { isPayloadType } from "../../../utils/asserts";
|
||||||
import { convertFolderToPreview } from "./getBySlugEndpoint";
|
import { convertFolderToPreview } from "./getBySlugEndpoint";
|
||||||
|
|
||||||
|
|
||||||
export const getRootFoldersEndpoint: CollectionEndpoint = {
|
export const getRootFoldersEndpoint: CollectionEndpoint = {
|
||||||
method: "get",
|
method: "get",
|
||||||
path: "/root",
|
path: "/root",
|
||||||
|
@ -40,8 +39,14 @@ export const getRootFoldersEndpoint: CollectionEndpoint = {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = folders.filter(isPayloadType).map<EndpointFolderPreview>(convertFolderToPreview);
|
const result = folders.filter(isPayloadType).filter(isEmptyFolder).map(convertFolderToPreview);
|
||||||
|
|
||||||
res.status(200).json(result);
|
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;
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue