-
Notifications
You must be signed in to change notification settings - Fork 2
/
schema.ts
67 lines (65 loc) · 2.18 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
import { createSchema, list } from '@keystone-next/keystone/schema';
import { checkbox, password, relationship, select, text, timestamp } from '@keystone-next/fields';
export const lists = createSchema({
// Things to be done
Task: list({
access: { delete: ({ session }) => session?.data?.isAdmin },
fields: {
label: text({ isRequired: true }),
priority: select({
dataType: 'enum',
options: [
{ label: 'Low', value: 'low' },
{ label: 'Medium', value: 'medium' },
{ label: 'High', value: 'high' },
],
}),
isComplete: checkbox(),
assignedTo: relationship({ ref: 'Person.tasks', many: false }),
finishBy: timestamp(),
},
}),
// Can be assigned tasks
// People are also the operators of the system; can sign in to the Admin UI and manage data
Person: list({
access: { delete: ({ session }) => session?.data?.isAdmin },
ui: {
hideDelete: ({ session }) => !session?.data?.isAdmin,
listView: { initialColumns: ['name', 'email', 'isAdmin'] },
},
fields: {
name: text({ isRequired: true }),
email: text({ isRequired: true, isUnique: true }),
password: password({
access: {
update: ({ session, item }) =>
session && (session.data.isAdmin || session.itemId === item.id),
},
ui: {
itemView: {
fieldMode: ({ session, item }) =>
session && (session.data.isAdmin || session.itemId === item.id) ? 'edit' : 'hidden',
},
listView: {
fieldMode: ({ session }) => (session?.item?.isAdmin ? 'read' : 'hidden'),
},
},
}),
isAdmin: checkbox({
access: {
create: ({ session }) => session?.data.isAdmin,
update: ({ session }) => session?.data.isAdmin,
},
ui: {
createView: {
fieldMode: ({ session }) => (session?.data.isAdmin ? 'edit' : 'hidden'),
},
itemView: {
fieldMode: ({ session }) => (session?.data.isAdmin ? 'edit' : 'read'),
},
},
}),
tasks: relationship({ ref: 'Task.assignedTo', many: true }),
},
}),
});