-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.ts
More file actions
228 lines (213 loc) · 6.56 KB
/
schema.ts
File metadata and controls
228 lines (213 loc) · 6.56 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
// Welcome to your schema
// Schema driven development is Keystone's modus operandi
//
// This file is where we define the lists, fields and hooks for our data.
// If you want to learn more about how lists are configured, please read
// - https://keystonejs.com/docs/config/lists
import 'dotenv/config';
import { list } from '@keystone-6/core';
import { allowAll } from '@keystone-6/core/access';
import { createAuth } from '@keystone-6/auth';
// see https://keystonejs.com/docs/fields/overview for the full list of fields
// this is a few common fields for an example
import {
text,
relationship,
password,
timestamp,
select,
checkbox,
} from '@keystone-6/core/fields';
import { cloudinaryImage } from '@keystone-6/cloudinary';
// the document field is a more complicated field, so it has it's own package
import { document } from '@keystone-6/fields-document';
// if you want to make your own fields, see https://keystonejs.com/docs/guides/custom-fields
// when using Typescript, you can refine your types to a stricter subset by importing
// the generated types from '.keystone/types'
import type { Lists } from '.keystone/types';
const { withAuth } = createAuth({
listKey: 'User',
identityField: 'email',
secretField: 'password',
});
export const lists: Lists = {
User: list({
fields: {
// by adding isRequired, we enforce that every User should have a name
// if no name is provided, an error will be displayed
name: text({ validation: { isRequired: true } }),
email: text({
validation: { isRequired: true },
isIndexed: 'unique',
}),
isAdmin: checkbox(),
password: password({ validation: { isRequired: true } }),
createdAt: timestamp({
defaultValue: { kind: 'now' },
}),
},
access: {
operation: {
query: ({ session, context, listKey, operation }) => true,
create: ({ session, context, listKey, operation }) => true,
update: ({ session, context, listKey, operation }) => false,
delete: ({ session, context, listKey, operation }) => false,
},
filter: {
update: ({ session, context, listKey, operation }) => {
return { isAdmin: { equals: true } };
},
delete: ({ session, context, listKey, operation }) => {
return { isAdmin: { equals: true } };
},
},
}}),
Place: list({
fields: {
featured: checkbox(),
name: text({
validation: { isRequired: true },
isIndexed: 'unique',
}),
address: text({
validation: { isRequired: true },
}),
website: text(),
neighborhood: relationship({ ref: 'PlaceNeighborhood' }),
image: cloudinaryImage({
cloudinary: {
cloudName: process.env.CLOUDINARY_CLOUD_NAME,
apiKey: process.env.CLOUDINARY_API_KEY,
apiSecret: process.env.CLOUDINARY_API_SECRET,
folder: process.env.CLOUDINARY_API_FOLDER,
},
}),
simpleDescription: text(),
description: document({
formatting: true,
layouts: [
[1, 1],
[1, 1, 1],
[2, 1],
[1, 2],
[1, 2, 1],
],
links: true,
dividers: true,
}),
mainCategory: relationship({ ref: 'PlaceCategory' }),
subCategory: relationship({ ref: 'PlaceCategory' }),
time: relationship({ ref: 'PlaceTime', many: true, }),
details: relationship({ ref: 'PlaceDetail', many: true, }),
googleId: text(),
},
access: {
operation: {
query: ({ session, context, listKey, operation }) => true,
create: ({ session, context, listKey, operation }) => true,
update: ({ session, context, listKey, operation }) => true,
delete: ({ session, context, listKey, operation }) => true,
},
},
}),
PlaceTime: list({
fields: {
day: select({
type: 'string',
options: [
{ label: 'Sunday', value: 'Sunday' },
{ label: 'Monday', value: 'Monday' },
{ label: 'Tuesday', value: 'Tuesday' },
{ label: 'Wednesday', value: 'Wednesday' },
{ label: 'Thursday', value: 'Thursday' },
{ label: 'Friday', value: 'Friday' },
{ label: 'Saturday', value: 'Saturday' },
],
defaultValue: "Sunday",
ui: { displayMode: 'select' },
}),
time: text(),
},
ui: {
isHidden: true,
},
access: {
operation: {
query: ({ session, context, listKey, operation }) => true,
create: ({ session, context, listKey, operation }) => true,
update: ({ session, context, listKey, operation }) => true,
delete: ({ session, context, listKey, operation }) => false,
},
},
}),
PlaceNeighborhood: list({
fields: {
name: text({
isIndexed: 'unique',
}),
},
ui: {
isHidden: true,
},
access: {
operation: {
query: ({ session, context, listKey, operation }) => true,
create: ({ session, context, listKey, operation }) => true,
update: ({ session, context, listKey, operation }) => true,
delete: ({ session, context, listKey, operation }) => false,
},
},
}),
PlaceDetail: list({
fields: {
name: text({
isIndexed: 'unique',
}),
},
ui: {
isHidden: true,
},
access: {
operation: {
query: ({ session, context, listKey, operation }) => true,
create: ({ session, context, listKey, operation }) => true,
update: ({ session, context, listKey, operation }) => true,
delete: ({ session, context, listKey, operation }) => false,
},
},
}),
PlaceCategory: list({
fields: {
name: text({
isIndexed: 'unique',
}),
},
ui: {
isHidden: true,
},
access: {
operation: {
query: ({ session, context, listKey, operation }) => true,
create: ({ session, context, listKey, operation }) => true,
update: ({ session, context, listKey, operation }) => true,
delete: ({ session, context, listKey, operation }) => false,
},
},
}),
FavoritesList: list({
fields: {
url: text({
isIndexed: 'unique',
}),
places: relationship({ ref: 'Place', many: true, }),
},
access: {
operation: {
query: ({ session, context, listKey, operation }) => true,
create: ({ session, context, listKey, operation }) => true,
update: ({ session, context, listKey, operation }) => true,
delete: ({ session, context, listKey, operation }) => false,
},
},
}),
};