forked from keystonejs/keystone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.ts
43 lines (42 loc) · 1.43 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
import { list } from '@keystone-6/core';
import { checkbox, password, relationship, text, timestamp } from '@keystone-6/core/fields';
import { select } from '@keystone-6/core/fields';
export const lists = {
Task: list({
fields: {
label: text({ validation: { isRequired: true } }),
priority: select({
type: '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(),
},
// Add access control so that only the assigned user can update a task
// We will write a test to verify that this is working correctly.
access: {
item: {
update: async ({ session, item, context }) => {
const task = await context.query.Task.findOne({
where: { id: item.id.toString() },
query: 'assignedTo { id }',
});
return !!(session?.itemId && session.itemId === task.assignedTo?.id);
},
},
},
}),
Person: list({
fields: {
name: text({ validation: { isRequired: true } }),
email: text({ isIndexed: 'unique', validation: { isRequired: true } }),
password: password({ validation: { isRequired: true } }),
tasks: relationship({ ref: 'Task.assignedTo', many: true }),
},
}),
};