@valentine-efagene/qshelter-common 2.0.53 → 2.0.55

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.
@@ -23,7 +23,6 @@ export * from './PaymentMethodPhaseDocument';
23
23
  export * from './PaymentMethodPhaseStep';
24
24
  export * from './PaymentPlan';
25
25
  export * from './Permission';
26
- export * from './Prequalification';
27
26
  export * from './Property';
28
27
  export * from './PropertyAmenity';
29
28
  export * from './PropertyDocument';
@@ -42,7 +41,6 @@ export * from './Settings';
42
41
  export * from './Social';
43
42
  export * from './Tenant';
44
43
  export * from './Transaction';
45
- export * from './UnderwritingDecision';
46
44
  export * from './User';
47
45
  export * from './UserRole';
48
46
  export * from './UserSuspension';
@@ -23,7 +23,6 @@ export * from './PaymentMethodPhaseDocument';
23
23
  export * from './PaymentMethodPhaseStep';
24
24
  export * from './PaymentPlan';
25
25
  export * from './Permission';
26
- export * from './Prequalification';
27
26
  export * from './Property';
28
27
  export * from './PropertyAmenity';
29
28
  export * from './PropertyDocument';
@@ -42,7 +41,6 @@ export * from './Settings';
42
41
  export * from './Social';
43
42
  export * from './Tenant';
44
43
  export * from './Transaction';
45
- export * from './UnderwritingDecision';
46
44
  export * from './User';
47
45
  export * from './UserRole';
48
46
  export * from './UserSuspension';
@@ -42,8 +42,6 @@ export type * from './models/ContractEvent.js';
42
42
  export type * from './models/DocumentTemplate.js';
43
43
  export type * from './models/OfferLetter.js';
44
44
  export type * from './models/ContractTermination.js';
45
- export type * from './models/Prequalification.js';
46
- export type * from './models/UnderwritingDecision.js';
47
45
  export type * from './models/PaymentMethodChangeRequest.js';
48
46
  export type * from './models/DocumentRequirementRule.js';
49
47
  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.53",
3
+ "version": "2.0.55",
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,2 @@
1
+ -- AlterTable
2
+ ALTER TABLE `contract_phases` MODIFY `status` ENUM('PENDING', 'IN_PROGRESS', 'AWAITING_APPROVAL', 'ACTIVE', 'COMPLETED', 'SKIPPED', 'FAILED', 'SUPERSEDED') NOT NULL DEFAULT 'PENDING';
@@ -0,0 +1,17 @@
1
+ -- AlterTable
2
+ ALTER TABLE `contract_phase_steps` ADD COLUMN `debtToIncomeRatio` DOUBLE NULL,
3
+ ADD COLUMN `preApprovalAnswers` JSON NULL,
4
+ ADD COLUMN `underwritingDecision` VARCHAR(191) NULL,
5
+ ADD COLUMN `underwritingNotes` TEXT NULL,
6
+ ADD COLUMN `underwritingScore` DOUBLE NULL,
7
+ MODIFY `stepType` ENUM('UPLOAD', 'REVIEW', 'SIGNATURE', 'APPROVAL', 'EXTERNAL_CHECK', 'WAIT', 'GENERATE_DOCUMENT', 'PRE_APPROVAL', 'UNDERWRITING') NOT NULL;
8
+
9
+ -- AlterTable
10
+ ALTER TABLE `contracts` ADD COLUMN `debtToIncomeRatio` DOUBLE NULL,
11
+ ADD COLUMN `monthlyExpenses` DOUBLE NULL,
12
+ ADD COLUMN `monthlyIncome` DOUBLE NULL,
13
+ ADD COLUMN `preApprovalAnswers` JSON NULL,
14
+ ADD COLUMN `underwritingScore` DOUBLE NULL;
15
+
16
+ -- AlterTable
17
+ ALTER TABLE `payment_method_phase_steps` MODIFY `stepType` ENUM('UPLOAD', 'REVIEW', 'SIGNATURE', 'APPROVAL', 'EXTERNAL_CHECK', 'WAIT', 'GENERATE_DOCUMENT', 'PRE_APPROVAL', 'UNDERWRITING') NOT NULL;
@@ -69,6 +69,8 @@ enum StepType {
69
69
  EXTERNAL_CHECK
70
70
  WAIT
71
71
  GENERATE_DOCUMENT // Triggers document generation (offer letters, contracts, etc.)
72
+ PRE_APPROVAL // Customer answers eligibility questionnaire
73
+ UNDERWRITING // System evaluates DTI, score, eligibility
72
74
  }
73
75
 
74
76
  enum StepStatus {
@@ -180,12 +182,6 @@ enum OfferLetterStatus {
180
182
  CANCELLED
181
183
  }
182
184
 
183
- enum UnderwritingDecisionKind {
184
- APPROVE
185
- REJECT
186
- CONDITIONAL
187
- }
188
-
189
185
  // =============================================================================
190
186
  // USER & AUTH DOMAIN
191
187
  // =============================================================================
@@ -230,8 +226,7 @@ model User {
230
226
  stepApprovals DocumentationStepApproval[] @relation("DocumentationStepApprover")
231
227
  uploadedDocs ContractDocument[] @relation("DocumentUploader")
232
228
 
233
- // Prequalification and payment method changes
234
- prequalifications Prequalification[]
229
+ // Payment method changes
235
230
  paymentMethodChangeRequests PaymentMethodChangeRequest[] @relation("ChangeRequestor")
236
231
  reviewedChangeRequests PaymentMethodChangeRequest[] @relation("ChangeReviewer")
237
232
 
@@ -312,8 +307,7 @@ model Tenant {
312
307
  paymentMethods PropertyPaymentMethod[]
313
308
  contracts Contract[]
314
309
 
315
- // Prequalification and payment method changes
316
- prequalifications Prequalification[]
310
+ // Payment method changes
317
311
  paymentMethodChangeRequests PaymentMethodChangeRequest[]
318
312
  documentRequirementRules DocumentRequirementRule[]
319
313
 
@@ -324,9 +318,6 @@ model Tenant {
324
318
  documentTemplates DocumentTemplate[]
325
319
  offerLetters OfferLetter[]
326
320
 
327
- // Underwriting
328
- underwritingDecisions UnderwritingDecision[]
329
-
330
321
  @@index([subdomain])
331
322
  @@map("tenants")
332
323
  }
@@ -502,12 +493,11 @@ model Property {
502
493
  updatedAt DateTime @updatedAt
503
494
 
504
495
  // Relations
505
- documents PropertyDocument[]
506
- media PropertyMedia[] @relation("PropertyMedia")
507
- amenities PropertyAmenity[] // Shared amenities (gym, pool, security)
508
- paymentMethods PropertyPaymentMethodLink[]
509
- variants PropertyVariant[]
510
- prequalifications Prequalification[]
496
+ documents PropertyDocument[]
497
+ media PropertyMedia[] @relation("PropertyMedia")
498
+ amenities PropertyAmenity[] // Shared amenities (gym, pool, security)
499
+ paymentMethods PropertyPaymentMethodLink[]
500
+ variants PropertyVariant[]
511
501
 
512
502
  @@index([tenantId])
513
503
  @@index([userId])
@@ -757,9 +747,6 @@ model PropertyPaymentMethod {
757
747
  // Contracts using this method
758
748
  contracts Contract[]
759
749
 
760
- // Prequalifications for this payment method
761
- prequalifications Prequalification[]
762
-
763
750
  // Payment method change tracking
764
751
  changeRequestsFrom PaymentMethodChangeRequest[] @relation("ChangeFromMethod")
765
752
  changeRequestsTo PaymentMethodChangeRequest[] @relation("ChangeToMethod")
@@ -914,6 +901,13 @@ model Contract {
914
901
  totalPaidToDate Float @default(0)
915
902
  totalInterestPaid Float @default(0)
916
903
 
904
+ // Pre-approval and underwriting data (moved from prequalification)
905
+ monthlyIncome Float? // Buyer's monthly income
906
+ monthlyExpenses Float? // Buyer's monthly expenses
907
+ preApprovalAnswers Json? // Questionnaire answers from PRE_APPROVAL step
908
+ underwritingScore Float? // Aggregate score from underwriting evaluation
909
+ debtToIncomeRatio Float? // Calculated DTI ratio
910
+
917
911
  // FSM state (DB-enforced enums)
918
912
  status ContractStatus @default(DRAFT)
919
913
  state ContractStatus @default(DRAFT) // FSM state for workflow
@@ -938,8 +932,6 @@ model Contract {
938
932
  terminations ContractTermination[]
939
933
  offerLetters OfferLetter[]
940
934
 
941
- // Prequalification that led to this contract (optional)
942
- prequalification Prequalification?
943
935
  // Payment method change requests for this contract
944
936
  paymentMethodChangeRequests PaymentMethodChangeRequest[]
945
937
 
@@ -1040,6 +1032,15 @@ model DocumentationStep {
1040
1032
  // Configuration metadata (for GENERATE_DOCUMENT steps, etc.)
1041
1033
  metadata Json?
1042
1034
 
1035
+ // For PRE_APPROVAL steps: store questionnaire answers
1036
+ preApprovalAnswers Json?
1037
+
1038
+ // For UNDERWRITING steps: store evaluation results
1039
+ underwritingScore Float?
1040
+ debtToIncomeRatio Float?
1041
+ underwritingDecision String? // APPROVED, CONDITIONAL, DECLINED
1042
+ underwritingNotes String? @db.Text
1043
+
1043
1044
  // Assignment
1044
1045
  assigneeId String?
1045
1046
  assignee User? @relation("DocumentationStepAssignee", fields: [assigneeId], references: [id])
@@ -1400,119 +1401,7 @@ model ContractTermination {
1400
1401
  @@map("contract_terminations")
1401
1402
  }
1402
1403
 
1403
- // =============================================================================
1404
- // PREQUALIFICATION - Eligibility assessment before contract creation
1405
- // =============================================================================
1406
- // Prequalification is a separate aggregate that evaluates a user's eligibility
1407
- // for a specific product (property + payment method). It captures their answers
1408
- // to eligibility questions and calculates a score. Once approved, it can be
1409
- // linked to a Contract to provide context about how the buyer qualified.
1410
- // =============================================================================
1411
-
1412
- enum PrequalificationStatus {
1413
- DRAFT
1414
- SUBMITTED
1415
- UNDER_REVIEW
1416
- APPROVED
1417
- REJECTED
1418
- EXPIRED
1419
- }
1420
-
1421
- model Prequalification {
1422
- id String @id @default(cuid())
1423
- tenantId String
1424
- tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
1425
- userId String
1426
- user User @relation(fields: [userId], references: [id], onDelete: Cascade)
1427
-
1428
- // What they're applying for
1429
- propertyId String
1430
- property Property @relation(fields: [propertyId], references: [id], onDelete: Cascade)
1431
- paymentMethodId String
1432
- paymentMethod PropertyPaymentMethod @relation(fields: [paymentMethodId], references: [id])
1433
-
1434
- // Questionnaire responses and scoring
1435
- answers Json // Array of {questionId, answer, weight, score}
1436
- score Float? // Computed eligibility score (0-100)
1437
-
1438
- // Financial assessment
1439
- requestedAmount Float? // How much they want to finance
1440
- monthlyIncome Float? // Self-reported monthly income
1441
- monthlyExpenses Float? // Self-reported monthly expenses
1442
- debtToIncomeRatio Float? // Computed DTI
1443
- suggestedTermMonths Int? // System-suggested term based on affordability
1444
-
1445
- // Status tracking
1446
- status PrequalificationStatus @default(DRAFT)
1447
- notes String? @db.Text // Admin notes
1448
- reviewedBy String? // Admin who reviewed
1449
- reviewedAt DateTime?
1450
- expiresAt DateTime? // Prequalification validity period
1451
-
1452
- // If approved, may be linked to eventual contract
1453
- contractId String? @unique
1454
- contract Contract? @relation(fields: [contractId], references: [id])
1455
-
1456
- // Underwriting decisions for this prequalification
1457
- underwritingDecisions UnderwritingDecision[]
1458
-
1459
- createdAt DateTime @default(now())
1460
- updatedAt DateTime @updatedAt
1461
-
1462
- @@index([tenantId])
1463
- @@index([userId])
1464
- @@index([propertyId])
1465
- @@index([status])
1466
- @@map("prequalifications")
1467
- }
1468
-
1469
- // =============================================================================
1470
- // UNDERWRITING DECISION - Automated/manual credit decisions
1471
- // =============================================================================
1472
- // Records each underwriting decision for a prequalification. Multiple decisions
1473
- // may exist if re-evaluation occurs (e.g., after document submission).
1474
- // =============================================================================
1475
-
1476
- model UnderwritingDecision {
1477
- id String @id @default(cuid())
1478
- tenantId String
1479
- tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
1480
-
1481
- // Link to prequalification being evaluated
1482
- prequalificationId String
1483
- prequalification Prequalification @relation(fields: [prequalificationId], references: [id], onDelete: Cascade)
1484
-
1485
- // Decision outcome
1486
- decision UnderwritingDecisionKind
1487
-
1488
- // Scoring and rationale
1489
- score Float? // Computed risk score (0-100)
1490
- reasons Json? // Array of reason codes/messages for decision
1491
- conditions Json? // Array of conditions for CONDITIONAL decisions
1492
-
1493
- // Rule engine metadata
1494
- rulesVersion String? // Version of rules/model used
1495
- ruleResults Json? // Detailed rule evaluation results
1496
-
1497
- // External data references (credit bureau, verifications)
1498
- externalChecks Json? // { creditBureau: {...}, incomeVerification: {...} }
1499
1404
 
1500
- // Manual review (if escalated)
1501
- isManualReview Boolean @default(false)
1502
- reviewedBy String? // Admin who reviewed
1503
- reviewedAt DateTime?
1504
- reviewNotes String? @db.Text
1505
-
1506
- // Audit
1507
- createdAt DateTime @default(now())
1508
- updatedAt DateTime @updatedAt
1509
-
1510
- @@index([tenantId])
1511
- @@index([prequalificationId])
1512
- @@index([decision])
1513
- @@index([createdAt])
1514
- @@map("underwriting_decisions")
1515
- }
1516
1405
 
1517
1406
  // =============================================================================
1518
1407
  // PAYMENT METHOD CHANGE REQUEST - Mid-contract payment method changes
@@ -1595,7 +1484,6 @@ model PaymentMethodChangeRequest {
1595
1484
  // =============================================================================
1596
1485
 
1597
1486
  enum DocumentRequirementContext {
1598
- PREQUALIFICATION // During prequalification
1599
1487
  CONTRACT_PHASE // During a contract phase
1600
1488
  PAYMENT_METHOD_CHANGE // When changing payment method mid-contract
1601
1489
  }