diff --git a/src/collections/Collectibles/Collectibles.ts b/src/collections/Collectibles/Collectibles.ts index b6a873c..d263969 100644 --- a/src/collections/Collectibles/Collectibles.ts +++ b/src/collections/Collectibles/Collectibles.ts @@ -28,6 +28,7 @@ import { getBySlugEndpointGallery } from "./endpoints/getBySlugEndpointGallery"; import { getBySlugEndpointGalleryImage } from "./endpoints/getBySlugEndpointGalleryImage"; import { getBySlugEndpointScanPage } from "./endpoints/getBySlugEndpointScanPage"; import { getBySlugEndpointScans } from "./endpoints/getBySlugEndpointScans"; +import { getSlugsEndpoint } from "./endpoints/getSlugsEndpoint"; const fields = { status: "_status", @@ -151,6 +152,7 @@ export const Collectibles = buildVersionedCollectionConfig({ getBySlugEndpointScanPage, getBySlugEndpointGallery, getBySlugEndpointGalleryImage, + getSlugsEndpoint, ], fields: [ { diff --git a/src/collections/Collectibles/endpoints/getSlugsEndpoint.ts b/src/collections/Collectibles/endpoints/getSlugsEndpoint.ts new file mode 100644 index 0000000..2b38102 --- /dev/null +++ b/src/collections/Collectibles/endpoints/getSlugsEndpoint.ts @@ -0,0 +1,33 @@ +import payload from "payload"; +import { Endpoint } from "payload/config"; +import { Collections } from "../../../constants"; + +export const getSlugsEndpoint: Endpoint = { + method: "get", + path: "/slugs", + handler: async (req, res) => { + if (!req.user) { + return res.status(403).send({ + errors: [ + { + message: "You are not allowed to perform this action.", + }, + ], + }); + } + + const collectibles = await payload.find({ + collection: Collections.Collectibles, + depth: 0, + pagination: false, + user: req.user, + where: { + _status: { + equals: "published", + }, + }, + }); + + return res.status(200).send(collectibles.docs.map(({ slug }) => slug)); + }, +}; diff --git a/src/collections/Folders/Folders.ts b/src/collections/Folders/Folders.ts index b4bcefe..7df28c9 100644 --- a/src/collections/Folders/Folders.ts +++ b/src/collections/Folders/Folders.ts @@ -9,6 +9,7 @@ import { isPayloadType } from "../../utils/asserts"; import { buildCollectionConfig } from "../../utils/collectionConfig"; import { createEditor } from "../../utils/editor"; import { getBySlugEndpoint } from "./endpoints/getBySlugEndpoint"; +import { getSlugsEndpoint } from "./endpoints/getSlugsEndpoint"; const fields = { slug: "slug", @@ -42,7 +43,7 @@ export const Folders = buildCollectionConfig({ "Folders provide a way to structure our content. A folder can contain subfolders and/or files.", preview: ({ slug }) => `${process.env.PAYLOAD_PUBLIC_FRONTEND_BASE_URL}/en/folders/${slug}`, }, - endpoints: [getBySlugEndpoint], + endpoints: [getBySlugEndpoint, getSlugsEndpoint], fields: [ rowField([ slugField({ name: fields.slug }), diff --git a/src/collections/Folders/endpoints/getSlugsEndpoint.ts b/src/collections/Folders/endpoints/getSlugsEndpoint.ts new file mode 100644 index 0000000..cbba44f --- /dev/null +++ b/src/collections/Folders/endpoints/getSlugsEndpoint.ts @@ -0,0 +1,28 @@ +import payload from "payload"; +import { Endpoint } from "payload/config"; +import { Collections } from "../../../constants"; + +export const getSlugsEndpoint: Endpoint = { + method: "get", + path: "/slugs", + handler: async (req, res) => { + if (!req.user) { + return res.status(403).send({ + errors: [ + { + message: "You are not allowed to perform this action.", + }, + ], + }); + } + + const folders = await payload.find({ + collection: Collections.Folders, + depth: 0, + pagination: false, + user: req.user, + }); + + return res.status(200).send(folders.docs.map(({ slug }) => slug)); + }, +}; diff --git a/src/collections/Pages/Pages.ts b/src/collections/Pages/Pages.ts index d091a41..b7be307 100644 --- a/src/collections/Pages/Pages.ts +++ b/src/collections/Pages/Pages.ts @@ -17,6 +17,7 @@ import { beforeDuplicateUnpublish } from "../../hooks/beforeDuplicateUnpublish"; import { createEditor } from "../../utils/editor"; import { buildVersionedCollectionConfig } from "../../utils/versionedCollectionConfig"; import { getBySlugEndpoint } from "./endpoints/getBySlugEndpoint"; +import { getSlugsEndpoint } from "./endpoints/getSlugsEndpoint"; const fields = { slug: "slug", @@ -69,7 +70,7 @@ export const Pages = buildVersionedCollectionConfig({ ]), }, }, - endpoints: [getBySlugEndpoint], + endpoints: [getBySlugEndpoint, getSlugsEndpoint], fields: [ slugField({ name: fields.slug }), rowField([ diff --git a/src/collections/Pages/endpoints/getSlugsEndpoint.ts b/src/collections/Pages/endpoints/getSlugsEndpoint.ts new file mode 100644 index 0000000..0b40b88 --- /dev/null +++ b/src/collections/Pages/endpoints/getSlugsEndpoint.ts @@ -0,0 +1,33 @@ +import payload from "payload"; +import { Endpoint } from "payload/config"; +import { Collections } from "../../../constants"; + +export const getSlugsEndpoint: Endpoint = { + method: "get", + path: "/slugs", + handler: async (req, res) => { + if (!req.user) { + return res.status(403).send({ + errors: [ + { + message: "You are not allowed to perform this action.", + }, + ], + }); + } + + const pages = await payload.find({ + collection: Collections.Pages, + depth: 0, + pagination: false, + user: req.user, + where: { + _status: { + equals: "published", + }, + }, + }); + + return res.status(200).send(pages.docs.map(({ slug }) => slug)); + }, +}; diff --git a/src/endpoints/getAllSDKUrlsEndpoint.ts b/src/endpoints/getAllSDKUrlsEndpoint.ts index bd4819f..74b4e83 100644 --- a/src/endpoints/getAllSDKUrlsEndpoint.ts +++ b/src/endpoints/getAllSDKUrlsEndpoint.ts @@ -111,9 +111,7 @@ export const getAllSDKUrlsEndpoint: Endpoint = { ...audios.docs.flatMap((doc) => getSDKUrlsForDocument(Collections.Audios, doc)), ...images.docs.flatMap((doc) => getSDKUrlsForDocument(Collections.Images, doc)), ...files.docs.flatMap((doc) => getSDKUrlsForDocument(Collections.Files, doc)), - ...collectibles.docs.flatMap((doc) => - getSDKUrlsForDocument(Collections.Collectibles, doc) - ), + ...collectibles.docs.flatMap((doc) => getSDKUrlsForDocument(Collections.Collectibles, doc)), ...recorders.docs.flatMap((doc) => getSDKUrlsForDocument(Collections.Recorders, doc)), ]);