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 { getBySlugEndpointGalleryImage } from "./endpoints/getBySlugEndpointGalleryImage";
|
||||||
import { getBySlugEndpointScanPage } from "./endpoints/getBySlugEndpointScanPage";
|
import { getBySlugEndpointScanPage } from "./endpoints/getBySlugEndpointScanPage";
|
||||||
import { getBySlugEndpointScans } from "./endpoints/getBySlugEndpointScans";
|
import { getBySlugEndpointScans } from "./endpoints/getBySlugEndpointScans";
|
||||||
import { getSlugsEndpoint } from "./endpoints/getSlugsEndpoint";
|
|
||||||
|
|
||||||
const fields = {
|
const fields = {
|
||||||
status: "_status",
|
status: "_status",
|
||||||
|
@ -152,7 +151,6 @@ export const Collectibles = buildVersionedCollectionConfig({
|
||||||
getBySlugEndpointScanPage,
|
getBySlugEndpointScanPage,
|
||||||
getBySlugEndpointGallery,
|
getBySlugEndpointGallery,
|
||||||
getBySlugEndpointGalleryImage,
|
getBySlugEndpointGalleryImage,
|
||||||
getSlugsEndpoint,
|
|
||||||
],
|
],
|
||||||
fields: [
|
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 { buildCollectionConfig } from "../../utils/collectionConfig";
|
||||||
import { createEditor } from "../../utils/editor";
|
import { createEditor } from "../../utils/editor";
|
||||||
import { getBySlugEndpoint } from "./endpoints/getBySlugEndpoint";
|
import { getBySlugEndpoint } from "./endpoints/getBySlugEndpoint";
|
||||||
import { getSlugsEndpoint } from "./endpoints/getSlugsEndpoint";
|
|
||||||
|
|
||||||
const fields = {
|
const fields = {
|
||||||
slug: "slug",
|
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.",
|
"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}`,
|
preview: ({ slug }) => `${process.env.PAYLOAD_PUBLIC_FRONTEND_BASE_URL}/en/folders/${slug}`,
|
||||||
},
|
},
|
||||||
endpoints: [getBySlugEndpoint, getSlugsEndpoint],
|
endpoints: [getBySlugEndpoint],
|
||||||
fields: [
|
fields: [
|
||||||
rowField([
|
rowField([
|
||||||
slugField({ name: fields.slug }),
|
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 { createEditor } from "../../utils/editor";
|
||||||
import { buildVersionedCollectionConfig } from "../../utils/versionedCollectionConfig";
|
import { buildVersionedCollectionConfig } from "../../utils/versionedCollectionConfig";
|
||||||
import { getBySlugEndpoint } from "./endpoints/getBySlugEndpoint";
|
import { getBySlugEndpoint } from "./endpoints/getBySlugEndpoint";
|
||||||
import { getSlugsEndpoint } from "./endpoints/getSlugsEndpoint";
|
|
||||||
|
|
||||||
const fields = {
|
const fields = {
|
||||||
slug: "slug",
|
slug: "slug",
|
||||||
|
@ -70,7 +69,7 @@ export const Pages = buildVersionedCollectionConfig({
|
||||||
]),
|
]),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
endpoints: [getBySlugEndpoint, getSlugsEndpoint],
|
endpoints: [getBySlugEndpoint],
|
||||||
fields: [
|
fields: [
|
||||||
slugField({ name: fields.slug }),
|
slugField({ name: fields.slug }),
|
||||||
rowField([
|
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 { Icon } from "./components/Icon";
|
||||||
import { Logo } from "./components/Logo";
|
import { Logo } from "./components/Logo";
|
||||||
import { Collections } from "./constants";
|
import { Collections } from "./constants";
|
||||||
|
import { getAllIds } from "./endpoints/getAllIdsEndpoint";
|
||||||
import { getAllSDKUrlsEndpoint } from "./endpoints/getAllSDKUrlsEndpoint";
|
import { getAllSDKUrlsEndpoint } from "./endpoints/getAllSDKUrlsEndpoint";
|
||||||
import { createEditor } from "./utils/editor";
|
import { createEditor } from "./utils/editor";
|
||||||
|
|
||||||
|
@ -87,7 +88,7 @@ export default buildConfig({
|
||||||
typescript: {
|
typescript: {
|
||||||
outputFile: path.resolve(__dirname, "types/collections.ts"),
|
outputFile: path.resolve(__dirname, "types/collections.ts"),
|
||||||
},
|
},
|
||||||
endpoints: [getAllSDKUrlsEndpoint],
|
endpoints: [getAllSDKUrlsEndpoint, getAllIds],
|
||||||
graphQL: {
|
graphQL: {
|
||||||
disable: true,
|
disable: true,
|
||||||
},
|
},
|
||||||
|
|
28
src/sdk.ts
28
src/sdk.ts
|
@ -535,19 +535,28 @@ export type EndpointAllSDKUrls = {
|
||||||
urls: string[];
|
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
|
// SDK
|
||||||
|
|
||||||
export const getSDKEndpoint = {
|
export const getSDKEndpoint = {
|
||||||
getConfigEndpoint: () => `/globals/${Collections.WebsiteConfig}/config`,
|
getConfigEndpoint: () => `/globals/${Collections.WebsiteConfig}/config`,
|
||||||
getFolderEndpoint: (slug: string) => `/${Collections.Folders}/slug/${slug}`,
|
getFolderEndpoint: (slug: string) => `/${Collections.Folders}/slug/${slug}`,
|
||||||
getFolderSlugsEndpoint: () => `/${Collections.Folders}/slugs`,
|
|
||||||
getLanguagesEndpoint: () => `/${Collections.Languages}/all`,
|
getLanguagesEndpoint: () => `/${Collections.Languages}/all`,
|
||||||
getCurrenciesEndpoint: () => `/${Collections.Currencies}/all`,
|
getCurrenciesEndpoint: () => `/${Collections.Currencies}/all`,
|
||||||
getWordingsEndpoint: () => `/${Collections.Wordings}/all`,
|
getWordingsEndpoint: () => `/${Collections.Wordings}/all`,
|
||||||
getPageEndpoint: (slug: string) => `/${Collections.Pages}/slug/${slug}`,
|
getPageEndpoint: (slug: string) => `/${Collections.Pages}/slug/${slug}`,
|
||||||
getPageSlugsEndpoint: () => `/${Collections.Pages}/slugs`,
|
|
||||||
getCollectibleEndpoint: (slug: string) => `/${Collections.Collectibles}/slug/${slug}`,
|
getCollectibleEndpoint: (slug: string) => `/${Collections.Collectibles}/slug/${slug}`,
|
||||||
getCollectibleSlugsEndpoint: () => `/${Collections.Collectibles}/slugs`,
|
|
||||||
getCollectibleScansEndpoint: (slug: string) => `/${Collections.Collectibles}/slug/${slug}/scans`,
|
getCollectibleScansEndpoint: (slug: string) => `/${Collections.Collectibles}/slug/${slug}/scans`,
|
||||||
getCollectibleScanPageEndpoint: (slug: string, index: string) =>
|
getCollectibleScanPageEndpoint: (slug: string, index: string) =>
|
||||||
`/${Collections.Collectibles}/slug/${slug}/scans/${index}`,
|
`/${Collections.Collectibles}/slug/${slug}/scans/${index}`,
|
||||||
|
@ -563,6 +572,7 @@ export const getSDKEndpoint = {
|
||||||
getFileByIDEndpoint: (id: string) => `/${Collections.Files}/id/${id}`,
|
getFileByIDEndpoint: (id: string) => `/${Collections.Files}/id/${id}`,
|
||||||
getRecorderByIDEndpoint: (id: string) => `/${Collections.Recorders}/id/${id}`,
|
getRecorderByIDEndpoint: (id: string) => `/${Collections.Recorders}/id/${id}`,
|
||||||
getAllSDKUrlsEndpoint: () => `/all-sdk-urls`,
|
getAllSDKUrlsEndpoint: () => `/all-sdk-urls`,
|
||||||
|
getAllIds: () => `/all-ids`,
|
||||||
getLoginEndpoint: () => `/${Collections.Recorders}/login`,
|
getLoginEndpoint: () => `/${Collections.Recorders}/login`,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -652,9 +662,6 @@ export class PayloadSDK {
|
||||||
async getFolder(slug: string): Promise<PayloadSDKResponse<EndpointFolder>> {
|
async getFolder(slug: string): Promise<PayloadSDKResponse<EndpointFolder>> {
|
||||||
return await this.request(getSDKEndpoint.getFolderEndpoint(slug));
|
return await this.request(getSDKEndpoint.getFolderEndpoint(slug));
|
||||||
}
|
}
|
||||||
async getFolderSlugs(): Promise<PayloadSDKResponse<string[]>> {
|
|
||||||
return await this.request(getSDKEndpoint.getFolderSlugsEndpoint());
|
|
||||||
}
|
|
||||||
async getLanguages(): Promise<PayloadSDKResponse<Language[]>> {
|
async getLanguages(): Promise<PayloadSDKResponse<Language[]>> {
|
||||||
return await this.request(getSDKEndpoint.getLanguagesEndpoint());
|
return await this.request(getSDKEndpoint.getLanguagesEndpoint());
|
||||||
}
|
}
|
||||||
|
@ -667,15 +674,9 @@ export class PayloadSDK {
|
||||||
async getPage(slug: string): Promise<PayloadSDKResponse<EndpointPage>> {
|
async getPage(slug: string): Promise<PayloadSDKResponse<EndpointPage>> {
|
||||||
return await this.request(getSDKEndpoint.getPageEndpoint(slug));
|
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>> {
|
async getCollectible(slug: string): Promise<PayloadSDKResponse<EndpointCollectible>> {
|
||||||
return await this.request(getSDKEndpoint.getCollectibleEndpoint(slug));
|
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>> {
|
async getCollectibleScans(slug: string): Promise<PayloadSDKResponse<EndpointCollectibleScans>> {
|
||||||
return await this.request(getSDKEndpoint.getCollectibleScansEndpoint(slug));
|
return await this.request(getSDKEndpoint.getCollectibleScansEndpoint(slug));
|
||||||
}
|
}
|
||||||
|
@ -720,4 +721,7 @@ export class PayloadSDK {
|
||||||
async getAllSdkUrls(): Promise<PayloadSDKResponse<EndpointAllSDKUrls>> {
|
async getAllSdkUrls(): Promise<PayloadSDKResponse<EndpointAllSDKUrls>> {
|
||||||
return await this.request(getSDKEndpoint.getAllSDKUrlsEndpoint());
|
return await this.request(getSDKEndpoint.getAllSDKUrlsEndpoint());
|
||||||
}
|
}
|
||||||
|
async getAllIds(): Promise<PayloadSDKResponse<EndpointAllIds>> {
|
||||||
|
return await this.request(getSDKEndpoint.getAllIds());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue