-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.zmodel
107 lines (87 loc) · 2.31 KB
/
schema.zmodel
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
datasource db {
provider = 'postgresql'
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
}
plugin zod {
provider = "@core/zod"
}
// Auth stuff
enum UserType {
USER // Keep this as first so the preview shows this
ADMIN
SUPER_ADMIN
}
model User {
id String @id @default(cuid())
firstName String
lastName String
userType UserType @default(USER) @deny('update', auth().userType == USER)
basicAuth BasicAuth?
googleAuth GoogleAuth?
@@allow('read', auth().userType == ADMIN || this.userType == USER)
@@allow('all', auth() == this || auth().userType == SUPER_ADMIN)
@@allow('create', true)
}
abstract model IAuth {
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String @unique
email String @email @unique
@@allow('read', auth().userType == ADMIN)
@@allow('all', auth() == user || auth().userType == SUPER_ADMIN)
}
model BasicAuth extends IAuth {
password String @password @omit @length(8)
verified Boolean @default(false)
}
model GoogleAuth extends IAuth {
reference String @unique
}
// Forms stuff
model Form {
id String @id @default(cuid())
title String
description String?
live Boolean @default(false)
startAt DateTime
endAt DateTime
questions Question[]
@@allow('read', live)
@@allow('all', auth().userType == SUPER_ADMIN || auth().userType == ADMIN)
}
model Question {
id String @id @default(cuid())
form Form @relation(fields: [formId], references: [id], onDelete: Cascade)
formId String
label String
description String?
required Boolean
text TextQuestion?
number NumberQuestion?
boolean BooleanQuestion?
@@allow('read', form.live)
@@allow('all', auth().userType == SUPER_ADMIN || auth().userType == ADMIN)
}
abstract model IQuestionType {
question Question @relation(fields: [questionId], references: [id], onDelete: Cascade)
questionId String @unique
@@allow('read', question.form.live)
@@allow('all', auth().userType == SUPER_ADMIN || auth().userType == ADMIN)
}
model TextQuestion extends IQuestionType {
defaultValue String?
minLength Int?
maxLength Int?
regex String?
}
model NumberQuestion extends IQuestionType {
defaultValue Int?
minValue Int?
maxValue Int?
precision Int? @default(0)
}
model BooleanQuestion extends IQuestionType {
defaultValue Boolean?
}