Added get slugs endpoints
This commit is contained in:
parent
bd1cd47dc1
commit
aa974882ec
|
@ -28,6 +28,7 @@ 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",
|
||||||
|
@ -151,6 +152,7 @@ export const Collectibles = buildVersionedCollectionConfig({
|
||||||
getBySlugEndpointScanPage,
|
getBySlugEndpointScanPage,
|
||||||
getBySlugEndpointGallery,
|
getBySlugEndpointGallery,
|
||||||
getBySlugEndpointGalleryImage,
|
getBySlugEndpointGalleryImage,
|
||||||
|
getSlugsEndpoint,
|
||||||
],
|
],
|
||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
||||||
|
|
|
@ -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));
|
||||||
|
},
|
||||||
|
};
|
|
@ -9,6 +9,7 @@ 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",
|
||||||
|
@ -42,7 +43,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],
|
endpoints: [getBySlugEndpoint, getSlugsEndpoint],
|
||||||
fields: [
|
fields: [
|
||||||
rowField([
|
rowField([
|
||||||
slugField({ name: fields.slug }),
|
slugField({ name: fields.slug }),
|
||||||
|
|
|
@ -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));
|
||||||
|
},
|
||||||
|
};
|
|
@ -17,6 +17,7 @@ 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",
|
||||||
|
@ -69,7 +70,7 @@ export const Pages = buildVersionedCollectionConfig({
|
||||||
]),
|
]),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
endpoints: [getBySlugEndpoint],
|
endpoints: [getBySlugEndpoint, getSlugsEndpoint],
|
||||||
fields: [
|
fields: [
|
||||||
slugField({ name: fields.slug }),
|
slugField({ name: fields.slug }),
|
||||||
rowField([
|
rowField([
|
||||||
|
|
|
@ -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));
|
||||||
|
},
|
||||||
|
};
|
|
@ -111,9 +111,7 @@ export const getAllSDKUrlsEndpoint: Endpoint = {
|
||||||
...audios.docs.flatMap((doc) => getSDKUrlsForDocument(Collections.Audios, doc)),
|
...audios.docs.flatMap((doc) => getSDKUrlsForDocument(Collections.Audios, doc)),
|
||||||
...images.docs.flatMap((doc) => getSDKUrlsForDocument(Collections.Images, doc)),
|
...images.docs.flatMap((doc) => getSDKUrlsForDocument(Collections.Images, doc)),
|
||||||
...files.docs.flatMap((doc) => getSDKUrlsForDocument(Collections.Files, doc)),
|
...files.docs.flatMap((doc) => getSDKUrlsForDocument(Collections.Files, doc)),
|
||||||
...collectibles.docs.flatMap((doc) =>
|
...collectibles.docs.flatMap((doc) => getSDKUrlsForDocument(Collections.Collectibles, doc)),
|
||||||
getSDKUrlsForDocument(Collections.Collectibles, doc)
|
|
||||||
),
|
|
||||||
...recorders.docs.flatMap((doc) => getSDKUrlsForDocument(Collections.Recorders, doc)),
|
...recorders.docs.flatMap((doc) => getSDKUrlsForDocument(Collections.Recorders, doc)),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue