@valentine-efagene/qshelter-common 2.0.54 → 2.0.56

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.
@@ -6,7 +6,6 @@ export * from './ContractInstallment';
6
6
  export * from './ContractPayment';
7
7
  export * from './ContractPhase';
8
8
  export * from './ContractTermination';
9
- export * from './ContractTransition';
10
9
  export * from './DeviceEndpoint';
11
10
  export * from './DocumentRequirementRule';
12
11
  export * from './DocumentTemplate';
@@ -23,7 +22,6 @@ export * from './PaymentMethodPhaseDocument';
23
22
  export * from './PaymentMethodPhaseStep';
24
23
  export * from './PaymentPlan';
25
24
  export * from './Permission';
26
- export * from './Prequalification';
27
25
  export * from './Property';
28
26
  export * from './PropertyAmenity';
29
27
  export * from './PropertyDocument';
@@ -42,7 +40,6 @@ export * from './Settings';
42
40
  export * from './Social';
43
41
  export * from './Tenant';
44
42
  export * from './Transaction';
45
- export * from './UnderwritingDecision';
46
43
  export * from './User';
47
44
  export * from './UserRole';
48
45
  export * from './UserSuspension';
@@ -6,7 +6,6 @@ export * from './ContractInstallment';
6
6
  export * from './ContractPayment';
7
7
  export * from './ContractPhase';
8
8
  export * from './ContractTermination';
9
- export * from './ContractTransition';
10
9
  export * from './DeviceEndpoint';
11
10
  export * from './DocumentRequirementRule';
12
11
  export * from './DocumentTemplate';
@@ -23,7 +22,6 @@ export * from './PaymentMethodPhaseDocument';
23
22
  export * from './PaymentMethodPhaseStep';
24
23
  export * from './PaymentPlan';
25
24
  export * from './Permission';
26
- export * from './Prequalification';
27
25
  export * from './Property';
28
26
  export * from './PropertyAmenity';
29
27
  export * from './PropertyDocument';
@@ -42,7 +40,6 @@ export * from './Settings';
42
40
  export * from './Social';
43
41
  export * from './Tenant';
44
42
  export * from './Transaction';
45
- export * from './UnderwritingDecision';
46
43
  export * from './User';
47
44
  export * from './UserRole';
48
45
  export * from './UserSuspension';
@@ -37,13 +37,10 @@ export type * from './models/DocumentationStepApproval.js';
37
37
  export type * from './models/ContractInstallment.js';
38
38
  export type * from './models/ContractPayment.js';
39
39
  export type * from './models/ContractDocument.js';
40
- export type * from './models/ContractTransition.js';
41
40
  export type * from './models/ContractEvent.js';
42
41
  export type * from './models/DocumentTemplate.js';
43
42
  export type * from './models/OfferLetter.js';
44
43
  export type * from './models/ContractTermination.js';
45
- export type * from './models/Prequalification.js';
46
- export type * from './models/UnderwritingDecision.js';
47
44
  export type * from './models/PaymentMethodChangeRequest.js';
48
45
  export type * from './models/DocumentRequirementRule.js';
49
46
  export type * from './models/DomainEvent.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valentine-efagene/qshelter-common",
3
- "version": "2.0.54",
3
+ "version": "2.0.56",
4
4
  "description": "Shared database schemas and utilities for QShelter services",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",
@@ -0,0 +1,37 @@
1
+ /*
2
+ Warnings:
3
+
4
+ - The values [PREQUALIFICATION] on the enum `document_requirement_rules_context` will be removed. If these variants are still used in the database, this will fail.
5
+ - You are about to drop the `prequalifications` table. If the table is not empty, all the data it contains will be lost.
6
+ - You are about to drop the `underwriting_decisions` table. If the table is not empty, all the data it contains will be lost.
7
+
8
+ */
9
+ -- DropForeignKey
10
+ ALTER TABLE `prequalifications` DROP FOREIGN KEY `prequalifications_contractId_fkey`;
11
+
12
+ -- DropForeignKey
13
+ ALTER TABLE `prequalifications` DROP FOREIGN KEY `prequalifications_paymentMethodId_fkey`;
14
+
15
+ -- DropForeignKey
16
+ ALTER TABLE `prequalifications` DROP FOREIGN KEY `prequalifications_propertyId_fkey`;
17
+
18
+ -- DropForeignKey
19
+ ALTER TABLE `prequalifications` DROP FOREIGN KEY `prequalifications_tenantId_fkey`;
20
+
21
+ -- DropForeignKey
22
+ ALTER TABLE `prequalifications` DROP FOREIGN KEY `prequalifications_userId_fkey`;
23
+
24
+ -- DropForeignKey
25
+ ALTER TABLE `underwriting_decisions` DROP FOREIGN KEY `underwriting_decisions_prequalificationId_fkey`;
26
+
27
+ -- DropForeignKey
28
+ ALTER TABLE `underwriting_decisions` DROP FOREIGN KEY `underwriting_decisions_tenantId_fkey`;
29
+
30
+ -- AlterTable
31
+ ALTER TABLE `document_requirement_rules` MODIFY `context` ENUM('CONTRACT_PHASE', 'PAYMENT_METHOD_CHANGE') NOT NULL;
32
+
33
+ -- DropTable
34
+ DROP TABLE `prequalifications`;
35
+
36
+ -- DropTable
37
+ DROP TABLE `underwriting_decisions`;
@@ -182,12 +182,6 @@ enum OfferLetterStatus {
182
182
  CANCELLED
183
183
  }
184
184
 
185
- enum UnderwritingDecisionKind {
186
- APPROVE
187
- REJECT
188
- CONDITIONAL
189
- }
190
-
191
185
  // =============================================================================
192
186
  // USER & AUTH DOMAIN
193
187
  // =============================================================================
@@ -232,8 +226,7 @@ model User {
232
226
  stepApprovals DocumentationStepApproval[] @relation("DocumentationStepApprover")
233
227
  uploadedDocs ContractDocument[] @relation("DocumentUploader")
234
228
 
235
- // Prequalification and payment method changes
236
- prequalifications Prequalification[]
229
+ // Payment method changes
237
230
  paymentMethodChangeRequests PaymentMethodChangeRequest[] @relation("ChangeRequestor")
238
231
  reviewedChangeRequests PaymentMethodChangeRequest[] @relation("ChangeReviewer")
239
232
 
@@ -314,8 +307,7 @@ model Tenant {
314
307
  paymentMethods PropertyPaymentMethod[]
315
308
  contracts Contract[]
316
309
 
317
- // Prequalification and payment method changes
318
- prequalifications Prequalification[]
310
+ // Payment method changes
319
311
  paymentMethodChangeRequests PaymentMethodChangeRequest[]
320
312
  documentRequirementRules DocumentRequirementRule[]
321
313
 
@@ -326,9 +318,6 @@ model Tenant {
326
318
  documentTemplates DocumentTemplate[]
327
319
  offerLetters OfferLetter[]
328
320
 
329
- // Underwriting
330
- underwritingDecisions UnderwritingDecision[]
331
-
332
321
  @@index([subdomain])
333
322
  @@map("tenants")
334
323
  }
@@ -504,12 +493,11 @@ model Property {
504
493
  updatedAt DateTime @updatedAt
505
494
 
506
495
  // Relations
507
- documents PropertyDocument[]
508
- media PropertyMedia[] @relation("PropertyMedia")
509
- amenities PropertyAmenity[] // Shared amenities (gym, pool, security)
510
- paymentMethods PropertyPaymentMethodLink[]
511
- variants PropertyVariant[]
512
- prequalifications Prequalification[]
496
+ documents PropertyDocument[]
497
+ media PropertyMedia[] @relation("PropertyMedia")
498
+ amenities PropertyAmenity[] // Shared amenities (gym, pool, security)
499
+ paymentMethods PropertyPaymentMethodLink[]
500
+ variants PropertyVariant[]
513
501
 
514
502
  @@index([tenantId])
515
503
  @@index([userId])
@@ -759,9 +747,6 @@ model PropertyPaymentMethod {
759
747
  // Contracts using this method
760
748
  contracts Contract[]
761
749
 
762
- // Prequalifications for this payment method
763
- prequalifications Prequalification[]
764
-
765
750
  // Payment method change tracking
766
751
  changeRequestsFrom PaymentMethodChangeRequest[] @relation("ChangeFromMethod")
767
752
  changeRequestsTo PaymentMethodChangeRequest[] @relation("ChangeToMethod")
@@ -942,13 +927,10 @@ model Contract {
942
927
  phases ContractPhase[]
943
928
  documents ContractDocument[]
944
929
  payments ContractPayment[]
945
- transitions ContractTransition[]
946
930
  events ContractEvent[]
947
931
  terminations ContractTermination[]
948
932
  offerLetters OfferLetter[]
949
933
 
950
- // Prequalification that led to this contract (optional)
951
- prequalification Prequalification?
952
934
  // Payment method change requests for this contract
953
935
  paymentMethodChangeRequests PaymentMethodChangeRequest[]
954
936
 
@@ -1210,31 +1192,35 @@ model ContractDocument {
1210
1192
  @@map("contract_documents")
1211
1193
  }
1212
1194
 
1213
- // FSM transitions for audit
1214
- model ContractTransition {
1215
- id String @id @default(cuid())
1216
- contractId String
1217
- contract Contract @relation(fields: [contractId], references: [id], onDelete: Cascade)
1218
- fromState String
1219
- toState String
1220
- trigger String
1221
- metadata String? @db.Text // JSON
1222
- transitionedAt DateTime @default(now())
1223
-
1224
- @@index([contractId])
1225
- @@map("contract_transitions")
1226
- }
1227
-
1228
- // Domain events for audit and integration
1195
+ // Contract domain events (FSM transitions, payments, documents, etc.)
1229
1196
  model ContractEvent {
1230
1197
  id String @id @default(cuid())
1231
1198
  contractId String
1232
1199
  contract Contract @relation(fields: [contractId], references: [id], onDelete: Cascade)
1233
- event String
1234
- data String? @db.Text // JSON
1235
- createdAt DateTime @default(now())
1200
+
1201
+ // Event classification
1202
+ eventType String // STATE.TRANSITION, PHASE.ACTIVATED, PAYMENT.COMPLETED, etc.
1203
+ eventGroup String? // STATE_CHANGE, PAYMENT, DOCUMENT, NOTIFICATION (for filtering)
1204
+
1205
+ // For state transitions (optional - only populated for STATE.TRANSITION events)
1206
+ fromState String?
1207
+ toState String?
1208
+ trigger String?
1209
+
1210
+ // Event payload (all event-specific data)
1211
+ data Json?
1212
+
1213
+ // Actor tracking
1214
+ actorId String?
1215
+ actorType String? // USER, SYSTEM, WEBHOOK
1216
+
1217
+ // Timing
1218
+ occurredAt DateTime @default(now())
1236
1219
 
1237
1220
  @@index([contractId])
1221
+ @@index([eventType])
1222
+ @@index([eventGroup])
1223
+ @@index([occurredAt])
1238
1224
  @@map("contract_events")
1239
1225
  }
1240
1226
 
@@ -1418,120 +1404,6 @@ model ContractTermination {
1418
1404
  @@map("contract_terminations")
1419
1405
  }
1420
1406
 
1421
- // =============================================================================
1422
- // PREQUALIFICATION - Eligibility assessment before contract creation
1423
- // =============================================================================
1424
- // Prequalification is a separate aggregate that evaluates a user's eligibility
1425
- // for a specific product (property + payment method). It captures their answers
1426
- // to eligibility questions and calculates a score. Once approved, it can be
1427
- // linked to a Contract to provide context about how the buyer qualified.
1428
- // =============================================================================
1429
-
1430
- enum PrequalificationStatus {
1431
- DRAFT
1432
- SUBMITTED
1433
- UNDER_REVIEW
1434
- APPROVED
1435
- REJECTED
1436
- EXPIRED
1437
- }
1438
-
1439
- model Prequalification {
1440
- id String @id @default(cuid())
1441
- tenantId String
1442
- tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
1443
- userId String
1444
- user User @relation(fields: [userId], references: [id], onDelete: Cascade)
1445
-
1446
- // What they're applying for
1447
- propertyId String
1448
- property Property @relation(fields: [propertyId], references: [id], onDelete: Cascade)
1449
- paymentMethodId String
1450
- paymentMethod PropertyPaymentMethod @relation(fields: [paymentMethodId], references: [id])
1451
-
1452
- // Questionnaire responses and scoring
1453
- answers Json // Array of {questionId, answer, weight, score}
1454
- score Float? // Computed eligibility score (0-100)
1455
-
1456
- // Financial assessment
1457
- requestedAmount Float? // How much they want to finance
1458
- monthlyIncome Float? // Self-reported monthly income
1459
- monthlyExpenses Float? // Self-reported monthly expenses
1460
- debtToIncomeRatio Float? // Computed DTI
1461
- suggestedTermMonths Int? // System-suggested term based on affordability
1462
-
1463
- // Status tracking
1464
- status PrequalificationStatus @default(DRAFT)
1465
- notes String? @db.Text // Admin notes
1466
- reviewedBy String? // Admin who reviewed
1467
- reviewedAt DateTime?
1468
- expiresAt DateTime? // Prequalification validity period
1469
-
1470
- // If approved, may be linked to eventual contract
1471
- contractId String? @unique
1472
- contract Contract? @relation(fields: [contractId], references: [id])
1473
-
1474
- // Underwriting decisions for this prequalification
1475
- underwritingDecisions UnderwritingDecision[]
1476
-
1477
- createdAt DateTime @default(now())
1478
- updatedAt DateTime @updatedAt
1479
-
1480
- @@index([tenantId])
1481
- @@index([userId])
1482
- @@index([propertyId])
1483
- @@index([status])
1484
- @@map("prequalifications")
1485
- }
1486
-
1487
- // =============================================================================
1488
- // UNDERWRITING DECISION - Automated/manual credit decisions
1489
- // =============================================================================
1490
- // Records each underwriting decision for a prequalification. Multiple decisions
1491
- // may exist if re-evaluation occurs (e.g., after document submission).
1492
- // =============================================================================
1493
-
1494
- model UnderwritingDecision {
1495
- id String @id @default(cuid())
1496
- tenantId String
1497
- tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
1498
-
1499
- // Link to prequalification being evaluated
1500
- prequalificationId String
1501
- prequalification Prequalification @relation(fields: [prequalificationId], references: [id], onDelete: Cascade)
1502
-
1503
- // Decision outcome
1504
- decision UnderwritingDecisionKind
1505
-
1506
- // Scoring and rationale
1507
- score Float? // Computed risk score (0-100)
1508
- reasons Json? // Array of reason codes/messages for decision
1509
- conditions Json? // Array of conditions for CONDITIONAL decisions
1510
-
1511
- // Rule engine metadata
1512
- rulesVersion String? // Version of rules/model used
1513
- ruleResults Json? // Detailed rule evaluation results
1514
-
1515
- // External data references (credit bureau, verifications)
1516
- externalChecks Json? // { creditBureau: {...}, incomeVerification: {...} }
1517
-
1518
- // Manual review (if escalated)
1519
- isManualReview Boolean @default(false)
1520
- reviewedBy String? // Admin who reviewed
1521
- reviewedAt DateTime?
1522
- reviewNotes String? @db.Text
1523
-
1524
- // Audit
1525
- createdAt DateTime @default(now())
1526
- updatedAt DateTime @updatedAt
1527
-
1528
- @@index([tenantId])
1529
- @@index([prequalificationId])
1530
- @@index([decision])
1531
- @@index([createdAt])
1532
- @@map("underwriting_decisions")
1533
- }
1534
-
1535
1407
  // =============================================================================
1536
1408
  // PAYMENT METHOD CHANGE REQUEST - Mid-contract payment method changes
1537
1409
  // =============================================================================
@@ -1613,7 +1485,6 @@ model PaymentMethodChangeRequest {
1613
1485
  // =============================================================================
1614
1486
 
1615
1487
  enum DocumentRequirementContext {
1616
- PREQUALIFICATION // During prequalification
1617
1488
  CONTRACT_PHASE // During a contract phase
1618
1489
  PAYMENT_METHOD_CHANGE // When changing payment method mid-contract
1619
1490
  }