@danielcok17/prisma-db 1.2.2 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/prisma/app.prisma +248 -13
- package/prisma/generated/app/edge.js +140 -5
- package/prisma/generated/app/index-browser.js +137 -2
- package/prisma/generated/app/index.d.ts +16472 -4221
- package/prisma/generated/app/index.js +140 -5
- package/prisma/generated/app/package.json +1 -1
- package/prisma/generated/app/schema.prisma +236 -1
- package/prisma/generated/app/wasm.js +140 -5
- package/prisma/migrations/20251111182842_add_stripe_integration_and_organizations/migration.sql +246 -0
- package/prisma/migrations/20260102162551_add_billing_interval/migration.sql +8 -0
package/package.json
CHANGED
package/prisma/app.prisma
CHANGED
|
@@ -37,7 +37,6 @@ model User {
|
|
|
37
37
|
// Credentials authentication fields
|
|
38
38
|
password String? // Hashed password pre credentials login
|
|
39
39
|
createdAt DateTime @default(now())
|
|
40
|
-
messageCount Int @default(10)
|
|
41
40
|
agreedToTerms Boolean @default(false)
|
|
42
41
|
practiceArea String[]
|
|
43
42
|
lawFirm String?
|
|
@@ -53,16 +52,24 @@ model User {
|
|
|
53
52
|
// Nové polia pre tracking a žiadosť
|
|
54
53
|
referralSource String? // Odkiaľ sa o nás dozvedel (Google, Facebook, LinkedIn, etc.)
|
|
55
54
|
applicationText String? // Text žiadosti o prihlásenie
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
55
|
+
// ✨ STRIPE FIELDS (B2C - len pre individuálnych používateľov)
|
|
56
|
+
subscriptionTier SubscriptionTier @default(FREE) // Aktuálny subscription tier (cache)
|
|
57
|
+
messageCount Int @default(10) // ✅ OPRAVENÉ z 100 na 10
|
|
58
|
+
messageCountResetAt DateTime? // Kedy sa má resetovať message count
|
|
59
|
+
// Relations
|
|
60
|
+
approvalRequest UserApprovalRequest?
|
|
61
|
+
stripeCustomer StripeCustomer? // ✨ B2C Stripe customer
|
|
62
|
+
ownedOrganizations Organization[] @relation("OrganizationOwner")
|
|
63
|
+
organizationMembers OrganizationMember[]
|
|
64
|
+
accounts Account[]
|
|
65
|
+
answers Answer[]
|
|
66
|
+
conversations Conversation[]
|
|
67
|
+
feedbacks Feedback[]
|
|
68
|
+
pageViews PageView[]
|
|
69
|
+
sessions Session[]
|
|
70
|
+
workflowLogs WorkflowLog[]
|
|
71
|
+
verificationTokens VerificationToken[]
|
|
72
|
+
passwordResetTokens PasswordResetToken[]
|
|
66
73
|
}
|
|
67
74
|
|
|
68
75
|
// Nový model pre žiadosti o schválenie
|
|
@@ -81,6 +88,77 @@ model UserApprovalRequest {
|
|
|
81
88
|
@@index([reviewedAt])
|
|
82
89
|
}
|
|
83
90
|
|
|
91
|
+
// ============================================
|
|
92
|
+
// ORGANIZATION MODELS (B2B)
|
|
93
|
+
// ============================================
|
|
94
|
+
|
|
95
|
+
// Organization = Právna kancelária / Firma
|
|
96
|
+
model Organization {
|
|
97
|
+
id String @id @default(cuid())
|
|
98
|
+
name String // "Advokátska kancelária XYZ s.r.o."
|
|
99
|
+
|
|
100
|
+
// Billing & Legal Information
|
|
101
|
+
companyNumber String? // IČO (Identifikačné číslo organizácie)
|
|
102
|
+
vatNumber String? // IČ DPH (VAT Number)
|
|
103
|
+
taxNumber String? // DIČ (Daňové identifikačné číslo)
|
|
104
|
+
legalForm String? // "s.r.o.", "a.s.", "v.o.s.", "k.s.", "SZČO"
|
|
105
|
+
billingEmail String
|
|
106
|
+
|
|
107
|
+
// Address
|
|
108
|
+
street String?
|
|
109
|
+
city String?
|
|
110
|
+
postalCode String?
|
|
111
|
+
country String @default("SK")
|
|
112
|
+
|
|
113
|
+
// Subscription (B2B)
|
|
114
|
+
subscriptionTier SubscriptionTier @default(FREE) // Tier organizácie (cache)
|
|
115
|
+
messageCount Int @default(0) // Spoločný pool správ pre všetkých členov
|
|
116
|
+
messageLimit Int @default(100) // Limit správ podľa tieru
|
|
117
|
+
messageCountResetAt DateTime? // Kedy sa má resetovať pool
|
|
118
|
+
|
|
119
|
+
// Settings
|
|
120
|
+
isActive Boolean @default(true)
|
|
121
|
+
maxMembers Int @default(5) // Max počet členov podľa tieru
|
|
122
|
+
|
|
123
|
+
// Relations
|
|
124
|
+
owner User @relation("OrganizationOwner", fields: [ownerId], references: [id])
|
|
125
|
+
ownerId String
|
|
126
|
+
members OrganizationMember[]
|
|
127
|
+
stripeCustomer StripeCustomer?
|
|
128
|
+
|
|
129
|
+
createdAt DateTime @default(now())
|
|
130
|
+
updatedAt DateTime @updatedAt
|
|
131
|
+
|
|
132
|
+
@@index([ownerId])
|
|
133
|
+
@@index([vatNumber])
|
|
134
|
+
@@index([companyNumber])
|
|
135
|
+
@@index([subscriptionTier])
|
|
136
|
+
@@index([billingEmail])
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Many-to-Many: User ↔ Organization
|
|
140
|
+
model OrganizationMember {
|
|
141
|
+
id String @id @default(cuid())
|
|
142
|
+
organizationId String
|
|
143
|
+
userId String
|
|
144
|
+
role MemberRole @default(MEMBER)
|
|
145
|
+
joinedAt DateTime @default(now())
|
|
146
|
+
|
|
147
|
+
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
|
|
148
|
+
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
149
|
+
|
|
150
|
+
@@unique([organizationId, userId])
|
|
151
|
+
@@index([organizationId])
|
|
152
|
+
@@index([userId])
|
|
153
|
+
@@index([role])
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
enum MemberRole {
|
|
157
|
+
OWNER // Zakladateľ/vlastník, plný prístup k billing a settings
|
|
158
|
+
ADMIN // Administrátor, môže pridávať/odoberať členov
|
|
159
|
+
MEMBER // Bežný člen, len používa systém
|
|
160
|
+
}
|
|
161
|
+
|
|
84
162
|
// ZJEDNODUŠENÝ Conversation - len metadata, bez duplikátov
|
|
85
163
|
model Conversation {
|
|
86
164
|
id String @id @default(cuid())
|
|
@@ -138,8 +216,8 @@ model MessageFile {
|
|
|
138
216
|
id String @id @default(cuid())
|
|
139
217
|
answerId String
|
|
140
218
|
fileName String
|
|
141
|
-
fileType String
|
|
142
|
-
base64Data String
|
|
219
|
+
fileType String
|
|
220
|
+
base64Data String
|
|
143
221
|
uploadedAt DateTime @default(now())
|
|
144
222
|
answer Answer @relation(fields: [answerId], references: [id], onDelete: Cascade)
|
|
145
223
|
|
|
@@ -267,6 +345,137 @@ model Session {
|
|
|
267
345
|
@@index([startedAt])
|
|
268
346
|
}
|
|
269
347
|
|
|
348
|
+
// ============================================
|
|
349
|
+
// STRIPE INTEGRATION MODELS
|
|
350
|
+
// ============================================
|
|
351
|
+
|
|
352
|
+
// Stripe Customer - polymorphic relation (User OR Organization)
|
|
353
|
+
model StripeCustomer {
|
|
354
|
+
id String @id @default(cuid())
|
|
355
|
+
|
|
356
|
+
// ✅ Polymorphic relation - buď User (B2C) alebo Organization (B2B)
|
|
357
|
+
userId String? @unique // B2C: Individuálny používateľ
|
|
358
|
+
organizationId String? @unique // B2B: Organizácia
|
|
359
|
+
|
|
360
|
+
stripeCustomerId String @unique
|
|
361
|
+
email String
|
|
362
|
+
name String?
|
|
363
|
+
|
|
364
|
+
// Billing details (Stripe Address & Tax IDs)
|
|
365
|
+
billingAddress Json? // Stripe Address object
|
|
366
|
+
taxIds Json? // Stripe Tax IDs array (VAT, etc.)
|
|
367
|
+
|
|
368
|
+
createdAt DateTime @default(now())
|
|
369
|
+
updatedAt DateTime @updatedAt
|
|
370
|
+
|
|
371
|
+
// Relations
|
|
372
|
+
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
373
|
+
organization Organization? @relation(fields: [organizationId], references: [id], onDelete: Cascade)
|
|
374
|
+
subscriptions StripeSubscription[]
|
|
375
|
+
payments StripePayment[]
|
|
376
|
+
|
|
377
|
+
@@index([stripeCustomerId])
|
|
378
|
+
@@index([userId])
|
|
379
|
+
@@index([organizationId])
|
|
380
|
+
@@index([email])
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// Stripe Subscription - sledovanie predplatného (User alebo Organization)
|
|
384
|
+
model StripeSubscription {
|
|
385
|
+
id String @id @default(cuid())
|
|
386
|
+
|
|
387
|
+
// ✅ FIX: customerId = FK na StripeCustomer.id (nie stripeCustomerId!)
|
|
388
|
+
customerId String // FK na StripeCustomer.id
|
|
389
|
+
stripeCustomerId String // Stripe ID (pre logging/redundancia)
|
|
390
|
+
stripeSubscriptionId String @unique
|
|
391
|
+
stripePriceId String
|
|
392
|
+
stripeProductId String
|
|
393
|
+
|
|
394
|
+
status SubscriptionStatus
|
|
395
|
+
tier SubscriptionTier @default(FREE)
|
|
396
|
+
billingInterval BillingInterval @default(MONTHLY) // Monthly or Yearly billing
|
|
397
|
+
|
|
398
|
+
currentPeriodStart DateTime
|
|
399
|
+
currentPeriodEnd DateTime
|
|
400
|
+
cancelAtPeriodEnd Boolean @default(false)
|
|
401
|
+
canceledAt DateTime?
|
|
402
|
+
|
|
403
|
+
trialStart DateTime?
|
|
404
|
+
trialEnd DateTime?
|
|
405
|
+
|
|
406
|
+
// Additional fields
|
|
407
|
+
quantity Int @default(1) // Počet seats (pre LAW_FIRM/ENTERPRISE tier)
|
|
408
|
+
defaultPaymentMethodId String? // Stripe payment method ID
|
|
409
|
+
|
|
410
|
+
metadata Json? // Dodatočné Stripe metadata
|
|
411
|
+
createdAt DateTime @default(now())
|
|
412
|
+
updatedAt DateTime @updatedAt
|
|
413
|
+
|
|
414
|
+
// ✅ FIX: Relácia na customerId (interné ID), nie stripeCustomerId (Stripe ID)
|
|
415
|
+
customer StripeCustomer @relation(fields: [customerId], references: [id], onDelete: Cascade)
|
|
416
|
+
|
|
417
|
+
@@index([stripeSubscriptionId])
|
|
418
|
+
@@index([customerId])
|
|
419
|
+
@@index([stripeCustomerId])
|
|
420
|
+
@@index([status])
|
|
421
|
+
@@index([tier])
|
|
422
|
+
@@index([billingInterval])
|
|
423
|
+
@@index([currentPeriodEnd])
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
// Stripe Event - prevencia duplicitného spracovania webhookov (idempotencia)
|
|
427
|
+
model StripeEvent {
|
|
428
|
+
id String @id @default(cuid())
|
|
429
|
+
eventId String @unique // Stripe event ID
|
|
430
|
+
type String // Typ eventu (napr. 'checkout.session.completed')
|
|
431
|
+
data Json // Úplné event data pre debugging
|
|
432
|
+
processed Boolean @default(false)
|
|
433
|
+
processedAt DateTime?
|
|
434
|
+
error String? // Uloženie chýb pri spracovaní
|
|
435
|
+
createdAt DateTime @default(now())
|
|
436
|
+
|
|
437
|
+
@@index([eventId])
|
|
438
|
+
@@index([processed])
|
|
439
|
+
@@index([type])
|
|
440
|
+
@@index([createdAt])
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
// Stripe Payment - sledovanie jednotlivých platieb (voliteľné, pre detailnú analytiku)
|
|
444
|
+
model StripePayment {
|
|
445
|
+
id String @id @default(cuid())
|
|
446
|
+
|
|
447
|
+
// ✅ FIX: Pridaná relácia na StripeCustomer
|
|
448
|
+
customerId String
|
|
449
|
+
stripePaymentId String @unique
|
|
450
|
+
stripeCustomerId String // Redundantné, ale OK pre logging
|
|
451
|
+
|
|
452
|
+
amount Int // Suma v centoch
|
|
453
|
+
currency String @default("eur")
|
|
454
|
+
status String // succeeded, failed, pending
|
|
455
|
+
paymentMethod String? // card, sepa_debit, atď.
|
|
456
|
+
description String?
|
|
457
|
+
|
|
458
|
+
// Invoice info
|
|
459
|
+
invoiceId String? // Stripe Invoice ID
|
|
460
|
+
invoiceUrl String? // URL na faktúru
|
|
461
|
+
|
|
462
|
+
metadata Json?
|
|
463
|
+
createdAt DateTime @default(now())
|
|
464
|
+
|
|
465
|
+
// ✅ Relácia na StripeCustomer
|
|
466
|
+
customer StripeCustomer @relation(fields: [customerId], references: [id], onDelete: Cascade)
|
|
467
|
+
|
|
468
|
+
@@index([stripePaymentId])
|
|
469
|
+
@@index([customerId])
|
|
470
|
+
@@index([stripeCustomerId])
|
|
471
|
+
@@index([status])
|
|
472
|
+
@@index([createdAt])
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
// ============================================
|
|
476
|
+
// ENUMS
|
|
477
|
+
// ============================================
|
|
478
|
+
|
|
270
479
|
enum Role {
|
|
271
480
|
USER
|
|
272
481
|
ASSISTANT
|
|
@@ -293,6 +502,32 @@ enum ApprovalStatus {
|
|
|
293
502
|
REJECTED
|
|
294
503
|
}
|
|
295
504
|
|
|
505
|
+
// Stripe: Status predplatného
|
|
506
|
+
enum SubscriptionStatus {
|
|
507
|
+
ACTIVE // Predplatné je aktívne
|
|
508
|
+
CANCELED // Predplatné zrušené
|
|
509
|
+
INCOMPLETE // Iniciálna platba zlyhala
|
|
510
|
+
INCOMPLETE_EXPIRED // Neúplné predplatné expirované
|
|
511
|
+
PAST_DUE // Platba zlyhala, retry prebieha
|
|
512
|
+
TRIALING // V skúšobnom období
|
|
513
|
+
UNPAID // Platba zlyhala, žiadny retry
|
|
514
|
+
PAUSED // Predplatné pozastavené (Stripe feature)
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
// Stripe: Tier predplatného
|
|
518
|
+
enum SubscriptionTier {
|
|
519
|
+
FREE // ✅ Bezplatný tier (10 správ)
|
|
520
|
+
LAWYER // Právnik tier (1000 správ, €49/mes, 1 user)
|
|
521
|
+
LAW_FIRM // Právna kancelária tier (5000 správ, €149/mes, až 5 users)
|
|
522
|
+
ENTERPRISE // Enterprise tier (unlimited správ, unlimited users, custom price)
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
// Stripe: Billing interval
|
|
526
|
+
enum BillingInterval {
|
|
527
|
+
MONTHLY // Monthly billing
|
|
528
|
+
YEARLY // Yearly billing (17% discount)
|
|
529
|
+
}
|
|
530
|
+
|
|
296
531
|
// Nový model pre logovanie admin akcií
|
|
297
532
|
model AdminActionLog {
|
|
298
533
|
id String @id @default(cuid())
|