diff --git a/src/collections/Collectibles/Collectibles.ts b/src/collections/Collectibles/Collectibles.ts index d263969..b6a873c 100644 --- a/src/collections/Collectibles/Collectibles.ts +++ b/src/collections/Collectibles/Collectibles.ts @@ -28,7 +28,6 @@ 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", @@ -152,7 +151,6 @@ 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 deleted file mode 100644 index 2b38102..0000000 --- a/src/collections/Collectibles/endpoints/getSlugsEndpoint.ts +++ /dev/null @@ -1,33 +0,0 @@ -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 7df28c9..b4bcefe 100644 --- a/src/collections/Folders/Folders.ts +++ b/src/collections/Folders/Folders.ts @@ -9,7 +9,6 @@ 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", @@ -43,7 +42,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, getSlugsEndpoint], + endpoints: [getBySlugEndpoint], fields: [ rowField([ slugField({ name: fields.slug }), diff --git a/src/collections/Folders/endpoints/getSlugsEndpoint.ts b/src/collections/Folders/endpoints/getSlugsEndpoint.ts deleted file mode 100644 index cbba44f..0000000 --- a/src/collections/Folders/endpoints/getSlugsEndpoint.ts +++ /dev/null @@ -1,28 +0,0 @@ -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 b7be307..d091a41 100644 --- a/src/collections/Pages/Pages.ts +++ b/src/collections/Pages/Pages.ts @@ -17,7 +17,6 @@ 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", @@ -70,7 +69,7 @@ export const Pages = buildVersionedCollectionConfig({ ]), }, }, - endpoints: [getBySlugEndpoint, getSlugsEndpoint], + endpoints: [getBySlugEndpoint], fields: [ slugField({ name: fields.slug }), rowField([ diff --git a/src/collections/Pages/endpoints/getSlugsEndpoint.ts b/src/collections/Pages/endpoints/getSlugsEndpoint.ts deleted file mode 100644 index 0b40b88..0000000 --- a/src/collections/Pages/endpoints/getSlugsEndpoint.ts +++ /dev/null @@ -1,33 +0,0 @@ -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/getAllIdsEndpoint.ts b/src/endpoints/getAllIdsEndpoint.ts new file mode 100644 index 0000000..e5451cf --- /dev/null +++ b/src/endpoints/getAllIdsEndpoint.ts @@ -0,0 +1,112 @@ +import payload from "payload"; +import { Endpoint } from "payload/config"; +import { Collections } from "../constants"; +import { EndpointAllIds } from "../sdk"; + +export const getAllIds: Endpoint = { + method: "get", + path: "/all-ids", + 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", + }, + }, + }); + + const pages = await payload.find({ + collection: Collections.Pages, + depth: 0, + pagination: false, + user: req.user, + where: { + _status: { + equals: "published", + }, + }, + }); + + const folders = await payload.find({ + collection: Collections.Folders, + depth: 0, + pagination: false, + user: req.user, + }); + + const videos = await payload.find({ + collection: Collections.Videos, + depth: 0, + pagination: false, + user: req.user, + }); + + const audios = await payload.find({ + collection: Collections.Audios, + depth: 0, + pagination: false, + user: req.user, + }); + + const images = await payload.find({ + collection: Collections.Images, + depth: 0, + pagination: false, + user: req.user, + }); + + const files = await payload.find({ + collection: Collections.Files, + depth: 0, + pagination: false, + user: req.user, + }); + + const recorders = await payload.find({ + collection: Collections.Recorders, + depth: 0, + pagination: false, + user: req.user, + }); + + const chronologyEvents = await payload.find({ + collection: Collections.ChronologyEvents, + depth: 0, + pagination: false, + user: req.user, + where: { + _status: { + equals: "published", + }, + }, + }); + + const result: EndpointAllIds = { + collectibles: { slugs: collectibles.docs.map(({ slug }) => slug) }, + pages: { slugs: pages.docs.map(({ slug }) => slug) }, + folders: { slugs: folders.docs.map(({ slug }) => slug) }, + videos: { ids: videos.docs.map(({ id }) => id) }, + audios: { ids: audios.docs.map(({ id }) => id) }, + images: { ids: images.docs.map(({ id }) => id) }, + files: { ids: files.docs.map(({ id }) => id) }, + recorders: { ids: recorders.docs.map(({ id }) => id) }, + chronologyEvents: { ids: chronologyEvents.docs.map(({ id }) => id) }, + }; + + return res.status(200).send(result); + }, +}; diff --git a/src/payload.config.ts b/src/payload.config.ts index 1b44d7b..c513b0c 100644 --- a/src/payload.config.ts +++ b/src/payload.config.ts @@ -28,6 +28,7 @@ import { Wordings } from "./collections/Wordings/Wordings"; import { Icon } from "./components/Icon"; import { Logo } from "./components/Logo"; import { Collections } from "./constants"; +import { getAllIds } from "./endpoints/getAllIdsEndpoint"; import { getAllSDKUrlsEndpoint } from "./endpoints/getAllSDKUrlsEndpoint"; import { createEditor } from "./utils/editor"; @@ -87,7 +88,7 @@ export default buildConfig({ typescript: { outputFile: path.resolve(__dirname, "types/collections.ts"), }, - endpoints: [getAllSDKUrlsEndpoint], + endpoints: [getAllSDKUrlsEndpoint, getAllIds], graphQL: { disable: true, }, diff --git a/src/sdk.ts b/src/sdk.ts index 9595164..4646110 100644 --- a/src/sdk.ts +++ b/src/sdk.ts @@ -535,19 +535,28 @@ export type EndpointAllSDKUrls = { urls: string[]; }; +export type EndpointAllIds = { + collectibles: { slugs: string[] }; + pages: { slugs: string[] }; + folders: { slugs: string[] }; + videos: { ids: string[] }; + audios: { ids: string[] }; + images: { ids: string[] }; + files: { ids: string[] }; + recorders: { ids: string[] }; + chronologyEvents: { ids: string[] }; +}; + // SDK export const getSDKEndpoint = { getConfigEndpoint: () => `/globals/${Collections.WebsiteConfig}/config`, getFolderEndpoint: (slug: string) => `/${Collections.Folders}/slug/${slug}`, - getFolderSlugsEndpoint: () => `/${Collections.Folders}/slugs`, getLanguagesEndpoint: () => `/${Collections.Languages}/all`, getCurrenciesEndpoint: () => `/${Collections.Currencies}/all`, getWordingsEndpoint: () => `/${Collections.Wordings}/all`, getPageEndpoint: (slug: string) => `/${Collections.Pages}/slug/${slug}`, - getPageSlugsEndpoint: () => `/${Collections.Pages}/slugs`, getCollectibleEndpoint: (slug: string) => `/${Collections.Collectibles}/slug/${slug}`, - getCollectibleSlugsEndpoint: () => `/${Collections.Collectibles}/slugs`, getCollectibleScansEndpoint: (slug: string) => `/${Collections.Collectibles}/slug/${slug}/scans`, getCollectibleScanPageEndpoint: (slug: string, index: string) => `/${Collections.Collectibles}/slug/${slug}/scans/${index}`, @@ -563,6 +572,7 @@ export const getSDKEndpoint = { getFileByIDEndpoint: (id: string) => `/${Collections.Files}/id/${id}`, getRecorderByIDEndpoint: (id: string) => `/${Collections.Recorders}/id/${id}`, getAllSDKUrlsEndpoint: () => `/all-sdk-urls`, + getAllIds: () => `/all-ids`, getLoginEndpoint: () => `/${Collections.Recorders}/login`, }; @@ -652,9 +662,6 @@ export class PayloadSDK { async getFolder(slug: string): Promise> { return await this.request(getSDKEndpoint.getFolderEndpoint(slug)); } - async getFolderSlugs(): Promise> { - return await this.request(getSDKEndpoint.getFolderSlugsEndpoint()); - } async getLanguages(): Promise> { return await this.request(getSDKEndpoint.getLanguagesEndpoint()); } @@ -667,15 +674,9 @@ export class PayloadSDK { async getPage(slug: string): Promise> { return await this.request(getSDKEndpoint.getPageEndpoint(slug)); } - async getPageSlugs(): Promise> { - return await this.request(getSDKEndpoint.getPageSlugsEndpoint()); - } async getCollectible(slug: string): Promise> { return await this.request(getSDKEndpoint.getCollectibleEndpoint(slug)); } - async getCollectibleSlugs(): Promise> { - return await this.request(getSDKEndpoint.getCollectibleSlugsEndpoint()); - } async getCollectibleScans(slug: string): Promise> { return await this.request(getSDKEndpoint.getCollectibleScansEndpoint(slug)); } @@ -720,4 +721,7 @@ export class PayloadSDK { async getAllSdkUrls(): Promise> { return await this.request(getSDKEndpoint.getAllSDKUrlsEndpoint()); } + async getAllIds(): Promise> { + return await this.request(getSDKEndpoint.getAllIds()); + } }