-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathPets.ts
More file actions
118 lines (116 loc) · 2.95 KB
/
Pets.ts
File metadata and controls
118 lines (116 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import { createCustomEndpointDocumentation } from '@payload-oapi'
import type { CollectionConfig } from 'payload'
export const Categories: CollectionConfig = {
slug: 'petCategories',
access: {
read: () => true,
},
fields: [{ name: 'name', type: 'text' }],
}
export const Pets: CollectionConfig = {
slug: 'pets',
access: {
read: () => true,
},
fields: [
{ name: 'name', type: 'text', required: true },
{
name: 'category',
type: 'relationship',
relationTo: 'petCategories',
},
{
name: 'status',
type: 'radio',
required: true,
options: [
{ label: 'Available', value: 'available' },
{ label: 'Pending', value: 'pending' },
{ label: 'Sold', value: 'sold' },
],
},
{ name: 'lastUpdateAt', type: 'date', timezone: true },
],
endpoints: [
{
handler: async () => {
return Response.json({ message: 'Pet deleted successfully' })
},
method: 'delete',
path: '/status/:status',
custom: {
openapi: createCustomEndpointDocumentation({
summary: 'Delete pets by status',
description: 'Delete pets by status',
parameters: [
{
name: 'status',
in: 'path',
required: true,
schema: {
type: 'string',
enum: ['available', 'pending', 'sold'],
},
},
],
responses: {
200: {
type: 'object',
properties: {
message: {
type: 'string',
description: 'A message indicating the result of the operation',
},
},
},
},
}),
},
},
{
handler: async () => {
return Response.json({ message: 'Pet added successfully' })
},
method: 'post',
path: '/status/:status',
custom: {
openapi: createCustomEndpointDocumentation({
summary: 'Add a new pet by status',
description: 'Add a new pet by status',
parameters: [
{
name: 'status',
in: 'path',
required: true,
schema: {
type: 'string',
enum: ['available', 'pending', 'sold'],
},
},
],
requestBody: {
type: 'object',
properties: {
name: {
type: 'string',
description: 'Name of the pet',
},
},
required: ['name'],
},
responses: {
200: {
type: 'object',
properties: {
message: {
type: 'string',
description: 'A message indicating the result of the operation',
},
},
},
},
}),
},
},
],
}