@danielcok17/prisma-db 1.2.1 → 1.3.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.
@@ -1,5 +1,5 @@
1
1
  {
2
- "name": "prisma-client-f13be65f97f973045487dc73e8a7fc9e8dcf715dce0c8f7bdfacb5b3f22afcc0",
2
+ "name": "prisma-client-fcaeecba44be2bf319812cf77a98ee036c1af33eeb7c055c502a9bc323f577c1",
3
3
  "main": "index.js",
4
4
  "types": "index.d.ts",
5
5
  "browser": "default.js",
@@ -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(100)
41
40
  agreedToTerms Boolean @default(false)
42
41
  practiceArea String[]
43
42
  lawFirm String?
@@ -53,7 +52,15 @@ 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
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
56
60
  approvalRequest UserApprovalRequest?
61
+ stripeCustomer StripeCustomer? // ✨ B2C Stripe customer
62
+ ownedOrganizations Organization[] @relation("OrganizationOwner")
63
+ organizationMembers OrganizationMember[]
57
64
  accounts Account[]
58
65
  answers Answer[]
59
66
  conversations Conversation[]
@@ -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())
@@ -125,6 +203,7 @@ model Answer {
125
203
  references Reference[]
126
204
  metrics AnswerMetrics?
127
205
  WorkflowLog WorkflowLog[]
206
+ files MessageFile[]
128
207
 
129
208
  @@index([conversationId])
130
209
  @@index([messageId])
@@ -133,6 +212,20 @@ model Answer {
133
212
  @@index([createdAt])
134
213
  }
135
214
 
215
+ model MessageFile {
216
+ id String @id @default(cuid())
217
+ answerId String
218
+ fileName String
219
+ fileType String
220
+ base64Data String
221
+ uploadedAt DateTime @default(now())
222
+ answer Answer @relation(fields: [answerId], references: [id], onDelete: Cascade)
223
+
224
+ @@index([answerId])
225
+ @@index([fileType])
226
+ @@index([uploadedAt])
227
+ }
228
+
136
229
  // Nová tabuľka pre metriky odpovedí
137
230
  model AnswerMetrics {
138
231
  id String @id @default(cuid())
@@ -252,6 +345,135 @@ model Session {
252
345
  @@index([startedAt])
253
346
  }
254
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
+
397
+ currentPeriodStart DateTime
398
+ currentPeriodEnd DateTime
399
+ cancelAtPeriodEnd Boolean @default(false)
400
+ canceledAt DateTime?
401
+
402
+ trialStart DateTime?
403
+ trialEnd DateTime?
404
+
405
+ // Additional fields
406
+ quantity Int @default(1) // Počet seats (pre LAW_FIRM/ENTERPRISE tier)
407
+ defaultPaymentMethodId String? // Stripe payment method ID
408
+
409
+ metadata Json? // Dodatočné Stripe metadata
410
+ createdAt DateTime @default(now())
411
+ updatedAt DateTime @updatedAt
412
+
413
+ // ✅ FIX: Relácia na customerId (interné ID), nie stripeCustomerId (Stripe ID)
414
+ customer StripeCustomer @relation(fields: [customerId], references: [id], onDelete: Cascade)
415
+
416
+ @@index([stripeSubscriptionId])
417
+ @@index([customerId])
418
+ @@index([stripeCustomerId])
419
+ @@index([status])
420
+ @@index([tier])
421
+ @@index([currentPeriodEnd])
422
+ }
423
+
424
+ // Stripe Event - prevencia duplicitného spracovania webhookov (idempotencia)
425
+ model StripeEvent {
426
+ id String @id @default(cuid())
427
+ eventId String @unique // Stripe event ID
428
+ type String // Typ eventu (napr. 'checkout.session.completed')
429
+ data Json // Úplné event data pre debugging
430
+ processed Boolean @default(false)
431
+ processedAt DateTime?
432
+ error String? // Uloženie chýb pri spracovaní
433
+ createdAt DateTime @default(now())
434
+
435
+ @@index([eventId])
436
+ @@index([processed])
437
+ @@index([type])
438
+ @@index([createdAt])
439
+ }
440
+
441
+ // Stripe Payment - sledovanie jednotlivých platieb (voliteľné, pre detailnú analytiku)
442
+ model StripePayment {
443
+ id String @id @default(cuid())
444
+
445
+ // ✅ FIX: Pridaná relácia na StripeCustomer
446
+ customerId String
447
+ stripePaymentId String @unique
448
+ stripeCustomerId String // Redundantné, ale OK pre logging
449
+
450
+ amount Int // Suma v centoch
451
+ currency String @default("eur")
452
+ status String // succeeded, failed, pending
453
+ paymentMethod String? // card, sepa_debit, atď.
454
+ description String?
455
+
456
+ // Invoice info
457
+ invoiceId String? // Stripe Invoice ID
458
+ invoiceUrl String? // URL na faktúru
459
+
460
+ metadata Json?
461
+ createdAt DateTime @default(now())
462
+
463
+ // ✅ Relácia na StripeCustomer
464
+ customer StripeCustomer @relation(fields: [customerId], references: [id], onDelete: Cascade)
465
+
466
+ @@index([stripePaymentId])
467
+ @@index([customerId])
468
+ @@index([stripeCustomerId])
469
+ @@index([status])
470
+ @@index([createdAt])
471
+ }
472
+
473
+ // ============================================
474
+ // ENUMS
475
+ // ============================================
476
+
255
477
  enum Role {
256
478
  USER
257
479
  ASSISTANT
@@ -278,6 +500,26 @@ enum ApprovalStatus {
278
500
  REJECTED
279
501
  }
280
502
 
503
+ // Stripe: Status predplatného
504
+ enum SubscriptionStatus {
505
+ ACTIVE // Predplatné je aktívne
506
+ CANCELED // Predplatné zrušené
507
+ INCOMPLETE // Iniciálna platba zlyhala
508
+ INCOMPLETE_EXPIRED // Neúplné predplatné expirované
509
+ PAST_DUE // Platba zlyhala, retry prebieha
510
+ TRIALING // V skúšobnom období
511
+ UNPAID // Platba zlyhala, žiadny retry
512
+ PAUSED // Predplatné pozastavené (Stripe feature)
513
+ }
514
+
515
+ // Stripe: Tier predplatného
516
+ enum SubscriptionTier {
517
+ FREE // ✅ Bezplatný tier (10 správ)
518
+ LAWYER // Právnik tier (1000 správ, €49/mes, 1 user)
519
+ LAW_FIRM // Právna kancelária tier (5000 správ, €149/mes, až 5 users)
520
+ ENTERPRISE // Enterprise tier (unlimited správ, unlimited users, custom price)
521
+ }
522
+
281
523
  // Nový model pre logovanie admin akcií
282
524
  model AdminActionLog {
283
525
  id String @id @default(cuid())