Added get all paths endpoint
This commit is contained in:
parent
762c2e1819
commit
fb49341b57
|
@ -0,0 +1,81 @@
|
||||||
|
import payload from "payload";
|
||||||
|
import { Endpoint } from "payload/config";
|
||||||
|
import { Collections } from "../constants";
|
||||||
|
import { EndpointAllPaths } from "../sdk";
|
||||||
|
|
||||||
|
export const getAllPathsEndpoint: Endpoint = {
|
||||||
|
method: "get",
|
||||||
|
path: "/all-paths",
|
||||||
|
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,
|
||||||
|
});
|
||||||
|
|
||||||
|
const pages = await payload.find({
|
||||||
|
collection: Collections.Pages,
|
||||||
|
depth: 0,
|
||||||
|
pagination: false,
|
||||||
|
user: req.user,
|
||||||
|
});
|
||||||
|
|
||||||
|
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 recorders = await payload.find({
|
||||||
|
collection: Collections.Recorders,
|
||||||
|
depth: 0,
|
||||||
|
pagination: false,
|
||||||
|
user: req.user,
|
||||||
|
});
|
||||||
|
|
||||||
|
const result: EndpointAllPaths = {
|
||||||
|
collectibles: collectibles.docs.map(({ slug }) => slug),
|
||||||
|
pages: pages.docs.map(({ slug }) => slug),
|
||||||
|
folders: folders.docs.map(({ slug }) => slug),
|
||||||
|
videos: videos.docs.map(({ id }) => id),
|
||||||
|
audios: audios.docs.map(({ id }) => id),
|
||||||
|
images: images.docs.map(({ id }) => id),
|
||||||
|
recorders: recorders.docs.map(({ id }) => id),
|
||||||
|
};
|
||||||
|
|
||||||
|
return res.status(200).send(result);
|
||||||
|
},
|
||||||
|
};
|
|
@ -27,6 +27,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 { getAllPathsEndpoint } from "./endpoints/getAllPathsEndpoint";
|
||||||
import { createEditor } from "./utils/editor";
|
import { createEditor } from "./utils/editor";
|
||||||
|
|
||||||
const configuredFtpAdapter = sftpAdapter({
|
const configuredFtpAdapter = sftpAdapter({
|
||||||
|
@ -84,6 +85,7 @@ export default buildConfig({
|
||||||
typescript: {
|
typescript: {
|
||||||
outputFile: path.resolve(__dirname, "types/collections.ts"),
|
outputFile: path.resolve(__dirname, "types/collections.ts"),
|
||||||
},
|
},
|
||||||
|
endpoints: [getAllPathsEndpoint],
|
||||||
graphQL: {
|
graphQL: {
|
||||||
disable: true,
|
disable: true,
|
||||||
},
|
},
|
||||||
|
|
50
src/sdk.ts
50
src/sdk.ts
|
@ -516,6 +516,16 @@ export type PayloadImage = PayloadMedia & {
|
||||||
height: number;
|
height: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type EndpointAllPaths = {
|
||||||
|
collectibles: string[];
|
||||||
|
pages: string[];
|
||||||
|
folders: string[];
|
||||||
|
videos: string[];
|
||||||
|
audios: string[];
|
||||||
|
images: string[];
|
||||||
|
recorders: string[];
|
||||||
|
};
|
||||||
|
|
||||||
// SDK
|
// SDK
|
||||||
|
|
||||||
type GetPayloadSDKParams = {
|
type GetPayloadSDKParams = {
|
||||||
|
@ -542,7 +552,7 @@ export const getPayloadSDK = ({
|
||||||
responseCache,
|
responseCache,
|
||||||
}: GetPayloadSDKParams) => {
|
}: GetPayloadSDKParams) => {
|
||||||
const refreshToken = async () => {
|
const refreshToken = async () => {
|
||||||
const loginUrl = payloadApiUrl(Collections.Recorders, "login");
|
const loginUrl = `${apiURL}/${Collections.Recorders}/login`;
|
||||||
const loginResult = await fetch(loginUrl, {
|
const loginResult = await fetch(loginUrl, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
|
@ -562,9 +572,6 @@ export const getPayloadSDK = ({
|
||||||
return token;
|
return token;
|
||||||
};
|
};
|
||||||
|
|
||||||
const payloadApiUrl = (collection: Collections, endpoint?: string, isGlobal?: boolean): string =>
|
|
||||||
`${apiURL}/${isGlobal === undefined ? "" : "globals/"}${collection}${endpoint === undefined ? "" : `/${endpoint}`}`;
|
|
||||||
|
|
||||||
const request = async (url: string): Promise<any> => {
|
const request = async (url: string): Promise<any> => {
|
||||||
const cachedResponse = responseCache?.get(url);
|
const cachedResponse = responseCache?.get(url);
|
||||||
if (cachedResponse) {
|
if (cachedResponse) {
|
||||||
|
@ -589,45 +596,46 @@ export const getPayloadSDK = ({
|
||||||
|
|
||||||
return {
|
return {
|
||||||
getConfig: async (): Promise<EndpointWebsiteConfig> =>
|
getConfig: async (): Promise<EndpointWebsiteConfig> =>
|
||||||
await request(payloadApiUrl(Collections.WebsiteConfig, `config`, true)),
|
await request(`${apiURL}/globals/${Collections.WebsiteConfig}/config`),
|
||||||
getFolder: async (slug: string): Promise<EndpointFolder> =>
|
getFolder: async (slug: string): Promise<EndpointFolder> =>
|
||||||
await request(payloadApiUrl(Collections.Folders, `slug/${slug}`)),
|
await request(`${apiURL}/${Collections.Folders}/slug/${slug}`),
|
||||||
getLanguages: async (): Promise<Language[]> =>
|
getLanguages: async (): Promise<Language[]> =>
|
||||||
await request(payloadApiUrl(Collections.Languages, `all`)),
|
await request(`${apiURL}/${Collections.Languages}/all`),
|
||||||
getCurrencies: async (): Promise<Currency[]> =>
|
getCurrencies: async (): Promise<Currency[]> =>
|
||||||
await request(payloadApiUrl(Collections.Currencies, `all`)),
|
await request(`${apiURL}/${Collections.Currencies}/all`),
|
||||||
getWordings: async (): Promise<EndpointWording[]> =>
|
getWordings: async (): Promise<EndpointWording[]> =>
|
||||||
await request(payloadApiUrl(Collections.Wordings, `all`)),
|
await request(`${apiURL}/${Collections.Wordings}/all`),
|
||||||
getPage: async (slug: string): Promise<EndpointPage> =>
|
getPage: async (slug: string): Promise<EndpointPage> =>
|
||||||
await request(payloadApiUrl(Collections.Pages, `slug/${slug}`)),
|
await request(`${apiURL}/${Collections.Pages}/slug/${slug}`),
|
||||||
getCollectible: async (slug: string): Promise<EndpointCollectible> =>
|
getCollectible: async (slug: string): Promise<EndpointCollectible> =>
|
||||||
await request(payloadApiUrl(Collections.Collectibles, `slug/${slug}`)),
|
await request(`${apiURL}/${Collections.Collectibles}/slug/${slug}`),
|
||||||
getCollectibleScans: async (slug: string): Promise<EndpointCollectibleScans> =>
|
getCollectibleScans: async (slug: string): Promise<EndpointCollectibleScans> =>
|
||||||
await request(payloadApiUrl(Collections.Collectibles, `slug/${slug}/scans`)),
|
await request(`${apiURL}/${Collections.Collectibles}/slug/${slug}/scans`),
|
||||||
getCollectibleScanPage: async (
|
getCollectibleScanPage: async (
|
||||||
slug: string,
|
slug: string,
|
||||||
index: string
|
index: string
|
||||||
): Promise<EndpointCollectibleScanPage> =>
|
): Promise<EndpointCollectibleScanPage> =>
|
||||||
await request(payloadApiUrl(Collections.Collectibles, `slug/${slug}/scans/${index}`)),
|
await request(`${apiURL}/${Collections.Collectibles}/slug/${slug}/scans/${index}`),
|
||||||
getCollectibleGallery: async (slug: string): Promise<EndpointCollectibleGallery> =>
|
getCollectibleGallery: async (slug: string): Promise<EndpointCollectibleGallery> =>
|
||||||
await request(payloadApiUrl(Collections.Collectibles, `slug/${slug}/gallery`)),
|
await request(`${apiURL}/${Collections.Collectibles}/slug/${slug}/gallery`),
|
||||||
getCollectibleGalleryImage: async (
|
getCollectibleGalleryImage: async (
|
||||||
slug: string,
|
slug: string,
|
||||||
index: string
|
index: string
|
||||||
): Promise<EndpointCollectibleGalleryImage> =>
|
): Promise<EndpointCollectibleGalleryImage> =>
|
||||||
await request(payloadApiUrl(Collections.Collectibles, `slug/${slug}/gallery/${index}`)),
|
await request(`${apiURL}/${Collections.Collectibles}/slug/${slug}/gallery/${index}`),
|
||||||
getChronologyEvents: async (): Promise<EndpointChronologyEvent[]> =>
|
getChronologyEvents: async (): Promise<EndpointChronologyEvent[]> =>
|
||||||
await request(payloadApiUrl(Collections.ChronologyEvents, `all`)),
|
await request(`${apiURL}/${Collections.ChronologyEvents}/all`),
|
||||||
getChronologyEventByID: async (id: string): Promise<EndpointChronologyEvent> =>
|
getChronologyEventByID: async (id: string): Promise<EndpointChronologyEvent> =>
|
||||||
await request(payloadApiUrl(Collections.ChronologyEvents, `id/${id}`)),
|
await request(`${apiURL}/${Collections.ChronologyEvents}/id/${id}`),
|
||||||
getImageByID: async (id: string): Promise<EndpointImage> =>
|
getImageByID: async (id: string): Promise<EndpointImage> =>
|
||||||
await request(payloadApiUrl(Collections.Images, `id/${id}`)),
|
await request(`${apiURL}/${Collections.Images}/id/${id}`),
|
||||||
getAudioByID: async (id: string): Promise<EndpointAudio> =>
|
getAudioByID: async (id: string): Promise<EndpointAudio> =>
|
||||||
await request(payloadApiUrl(Collections.Audios, `id/${id}`)),
|
await request(`${apiURL}/${Collections.Audios}/id/${id}`),
|
||||||
getVideoByID: async (id: string): Promise<EndpointVideo> =>
|
getVideoByID: async (id: string): Promise<EndpointVideo> =>
|
||||||
await request(payloadApiUrl(Collections.Videos, `id/${id}`)),
|
await request(`${apiURL}/${Collections.Videos}/id/${id}`),
|
||||||
getRecorderByID: async (id: string): Promise<EndpointRecorder> =>
|
getRecorderByID: async (id: string): Promise<EndpointRecorder> =>
|
||||||
await request(payloadApiUrl(Collections.Recorders, `id/${id}`)),
|
await request(`${apiURL}/${Collections.Recorders}/id/${id}`),
|
||||||
|
getAllPaths: async (): Promise<EndpointAllPaths> => await request(`${apiURL}/all-paths`),
|
||||||
request: async (url: string): Promise<any> => await request(url),
|
request: async (url: string): Promise<any> => await request(url),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue