@valentine-efagene/qshelter-common 2.0.102 → 2.0.104

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.
Files changed (31) hide show
  1. package/dist/generated/client/browser.d.ts +20 -0
  2. package/dist/generated/client/client.d.ts +20 -0
  3. package/dist/generated/client/commonInputTypes.d.ts +174 -84
  4. package/dist/generated/client/enums.d.ts +34 -0
  5. package/dist/generated/client/enums.js +31 -0
  6. package/dist/generated/client/internal/class.d.ts +44 -0
  7. package/dist/generated/client/internal/class.js +2 -2
  8. package/dist/generated/client/internal/prismaNamespace.d.ts +389 -5
  9. package/dist/generated/client/internal/prismaNamespace.js +96 -0
  10. package/dist/generated/client/internal/prismaNamespaceBrowser.d.ts +104 -0
  11. package/dist/generated/client/internal/prismaNamespaceBrowser.js +96 -0
  12. package/dist/generated/client/models/DocumentationPhase.d.ts +231 -1
  13. package/dist/generated/client/models/DocumentationPlan.d.ts +1555 -0
  14. package/dist/generated/client/models/DocumentationPlan.js +1 -0
  15. package/dist/generated/client/models/DocumentationPlanStep.d.ts +1220 -0
  16. package/dist/generated/client/models/DocumentationPlanStep.js +1 -0
  17. package/dist/generated/client/models/PaymentMethodPhaseStep.d.ts +0 -3
  18. package/dist/generated/client/models/PropertyPaymentMethodPhase.d.ts +585 -1
  19. package/dist/generated/client/models/QuestionnairePhase.d.ts +413 -1
  20. package/dist/generated/client/models/QuestionnairePlan.d.ts +1844 -0
  21. package/dist/generated/client/models/QuestionnairePlan.js +1 -0
  22. package/dist/generated/client/models/QuestionnairePlanQuestion.d.ts +1444 -0
  23. package/dist/generated/client/models/QuestionnairePlanQuestion.js +1 -0
  24. package/dist/generated/client/models/Tenant.d.ts +1208 -118
  25. package/dist/generated/client/models/index.d.ts +4 -0
  26. package/dist/generated/client/models/index.js +4 -0
  27. package/dist/generated/client/models.d.ts +4 -0
  28. package/dist/src/prisma/tenant.js +4 -0
  29. package/package.json +1 -1
  30. package/prisma/migrations/20260114034523_add_documentation_plan/migration.sql +52 -0
  31. package/prisma/schema.prisma +210 -8
@@ -12,6 +12,8 @@ export * from './DeviceEndpoint';
12
12
  export * from './DocumentRequirementRule';
13
13
  export * from './DocumentTemplate';
14
14
  export * from './DocumentationPhase';
15
+ export * from './DocumentationPlan';
16
+ export * from './DocumentationPlanStep';
15
17
  export * from './DocumentationStep';
16
18
  export * from './DocumentationStepApproval';
17
19
  export * from './DocumentationStepDocument';
@@ -47,6 +49,8 @@ export * from './PropertyVariantAmenity';
47
49
  export * from './PropertyVariantMedia';
48
50
  export * from './QuestionnaireField';
49
51
  export * from './QuestionnairePhase';
52
+ export * from './QuestionnairePlan';
53
+ export * from './QuestionnairePlanQuestion';
50
54
  export * from './RefreshToken';
51
55
  export * from './Role';
52
56
  export * from './RolePermission';
@@ -12,6 +12,8 @@ export * from './DeviceEndpoint';
12
12
  export * from './DocumentRequirementRule';
13
13
  export * from './DocumentTemplate';
14
14
  export * from './DocumentationPhase';
15
+ export * from './DocumentationPlan';
16
+ export * from './DocumentationPlanStep';
15
17
  export * from './DocumentationStep';
16
18
  export * from './DocumentationStepApproval';
17
19
  export * from './DocumentationStepDocument';
@@ -47,6 +49,8 @@ export * from './PropertyVariantAmenity';
47
49
  export * from './PropertyVariantMedia';
48
50
  export * from './QuestionnaireField';
49
51
  export * from './QuestionnairePhase';
52
+ export * from './QuestionnairePlan';
53
+ export * from './QuestionnairePlanQuestion';
50
54
  export * from './RefreshToken';
51
55
  export * from './Role';
52
56
  export * from './RolePermission';
@@ -25,6 +25,10 @@ export type * from './models/PropertyVariantAmenity.js';
25
25
  export type * from './models/PropertyVariantMedia.js';
26
26
  export type * from './models/PropertyUnit.js';
27
27
  export type * from './models/PropertyAmenity.js';
28
+ export type * from './models/DocumentationPlan.js';
29
+ export type * from './models/DocumentationPlanStep.js';
30
+ export type * from './models/QuestionnairePlan.js';
31
+ export type * from './models/QuestionnairePlanQuestion.js';
28
32
  export type * from './models/PaymentPlan.js';
29
33
  export type * from './models/PropertyPaymentMethod.js';
30
34
  export type * from './models/PropertyPaymentMethodLink.js';
@@ -28,6 +28,10 @@ const GLOBAL_MODELS = [
28
28
  */
29
29
  const OPTIONAL_TENANT_MODELS = [
30
30
  "paymentPlan",
31
+ // DocumentationPlan can be global template (tenantId = null) or tenant-specific
32
+ "documentationPlan",
33
+ // QuestionnairePlan can be global template (tenantId = null) or tenant-specific
34
+ "questionnairePlan",
31
35
  // Role can be global template (tenantId = null) or tenant-specific
32
36
  "role",
33
37
  // Permission can be global template or tenant-specific
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valentine-efagene/qshelter-common",
3
- "version": "2.0.102",
3
+ "version": "2.0.104",
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,52 @@
1
+ -- AlterTable
2
+ ALTER TABLE `documentation_phases` ADD COLUMN `documentationPlanId` VARCHAR(191) NULL;
3
+
4
+ -- AlterTable
5
+ ALTER TABLE `property_payment_method_phases` ADD COLUMN `documentationPlanId` VARCHAR(191) NULL;
6
+
7
+ -- CreateTable
8
+ CREATE TABLE `documentation_plans` (
9
+ `id` VARCHAR(191) NOT NULL,
10
+ `tenantId` VARCHAR(191) NULL,
11
+ `name` VARCHAR(191) NOT NULL,
12
+ `description` TEXT NULL,
13
+ `isActive` BOOLEAN NOT NULL DEFAULT true,
14
+ `requiredDocumentTypes` JSON NULL,
15
+ `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
16
+ `updatedAt` DATETIME(3) NOT NULL,
17
+
18
+ INDEX `documentation_plans_tenantId_idx`(`tenantId`),
19
+ UNIQUE INDEX `documentation_plans_tenantId_name_key`(`tenantId`, `name`),
20
+ PRIMARY KEY (`id`)
21
+ ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
22
+
23
+ -- CreateTable
24
+ CREATE TABLE `documentation_plan_steps` (
25
+ `id` VARCHAR(191) NOT NULL,
26
+ `planId` VARCHAR(191) NOT NULL,
27
+ `name` VARCHAR(191) NOT NULL,
28
+ `stepType` ENUM('UPLOAD', 'REVIEW', 'SIGNATURE', 'APPROVAL', 'EXTERNAL_CHECK', 'WAIT', 'GENERATE_DOCUMENT', 'PRE_APPROVAL', 'UNDERWRITING') NOT NULL,
29
+ `order` INTEGER NOT NULL,
30
+ `documentType` VARCHAR(191) NULL,
31
+ `metadata` JSON NULL,
32
+ `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
33
+ `updatedAt` DATETIME(3) NOT NULL,
34
+
35
+ INDEX `documentation_plan_steps_planId_idx`(`planId`),
36
+ PRIMARY KEY (`id`)
37
+ ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
38
+
39
+ -- CreateIndex
40
+ CREATE INDEX `property_payment_method_phases_documentationPlanId_idx` ON `property_payment_method_phases`(`documentationPlanId`);
41
+
42
+ -- AddForeignKey
43
+ ALTER TABLE `documentation_plans` ADD CONSTRAINT `documentation_plans_tenantId_fkey` FOREIGN KEY (`tenantId`) REFERENCES `tenants`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
44
+
45
+ -- AddForeignKey
46
+ ALTER TABLE `documentation_plan_steps` ADD CONSTRAINT `documentation_plan_steps_planId_fkey` FOREIGN KEY (`planId`) REFERENCES `documentation_plans`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
47
+
48
+ -- AddForeignKey
49
+ ALTER TABLE `property_payment_method_phases` ADD CONSTRAINT `property_payment_method_phases_documentationPlanId_fkey` FOREIGN KEY (`documentationPlanId`) REFERENCES `documentation_plans`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
50
+
51
+ -- AddForeignKey
52
+ ALTER TABLE `documentation_phases` ADD CONSTRAINT `documentation_phases_documentationPlanId_fkey` FOREIGN KEY (`documentationPlanId`) REFERENCES `documentation_plans`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
@@ -492,11 +492,12 @@ model Tenant {
492
492
  updatedAt DateTime @updatedAt
493
493
 
494
494
  // Back-relations for multitenancy
495
- users User[]
496
- properties Property[]
497
- paymentPlans PaymentPlan[]
498
- paymentMethods PropertyPaymentMethod[]
499
- applications Application[]
495
+ users User[]
496
+ properties Property[]
497
+ paymentPlans PaymentPlan[]
498
+ documentationPlans DocumentationPlan[]
499
+ paymentMethods PropertyPaymentMethod[]
500
+ applications Application[]
500
501
 
501
502
  // RBAC: Tenant-scoped roles and permissions
502
503
  roles Role[]
@@ -566,6 +567,7 @@ model Tenant {
566
567
  settings Settings[]
567
568
  domainEvents DomainEvent[]
568
569
  workflowBlockers WorkflowBlocker[]
570
+ questionnairePlans QuestionnairePlan[]
569
571
 
570
572
  @@index([subdomain])
571
573
  @@map("tenants")
@@ -1023,6 +1025,144 @@ model PropertyAmenity {
1023
1025
  @@map("property_amenities")
1024
1026
  }
1025
1027
 
1028
+ // =============================================================================
1029
+ // DOCUMENTATION PLAN DOMAIN - Reusable step workflow templates
1030
+ // =============================================================================
1031
+
1032
+ // DocumentationPlan = reusable structure for documentation workflows
1033
+ // Examples: "Standard KYC", "Quick Verification", "Full Underwriting"
1034
+ model DocumentationPlan {
1035
+ id String @id @default(cuid())
1036
+ tenantId String? // NULL = global template available to all tenants
1037
+ tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: Cascade)
1038
+ name String
1039
+ description String? @db.Text
1040
+ isActive Boolean @default(true)
1041
+
1042
+ // Document requirements for this plan
1043
+ requiredDocumentTypes Json? // Array of document type strings, e.g., ["ID_CARD", "BANK_STATEMENT"]
1044
+
1045
+ createdAt DateTime @default(now())
1046
+ updatedAt DateTime @updatedAt
1047
+
1048
+ // Steps that make up this plan
1049
+ steps DocumentationPlanStep[]
1050
+ // Used by property payment method phases (templates)
1051
+ methodPhases PropertyPaymentMethodPhase[]
1052
+ // Used by instantiated documentation phases
1053
+ documentationPhases DocumentationPhase[]
1054
+
1055
+ @@unique([tenantId, name]) // Unique per tenant, or globally if tenantId is null
1056
+ @@index([tenantId])
1057
+ @@map("documentation_plans")
1058
+ }
1059
+
1060
+ // Step template within a DocumentationPlan
1061
+ model DocumentationPlanStep {
1062
+ id String @id @default(cuid())
1063
+ planId String
1064
+ plan DocumentationPlan @relation(fields: [planId], references: [id], onDelete: Cascade)
1065
+
1066
+ name String
1067
+ stepType StepType
1068
+ order Int
1069
+
1070
+ // Optional: which document type this step handles (for UPLOAD steps)
1071
+ documentType String?
1072
+ metadata Json?
1073
+
1074
+ createdAt DateTime @default(now())
1075
+ updatedAt DateTime @updatedAt
1076
+
1077
+ @@index([planId])
1078
+ @@map("documentation_plan_steps")
1079
+ }
1080
+
1081
+ // =============================================================================
1082
+ // QUESTIONNAIRE PLAN DOMAIN - Reusable form templates with scoring
1083
+ // =============================================================================
1084
+ // QuestionnairePlan = reusable structure for prequalification/screening forms
1085
+ // Examples: "Mortgage Prequalification", "Affordability Assessment", "Risk Screening"
1086
+ // =============================================================================
1087
+
1088
+ model QuestionnairePlan {
1089
+ id String @id @default(cuid())
1090
+ tenantId String? // NULL = global template available to all tenants
1091
+ tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: Cascade)
1092
+ name String
1093
+ description String? @db.Text
1094
+ version Int @default(1)
1095
+ isActive Boolean @default(true)
1096
+
1097
+ // Scoring configuration
1098
+ passingScore Int? // Minimum score to pass (null = no auto-scoring)
1099
+ scoringStrategy ScoringStrategy @default(SUM)
1100
+ autoDecisionEnabled Boolean @default(false) // Auto-pass/fail based on score
1101
+
1102
+ // Metadata
1103
+ estimatedMinutes Int? // Estimated time to complete
1104
+ category QuestionnaireCategory @default(PREQUALIFICATION)
1105
+
1106
+ createdAt DateTime @default(now())
1107
+ updatedAt DateTime @updatedAt
1108
+
1109
+ // Questions that make up this plan
1110
+ questions QuestionnairePlanQuestion[]
1111
+
1112
+ // Used by property payment method phases (templates)
1113
+ methodPhases PropertyPaymentMethodPhase[]
1114
+
1115
+ // Used by instantiated questionnaire phases
1116
+ questionnairePhases QuestionnairePhase[]
1117
+
1118
+ @@unique([tenantId, name, version])
1119
+ @@index([tenantId])
1120
+ @@index([category])
1121
+ @@map("questionnaire_plans")
1122
+ }
1123
+
1124
+ // Question template within a QuestionnairePlan
1125
+ model QuestionnairePlanQuestion {
1126
+ id String @id @default(cuid())
1127
+ questionnairePlanId String
1128
+ questionnairePlan QuestionnairePlan @relation(fields: [questionnairePlanId], references: [id], onDelete: Cascade)
1129
+
1130
+ // Question identification
1131
+ questionKey String // Unique key for this question (e.g., "annual_income")
1132
+ questionText String @db.Text // The actual question text
1133
+ helpText String? @db.Text // Optional help/tooltip text
1134
+
1135
+ // Field configuration
1136
+ questionType QuestionType
1137
+ order Int
1138
+
1139
+ // Validation
1140
+ isRequired Boolean @default(true)
1141
+ validationRules Json? // { min: 0, max: 1000000, pattern: "^[0-9]+$" }
1142
+
1143
+ // Options for SELECT/MULTI_SELECT/RADIO
1144
+ // [{ value: "employed", label: "Employed", score: 10 }, ...]
1145
+ options Json?
1146
+
1147
+ // Scoring
1148
+ scoreWeight Int @default(1) // Multiplier for this question's score
1149
+ scoringRules Json? // { "employed": 10, "self_employed": 7, "unemployed": 0 } or ranges
1150
+
1151
+ // Conditional logic (branching)
1152
+ // { "questionKey": "employment_status", "equals": "employed" }
1153
+ showIf Json?
1154
+
1155
+ // Metadata for grouping
1156
+ category String? // Group questions (e.g., "income", "employment", "property")
1157
+
1158
+ createdAt DateTime @default(now())
1159
+ updatedAt DateTime @updatedAt
1160
+
1161
+ @@unique([questionnairePlanId, questionKey])
1162
+ @@index([questionnairePlanId])
1163
+ @@map("questionnaire_plan_questions")
1164
+ }
1165
+
1026
1166
  // =============================================================================
1027
1167
  // PAYMENT PLAN DOMAIN - Reusable installment structure templates
1028
1168
  // =============================================================================
@@ -1142,8 +1282,14 @@ model PropertyPaymentMethodPhase {
1142
1282
  tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
1143
1283
  paymentMethodId String
1144
1284
  paymentMethod PropertyPaymentMethod @relation(fields: [paymentMethodId], references: [id], onDelete: Cascade)
1145
- paymentPlanId String? // Only for PAYMENT phases
1146
- paymentPlan PaymentPlan? @relation(fields: [paymentPlanId], references: [id])
1285
+
1286
+ // Plan references (only one should be set based on phaseCategory)
1287
+ paymentPlanId String? // Only for PAYMENT phases
1288
+ paymentPlan PaymentPlan? @relation(fields: [paymentPlanId], references: [id])
1289
+ documentationPlanId String? // Only for DOCUMENTATION phases
1290
+ documentationPlan DocumentationPlan? @relation(fields: [documentationPlanId], references: [id])
1291
+ questionnairePlanId String? // Only for QUESTIONNAIRE phases
1292
+ questionnairePlan QuestionnairePlan? @relation(fields: [questionnairePlanId], references: [id])
1147
1293
 
1148
1294
  name String
1149
1295
  description String? @db.Text
@@ -1168,13 +1314,14 @@ model PropertyPaymentMethodPhase {
1168
1314
  completionCriterion CompletionCriterion?
1169
1315
 
1170
1316
  // Snapshots for audit (original config at creation time)
1317
+ // These are still needed for inline definitions (backward compatibility)
1171
1318
  stepDefinitionsSnapshot Json?
1172
1319
  requiredDocumentSnapshot Json?
1173
1320
 
1174
1321
  createdAt DateTime @default(now())
1175
1322
  updatedAt DateTime @updatedAt
1176
1323
 
1177
- // Normalized child tables (for DOCUMENTATION phases)
1324
+ // Normalized child tables (for DOCUMENTATION phases - inline definitions)
1178
1325
  steps PaymentMethodPhaseStep[]
1179
1326
  requiredDocuments PaymentMethodPhaseDocument[]
1180
1327
  // Normalized child tables (for QUESTIONNAIRE phases)
@@ -1185,6 +1332,8 @@ model PropertyPaymentMethodPhase {
1185
1332
  @@index([tenantId])
1186
1333
  @@index([paymentMethodId])
1187
1334
  @@index([paymentPlanId])
1335
+ @@index([documentationPlanId])
1336
+ @@index([questionnairePlanId])
1188
1337
  @@index([phaseCategory])
1189
1338
  @@map("property_payment_method_phases")
1190
1339
  }
@@ -1318,6 +1467,44 @@ enum FieldType {
1318
1467
  FILE // File upload (single)
1319
1468
  }
1320
1469
 
1470
+ // =============================================================================
1471
+ // QUESTIONNAIRE PLAN ENUMS - For scoring and categorization
1472
+ // =============================================================================
1473
+
1474
+ enum QuestionType {
1475
+ TEXT
1476
+ NUMBER
1477
+ CURRENCY
1478
+ DATE
1479
+ SELECT
1480
+ MULTI_SELECT
1481
+ RADIO
1482
+ CHECKBOX
1483
+ FILE_UPLOAD
1484
+ PHONE
1485
+ EMAIL
1486
+ ADDRESS
1487
+ PERCENTAGE
1488
+ YEARS_MONTHS
1489
+ }
1490
+
1491
+ enum ScoringStrategy {
1492
+ SUM // Add up all scores
1493
+ AVERAGE // Average of all scores
1494
+ WEIGHTED_SUM // Sum with weights (score * weight)
1495
+ MIN_ALL // Must meet minimum on all questions
1496
+ CUSTOM // Use custom scoring function
1497
+ }
1498
+
1499
+ enum QuestionnaireCategory {
1500
+ PREQUALIFICATION // Initial eligibility screening
1501
+ AFFORDABILITY // Income/expense assessment
1502
+ PROPERTY_INTENT // What property are they looking for
1503
+ RISK_ASSESSMENT // Credit/risk questions
1504
+ COMPLIANCE // KYC/AML questions
1505
+ CUSTOM
1506
+ }
1507
+
1321
1508
  // Questionnaire field template within a QUESTIONNAIRE phase
1322
1509
  model PaymentMethodPhaseField {
1323
1510
  id String @id @default(cuid())
@@ -1575,10 +1762,20 @@ model QuestionnairePhase {
1575
1762
  phaseId String @unique
1576
1763
  phase ApplicationPhase @relation(fields: [phaseId], references: [id], onDelete: Cascade)
1577
1764
 
1765
+ // Questionnaire plan reference (if created from a plan)
1766
+ questionnairePlanId String?
1767
+ questionnairePlan QuestionnairePlan? @relation(fields: [questionnairePlanId], references: [id])
1768
+
1578
1769
  // Progress tracking
1579
1770
  completedFieldsCount Int @default(0)
1580
1771
  totalFieldsCount Int @default(0)
1581
1772
 
1773
+ // Scoring results (from QuestionnairePlan scoring)
1774
+ totalScore Int?
1775
+ passingScore Int? // Copied from plan at creation
1776
+ passed Boolean?
1777
+ scoredAt DateTime?
1778
+
1582
1779
  // Computed results (for UNDERWRITING phases)
1583
1780
  underwritingScore Float?
1584
1781
  debtToIncomeRatio Float?
@@ -1596,6 +1793,7 @@ model QuestionnairePhase {
1596
1793
 
1597
1794
  @@index([tenantId])
1598
1795
  @@index([phaseId])
1796
+ @@index([questionnairePlanId])
1599
1797
  @@map("questionnaire_phases")
1600
1798
  }
1601
1799
 
@@ -1612,6 +1810,10 @@ model DocumentationPhase {
1612
1810
  phaseId String @unique
1613
1811
  phase ApplicationPhase @relation(fields: [phaseId], references: [id], onDelete: Cascade)
1614
1812
 
1813
+ // Documentation plan reference (if created from a plan)
1814
+ documentationPlanId String?
1815
+ documentationPlan DocumentationPlan? @relation(fields: [documentationPlanId], references: [id])
1816
+
1615
1817
  // Current step pointer for UX and orchestration
1616
1818
  currentStepId String?
1617
1819
  currentStep DocumentationStep? @relation("CurrentStep", fields: [currentStepId], references: [id])