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 { getBySlugEndpointScanPage } from "./endpoints/getBySlugEndpointScanPage"; | ||||
| import { getBySlugEndpointScans } from "./endpoints/getBySlugEndpointScans"; | ||||
| import { getSlugsEndpoint } from "./endpoints/getSlugsEndpoint"; | ||||
| 
 | ||||
| const fields = { | ||||
|   status: "_status", | ||||
| @ -151,6 +152,7 @@ export const Collectibles = buildVersionedCollectionConfig({ | ||||
|     getBySlugEndpointScanPage, | ||||
|     getBySlugEndpointGallery, | ||||
|     getBySlugEndpointGalleryImage, | ||||
|     getSlugsEndpoint, | ||||
|   ], | ||||
|   fields: [ | ||||
|     { | ||||
|  | ||||
							
								
								
									
										33
									
								
								src/collections/Collectibles/endpoints/getSlugsEndpoint.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								src/collections/Collectibles/endpoints/getSlugsEndpoint.ts
									
									
									
									
									
										Normal file
									
								
							| @ -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 { createEditor } from "../../utils/editor"; | ||||
| import { getBySlugEndpoint } from "./endpoints/getBySlugEndpoint"; | ||||
| import { getSlugsEndpoint } from "./endpoints/getSlugsEndpoint"; | ||||
| 
 | ||||
| const fields = { | ||||
|   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.", | ||||
|     preview: ({ slug }) => `${process.env.PAYLOAD_PUBLIC_FRONTEND_BASE_URL}/en/folders/${slug}`, | ||||
|   }, | ||||
|   endpoints: [getBySlugEndpoint], | ||||
|   endpoints: [getBySlugEndpoint, getSlugsEndpoint], | ||||
|   fields: [ | ||||
|     rowField([ | ||||
|       slugField({ name: fields.slug }), | ||||
|  | ||||
							
								
								
									
										28
									
								
								src/collections/Folders/endpoints/getSlugsEndpoint.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								src/collections/Folders/endpoints/getSlugsEndpoint.ts
									
									
									
									
									
										Normal file
									
								
							| @ -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 { buildVersionedCollectionConfig } from "../../utils/versionedCollectionConfig"; | ||||
| import { getBySlugEndpoint } from "./endpoints/getBySlugEndpoint"; | ||||
| import { getSlugsEndpoint } from "./endpoints/getSlugsEndpoint"; | ||||
| 
 | ||||
| const fields = { | ||||
|   slug: "slug", | ||||
| @ -69,7 +70,7 @@ export const Pages = buildVersionedCollectionConfig({ | ||||
|       ]), | ||||
|     }, | ||||
|   }, | ||||
|   endpoints: [getBySlugEndpoint], | ||||
|   endpoints: [getBySlugEndpoint, getSlugsEndpoint], | ||||
|   fields: [ | ||||
|     slugField({ name: fields.slug }), | ||||
|     rowField([ | ||||
|  | ||||
							
								
								
									
										33
									
								
								src/collections/Pages/endpoints/getSlugsEndpoint.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								src/collections/Pages/endpoints/getSlugsEndpoint.ts
									
									
									
									
									
										Normal file
									
								
							| @ -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)), | ||||
|       ...images.docs.flatMap((doc) => getSDKUrlsForDocument(Collections.Images, doc)), | ||||
|       ...files.docs.flatMap((doc) => getSDKUrlsForDocument(Collections.Files, doc)), | ||||
|       ...collectibles.docs.flatMap((doc) => | ||||
|         getSDKUrlsForDocument(Collections.Collectibles, doc) | ||||
|       ), | ||||
|       ...collectibles.docs.flatMap((doc) => getSDKUrlsForDocument(Collections.Collectibles, doc)), | ||||
|       ...recorders.docs.flatMap((doc) => getSDKUrlsForDocument(Collections.Recorders, doc)), | ||||
|     ]); | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 DrMint
						DrMint