-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema.ts
95 lines (88 loc) · 2.03 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
import "dotenv/config"
import { list } from "@keystone-6/core"
import { allowAll } from "@keystone-6/core/access"
import { cloudinaryImage } from "@keystone-6/cloudinary"
import {
text,
password,
timestamp,
select,
integer,
relationship,
} from "@keystone-6/core/fields"
import type { Lists } from "./.keystone/types"
export const lists: Lists = {
User: list({
access: allowAll,
fields: {
name: text({ validation: { isRequired: true } }),
email: text({
validation: { isRequired: true },
isIndexed: "unique",
}),
password: password({ validation: { isRequired: true } }),
createdAt: timestamp({
defaultValue: { kind: "now" },
}),
},
}),
Product: list({
access: allowAll,
fields: {
name: text({ validation: { isRequired: true } }),
description: text({
ui: {
displayMode: "textarea",
},
}),
photo: relationship({
ref: "ProductImage.product",
ui: {
displayMode: "cards",
cardFields: ["image", "altText"],
inlineCreate: { fields: ["image", "altText"] },
inlineEdit: { fields: ["image", "altText"] },
},
}),
status: select({
options: [
{ label: "Draft", value: "DRAFT" },
{ label: "Available", value: "AVAILABLE" },
{ label: "Unavailable", value: "UNAVAILABLE" },
],
defaultValue: "DRAFT",
ui: {
displayMode: "segmented-control",
createView: { fieldMode: "hidden" },
},
}),
price: integer(),
},
ui: {
listView: {
initialColumns: ["name", "description", "status", "price"],
},
},
}),
ProductImage: list({
access: allowAll,
fields: {
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,
},
label: "Source",
}),
altText: text(),
product: relationship({ ref: "Product.photo" }),
},
ui: {
listView: {
initialColumns: ["image", "altText", "product"],
},
},
}),
}