-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.ts
295 lines (293 loc) · 9.5 KB
/
schema.ts
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
import { list, graphql } from '@keystone-6/core';
import { select, relationship, text, timestamp, checkbox, virtual } from '@keystone-6/core/fields';
import { access } from './firebaseAuth';
import * as Keystone from '.keystone/types';
import _ from 'lodash';
import { lists as reservationLists } from './schemaPlugins/reservation';
import { atTracking, byTracking } from './list-plugins/src'
import { DateTime } from 'luxon';
const withAtTracking = atTracking({});
const withByTracking = byTracking({
ref: 'User'
});
const User: Keystone.Lists.User = list(withByTracking(withAtTracking({
fields: {
name: text({ validation: { isRequired: true } }),
email: text({ isIndexed: 'unique', validation: { isRequired: true } }),
posts: relationship({ ref: 'Post.author', many: true }),
// bio: document({
// // We want to constrain the formatting in Author bios to a limited set of options.
// // We will allow bold, italics, unordered lists, and links.
// // See the document field guide for a complete list of configurable options
// formatting: {
// inlineMarks: {
// bold: true,
// italic: true,
// },
// listTypes: { unordered: true },
// },
// links: true,
// }),
phoneNumbers: relationship({
ref: 'PhoneNumber.user',
many: true,
ui: {
// TODO: Work out how to use custom views to customise the card + edit / create forms
// views: './admin/fieldViews/user/phoneNumber',
displayMode: 'cards',
cardFields: ['type', 'value'],
inlineEdit: { fields: ['type', 'value'] },
inlineCreate: { fields: ['type', 'value'] },
linkToItem: true,
// removeMode: 'delete',
},
}),
roles: relationship({
ref: 'Role.users',
many: true,
access: {
create: access.isAdmin,
update: access.isAdmin,
},
ui: {
createView: {
fieldMode: async (args) => (await access.isAdmin(args) ? 'edit' : 'hidden'),
},
itemView: {
fieldMode: async (args) => (await access.isAdmin(args) ? 'edit' : 'read'),
},
},
}),
firebaseId: text({
isIndexed: 'unique',
access: {
create: access.isAdmin,
update: access.isAdmin,
},
ui: {
createView: {
fieldMode: async (args) => (await access.isAdmin(args) ? 'edit' : 'hidden'),
},
itemView: {
fieldMode: async (args) => (await access.isAdmin(args) ? 'edit' : 'read'),
},
},
}),
reservations: relationship({ ref: 'Reservation.user', many: true }),
lastUpdated: timestamp({
db: { updatedAt: true },
ui: {
createView: {
fieldMode: 'hidden',
},
itemView: {
fieldMode: 'read',
},
}
}),
},
access: {
operation: {
create: access.isAdmin,
update: access.isAdmin,
delete: access.isAdmin,
},
filter: {
query: access.isOwnerFilter
}
}
})));
export const lists = {
Post: list({
fields: {
title: text({ validation: { isRequired: true } }),
slug: text({ isIndexed: 'unique', validation: { isRequired: true } }),
status: select({
type: 'enum',
options: [
{ label: 'Draft', value: 'draft' },
{ label: 'Published', value: 'published' },
],
}),
// content: document({
// // We want to have support a fully featured document editor for our
// // authors, so we're enabling all of the formatting abilities and
// // providing 1, 2 or 3 column layouts.
// formatting: true,
// dividers: true,
// links: true,
// layouts: [
// [1, 1],
// [1, 1, 1],
// ],
// // We want to support twitter-style mentions in blogs, so we add an
// // inline relationship which references the `Author` list.
// relationships: {
// mention: {
// kind: 'inline',
// listKey: 'User',
// label: 'Mention', // This will display in the Admin UI toolbar behind the `+` icon
// selection: 'id name', // These fields will be available to the renderer
// },
// },
// }),
publishDate: timestamp(),
author: relationship({ ref: 'User.posts', many: false }),
},
access: {
item: {
update: (args) => {
return access.isAdmin(args) || access.isOwner(args);
},
delete: (args) => {
return access.isAdmin(args) || access.isOwner(args);
},
}
}
}),
User,
PhoneNumber: list({
ui: {
isHidden: true,
},
fields: {
label: virtual({
field: graphql.field({
type: graphql.String,
resolve(item: any) {
return `${item.type} - ${item.value}`;
},
}),
ui: {
listView: {
fieldMode: 'hidden',
},
itemView: {
fieldMode: 'hidden',
},
},
}),
user: relationship({ ref: 'User.phoneNumbers' }),
type: select({
options: [
{ label: 'Home', value: 'home' },
{ label: 'Work', value: 'work' },
{ label: 'Mobile', value: 'mobile' },
],
ui: {
displayMode: 'segmented-control',
},
}),
value: text({}),
},
}),
Role: list({
ui: {
labelField: 'value',
isHidden: async (args) => {
return !await access.isAdmin(args);
},
// parentRelationship: 'user',
},
fields: {
value: text({}),
users: relationship({ ref: 'User.roles', many: true }),
},
access: {
operation: {
create: access.isAdmin,
update: access.isAdmin,
delete: access.isAdmin,
},
}
}),
Address: list({
ui: {
labelField: 'address',
isHidden: async (args) => {
return !await access.isEditor(args);
},
// parentRelationship: 'user',
},
fields: {
address: text({}),
city: text({}),
state: select({
type: 'enum',
options: [
{ label: 'Alabama', value: 'AL' },
{ label: 'Alaska', value: 'AK' },
{ label: 'American Samoa', value: 'AS' },
{ label: 'Arizona', value: 'AZ' },
{ label: 'Arkansas', value: 'AR' },
{ label: 'California', value: 'CA' },
{ label: 'Colorado', value: 'CO' },
{ label: 'Connecticut', value: 'CT' },
{ label: 'Delaware', value: 'DE' },
{ label: 'District of Columbia', value: 'DC' },
{ label: 'Federated States of Micronesia', value: 'FM' },
{ label: 'Florida', value: 'FL' },
{ label: 'Georgia', value: 'GA' },
{ label: 'Guam', value: 'GU' },
{ label: 'Hawaii', value: 'HI' },
{ label: 'Idaho', value: 'ID' },
{ label: 'Illinois', value: 'IL' },
{ label: 'Indiana', value: 'IN' },
{ label: 'Iowa', value: 'IA' },
{ label: 'Kansas', value: 'KS' },
{ label: 'Kentucky', value: 'KY' },
{ label: 'Louisiana', value: 'LA' },
{ label: 'Maine', value: 'ME' },
{ label: 'Marshall Islands', value: 'MH' },
{ label: 'Maryland', value: 'MD' },
{ label: 'Massachusetts', value: 'MA' },
{ label: 'Michigan', value: 'MI' },
{ label: 'Minnesota', value: 'MN' },
{ label: 'Mississippi', value: 'MS' },
{ label: 'Missouri', value: 'MO' },
{ label: 'Montana', value: 'MT' },
{ label: 'Nebraska', value: 'NE' },
{ label: 'Nevada', value: 'NV' },
{ label: 'New Hampshire', value: 'NH' },
{ label: 'New Jersey', value: 'NJ' },
{ label: 'New Mexico', value: 'NM' },
{ label: 'New York', value: 'NY' },
{ label: 'North Carolina', value: 'NC' },
{ label: 'North Dakota', value: 'ND' },
{ label: 'Northern Mariana Islands', value: 'MP' },
{ label: 'Ohio', value: 'OH' },
{ label: 'Oklahoma', value: 'OK' },
{ label: 'Oregon', value: 'OR' },
{ label: 'Palau', value: 'PW' },
{ label: 'Pennsylvania', value: 'PA' },
{ label: 'Puerto Rico', value: 'PR' },
{ label: 'Rhode Island', value: 'RI' },
{ label: 'South Carolina', value: 'SC' },
{ label: 'South Dakota', value: 'SD' },
{ label: 'Tennessee', value: 'TN' },
{ label: 'Texas', value: 'TX' },
{ label: 'Utah', value: 'UT' },
{ label: 'Vermont', value: 'VT' },
{ label: 'Virgin Islands', value: 'VI' },
{ label: 'Virginia', value: 'VA' },
{ label: 'Washington', value: 'WA' },
{ label: 'West Virginia', value: 'WV' },
{ label: 'Wisconsin', value: 'WI' },
{ label: 'Wyoming', value: 'WY' },
{ label: 'Armed Forces - AA', value: 'AA' },
{ label: 'Armed Forces - AE', value: 'AE' },
{ label: 'Armed Forces - AP', value: 'AP' },
],
}),
zipCode: text({}),
},
access: {
operation: {
create: access.isEditor,
update: access.isEditor,
delete: access.isEditor,
},
}
}),
...reservationLists
};