@valentine-efagene/qshelter-common 2.0.22 → 2.0.25

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.
@@ -118,10 +118,16 @@ model Tenant {
118
118
  name String
119
119
  subdomain String @unique
120
120
  isActive Boolean @default(true)
121
- users User[]
122
121
  createdAt DateTime @default(now())
123
122
  updatedAt DateTime @updatedAt
124
123
 
124
+ // Back-relations for multitenancy
125
+ users User[]
126
+ properties Property[]
127
+ paymentPlans PaymentPlan[]
128
+ paymentMethods PropertyPaymentMethod[]
129
+ contracts Contract[]
130
+
125
131
  @@index([subdomain])
126
132
  @@map("tenants")
127
133
  }
@@ -272,6 +278,8 @@ model Settings {
272
278
 
273
279
  model Property {
274
280
  id String @id @default(cuid())
281
+ tenantId String
282
+ tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
275
283
  userId String
276
284
  user User @relation(fields: [userId], references: [id], onDelete: Cascade)
277
285
  title String
@@ -297,10 +305,11 @@ model Property {
297
305
  // Relations
298
306
  documents PropertyDocument[]
299
307
  media PropertyMedia[] @relation("PropertyMedia")
300
- amenities PropertyAmenity[] // Shared amenities (gym, pool, security)
308
+ amenities PropertyAmenity[] // Shared amenities (gym, pool, security)
301
309
  paymentMethods PropertyPaymentMethodLink[]
302
310
  variants PropertyVariant[]
303
311
 
312
+ @@index([tenantId])
304
313
  @@index([userId])
305
314
  @@index([category])
306
315
  @@index([propertyType])
@@ -488,7 +497,9 @@ model PropertyAmenity {
488
497
  // Examples: "Monthly360" (360 monthly payments), "Weekly52", "OneTime"
489
498
  model PaymentPlan {
490
499
  id String @id @default(cuid())
491
- name String @unique
500
+ tenantId String? // NULL = global template available to all tenants
501
+ tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: Cascade)
502
+ name String
492
503
  description String? @db.Text
493
504
  isActive Boolean @default(true)
494
505
 
@@ -507,6 +518,8 @@ model PaymentPlan {
507
518
  // Used by instantiated contract phases
508
519
  contractPhases ContractPhase[]
509
520
 
521
+ @@unique([tenantId, name]) // Unique per tenant, or globally if tenantId is null
522
+ @@index([tenantId])
510
523
  @@map("payment_plans")
511
524
  }
512
525
 
@@ -517,6 +530,8 @@ model PaymentPlan {
517
530
  // PropertyPaymentMethod = how a property can be purchased (e.g., "Standard Mortgage", "Cash", "Rent-to-Own")
518
531
  model PropertyPaymentMethod {
519
532
  id String @id @default(cuid())
533
+ tenantId String
534
+ tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
520
535
  name String // "Standard Mortgage", "Flexible Payment", "Cash Purchase"
521
536
  description String? @db.Text
522
537
  isActive Boolean @default(true)
@@ -537,6 +552,8 @@ model PropertyPaymentMethod {
537
552
  // Contracts using this method
538
553
  contracts Contract[]
539
554
 
555
+ @@unique([tenantId, name]) // Unique per tenant
556
+ @@index([tenantId])
540
557
  @@map("property_payment_methods")
541
558
  }
542
559
 
@@ -604,6 +621,8 @@ model PropertyPaymentMethodPhase {
604
621
 
605
622
  model Contract {
606
623
  id String @id @default(cuid())
624
+ tenantId String
625
+ tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
607
626
  // Link to specific unit being purchased/rented
608
627
  propertyUnitId String
609
628
  propertyUnit PropertyUnit @relation(fields: [propertyUnitId], references: [id], onDelete: Cascade)
@@ -653,6 +672,7 @@ model Contract {
653
672
  transitions ContractTransition[]
654
673
  events ContractEvent[]
655
674
 
675
+ @@index([tenantId])
656
676
  @@index([propertyUnitId])
657
677
  @@index([buyerId])
658
678
  @@index([sellerId])