Removed individual slug endpoint and added get all ids
This commit is contained in:
parent
54362bbef2
commit
1fe9dc3e3d
|
@ -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: [
|
||||
{
|
||||
|
|
|
@ -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));
|
||||
},
|
||||
};
|
|
@ -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 }),
|
||||
|
|
|
@ -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));
|
||||
},
|
||||
};
|
|
@ -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([
|
||||
|
|
|
@ -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));
|
||||
},
|
||||
};
|
|
@ -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);
|
||||
},
|
||||
};
|
|
@ -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,
|
||||
},
|
||||
|
|
28
src/sdk.ts
28
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<PayloadSDKResponse<EndpointFolder>> {
|
||||
return await this.request(getSDKEndpoint.getFolderEndpoint(slug));
|
||||
}
|
||||
async getFolderSlugs(): Promise<PayloadSDKResponse<string[]>> {
|
||||
return await this.request(getSDKEndpoint.getFolderSlugsEndpoint());
|
||||
}
|
||||
async getLanguages(): Promise<PayloadSDKResponse<Language[]>> {
|
||||
return await this.request(getSDKEndpoint.getLanguagesEndpoint());
|
||||
}
|
||||
|
@ -667,15 +674,9 @@ export class PayloadSDK {
|
|||
async getPage(slug: string): Promise<PayloadSDKResponse<EndpointPage>> {
|
||||
return await this.request(getSDKEndpoint.getPageEndpoint(slug));
|
||||
}
|
||||
async getPageSlugs(): Promise<PayloadSDKResponse<string[]>> {
|
||||
return await this.request(getSDKEndpoint.getPageSlugsEndpoint());
|
||||
}
|
||||
async getCollectible(slug: string): Promise<PayloadSDKResponse<EndpointCollectible>> {
|
||||
return await this.request(getSDKEndpoint.getCollectibleEndpoint(slug));
|
||||
}
|
||||
async getCollectibleSlugs(): Promise<PayloadSDKResponse<string[]>> {
|
||||
return await this.request(getSDKEndpoint.getCollectibleSlugsEndpoint());
|
||||
}
|
||||
async getCollectibleScans(slug: string): Promise<PayloadSDKResponse<EndpointCollectibleScans>> {
|
||||
return await this.request(getSDKEndpoint.getCollectibleScansEndpoint(slug));
|
||||
}
|
||||
|
@ -720,4 +721,7 @@ export class PayloadSDK {
|
|||
async getAllSdkUrls(): Promise<PayloadSDKResponse<EndpointAllSDKUrls>> {
|
||||
return await this.request(getSDKEndpoint.getAllSDKUrlsEndpoint());
|
||||
}
|
||||
async getAllIds(): Promise<PayloadSDKResponse<EndpointAllIds>> {
|
||||
return await this.request(getSDKEndpoint.getAllIds());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue