-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.zmodel
257 lines (212 loc) · 7.01 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
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
import "base"
generator client {
provider = "prisma-client-js"
previewFeatures = ["fullTextSearch"]
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
plugin hooks {
provider = '@zenstackhq/tanstack-query'
target = 'react'
output = "./src/lib/hooks"
}
plugin openapi {
provider = "@zenstackhq/openapi"
output = "openapi.yaml"
prefix = "/api"
version = "1.0.0"
securitySchemes = {
bearer: {type: "http", scheme: "bearer", bearerFormat: "JWT"}
}
title = "Raffle System API"
description = "API for the Raffle System"
}
// User-related models
model User extends Base {
email String? @unique @email @lower @trim
emailVerified DateTime? @map("email_verified")
password String @password @length(min: 8, max: 32) @trim @omit
documentNumber String @unique @trim @map("document_number")
phoneNumber String @unique @trim @map("phone_number")
role UserRole @default(USER) @deny('update', auth().role == 'USER')
age Int @gt(0) @lte(120)
firstName String @trim @map("first_name")
lastName String? @trim @map("last_name")
imageUrl String @url @lower @trim @map("image_url")
termsAccepted Boolean @default(false) @map("terms_accepted")
marketingOptIn Boolean @default(false) @map("marketing_opt_in")
disabledAt DateTime? @map("disabled_at") @deny('update', auth().role == 'USER')
bannedAt DateTime? @map("banned_at")
lastLogin DateTime? @map("last_login")
accounts Account[]
auditLogs AuditLog[] @omit
rafflesCreated Raffle[]
rafflesWon WinnerOnRaffle[]
sessions Session[]
tickets Ticket[]
@@allow('create', true)
@@allow('read, update, delete', auth() == this)
@@map("users")
}
model Account extends Base {
userId String @map("user_id")
access_token String?
expires_at Int?
id_token String?
provider String
providerAccountId String @map("provider_account_id")
refresh_token String?
refresh_token_expires_in Int?
scope String?
session_state String?
token_type String?
type String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@unique([provider, providerAccountId])
@@map("accounts")
}
model Session extends Base {
userId String @map("user_id")
expires DateTime
ipAddress String? @map("ip_address")
sessionToken String @unique @map("session_token")
userAgent String? @map("user_agent")
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@map("sessions")
}
model VerificationToken extends Base {
identifier String
expires DateTime
token String @unique
@@unique([identifier, token])
@@map("verification_tokens")
}
model AuditLog extends Base {
userId String @map("user_id")
action String
details String?
ipAddress String? @map("ip_address")
user User @relation(fields: [userId], references: [id])
@@map("audit_logs")
}
// Raffle-related models
model Raffle extends Base {
creatorId String @default(auth().id) @map("creator_id")
name String @trim
description String @db.Text @trim
imageUrl String @url @lower @trim @map("image_url")
status RaffleStatus @default(PENDING)
currency CurrencyType @default(BRL)
ticketPrice Decimal @gt(0) @lte(999999) @map("ticket_price")
drawDate DateTime @map("draw_date")
drawEndDate DateTime? @map("draw_end_date")
drawType RaffleDrawType @default(INTERNAL) @map("draw_type")
maxTickets RaffleMaxTickets @default(VINTEECINCO) @map("max_tickets")
isCharity Boolean @default(false) @map("is_charity")
charityInfo String? @trim @map("charity_info")
termsConditions String @db.Text @trim @map("terms_conditions")
prizes Prize[]
tickets Ticket[]
winners WinnerOnRaffle[]
creator User @relation(fields: [creatorId], references: [id], onDelete: Cascade)
@@deny('update', future().creator != creator)
@@allow('all', creator == auth())
@@allow('read', status == 'PUBLISHED')
@@allow('create', auth() != null)
@@index([status, drawDate])
@@map("raffles")
}
model Prize extends Base {
raffleId String @map("raffle_id")
name String @trim
description String @db.Text @trim
imageUrl String? @url @lower @trim @map("image_url")
quantity Int @default(1)
value Decimal @gt(0) @lte(999999)
winners WinnerOnRaffle[]
raffle Raffle @relation(fields: [raffleId], references: [id])
@@allow('read', true)
@@allow('all', auth() == raffle.creator)
@@deny('update', future().raffle != raffle)
@@map("prizes")
}
model Ticket extends Base {
raffleId String @map("raffle_id")
ownerId String @map("owner_id")
status TicketStatus @default(PENDING)
number Int?
paymentId String? @unique @omit @map("payment_id")
owner User @relation(fields: [ownerId], references: [id])
raffle Raffle @relation(fields: [raffleId], references: [id])
@@allow('read', auth() == owner)
@@unique([raffleId, number])
@@index([status, raffleId])
@@map("tickets")
}
model WinnerOnRaffle extends Base {
prizeId String @map("prize_id")
raffleId String @map("raffle_id")
winnerId String @map("winner_id")
claimedAt DateTime? @map("claimed_at")
prize Prize @relation(fields: [prizeId], references: [id])
raffle Raffle @relation(fields: [raffleId], references: [id])
winner User @relation(fields: [winnerId], references: [id])
@@allow('read', true)
@@unique([raffleId, winnerId, prizeId])
@@map("winners_on_raffle")
}
// Enums
enum CurrencyType {
BRL
USD
}
enum UserRole {
USER
ADMIN
}
enum RaffleDrawType {
INTERNAL
LOTERIA_FEDERAL
}
enum RaffleMaxTickets {
VINTEECINCO
CINQUENTA
CEM
DUZENTOS
TREZENTOS
QUATROCENTOS
QUINHENTOS
SEISCENTOS
SETECENTOS
OITOCENTOS
NOVECENTOS
UM_K
DOIS_K
TRES_K
QUATRO_K
CINCO_K
SEIS_K
DEZ_K
VINTE_K
TRINTA_K
CINQUENTA_K
CEM_K
QUINHENTOS_K
UM_KK
UM_KK_E_QUINHENTOS_K
DEZ_KK
}
enum RaffleStatus {
PENDING
PUBLISHED
FINISHED
}
enum TicketStatus {
PENDING
VALID
CANCELED
REFUNDED
USED
}