@valentine-efagene/qshelter-common 2.0.139 → 2.0.140

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.
@@ -18,10 +18,6 @@ export * from './DocumentReview';
18
18
  export * from './DocumentTemplate';
19
19
  export * from './DocumentationPhase';
20
20
  export * from './DocumentationPlan';
21
- export * from './DocumentationPlanStep';
22
- export * from './DocumentationStep';
23
- export * from './DocumentationStepApproval';
24
- export * from './DocumentationStepDocument';
25
21
  export * from './DomainEvent';
26
22
  export * from './EmailPreference';
27
23
  export * from './EventChannel';
@@ -18,10 +18,6 @@ export * from './DocumentReview';
18
18
  export * from './DocumentTemplate';
19
19
  export * from './DocumentationPhase';
20
20
  export * from './DocumentationPlan';
21
- export * from './DocumentationPlanStep';
22
- export * from './DocumentationStep';
23
- export * from './DocumentationStepApproval';
24
- export * from './DocumentationStepDocument';
25
21
  export * from './DomainEvent';
26
22
  export * from './EmailPreference';
27
23
  export * from './EventChannel';
@@ -28,7 +28,6 @@ export type * from './models/PropertyVariantMedia.js';
28
28
  export type * from './models/PropertyUnit.js';
29
29
  export type * from './models/PropertyAmenity.js';
30
30
  export type * from './models/DocumentationPlan.js';
31
- export type * from './models/DocumentationPlanStep.js';
32
31
  export type * from './models/DocumentDefinition.js';
33
32
  export type * from './models/ApprovalStage.js';
34
33
  export type * from './models/QuestionnairePlan.js';
@@ -50,9 +49,6 @@ export type * from './models/DocumentationPhase.js';
50
49
  export type * from './models/PaymentPhase.js';
51
50
  export type * from './models/QuestionnaireField.js';
52
51
  export type * from './models/ApplicationEvent.js';
53
- export type * from './models/DocumentationStep.js';
54
- export type * from './models/DocumentationStepDocument.js';
55
- export type * from './models/DocumentationStepApproval.js';
56
52
  export type * from './models/PaymentInstallment.js';
57
53
  export type * from './models/ApplicationPayment.js';
58
54
  export type * from './models/ApplicationDocument.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valentine-efagene/qshelter-common",
3
- "version": "2.0.139",
3
+ "version": "2.0.140",
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",
@@ -486,11 +486,10 @@ model User {
486
486
  soldApplications Application[] @relation("ApplicationSeller")
487
487
  applicationPayments ApplicationPayment[] @relation("ApplicationPayer")
488
488
 
489
- // Documentation step assignments and approvals
490
- assignedSteps DocumentationStep[] @relation("DocumentationStepAssignee")
491
- gateActedSteps DocumentationStep[] @relation("GateActedBy")
492
- stepApprovals DocumentationStepApproval[] @relation("DocumentationStepApprover")
493
- uploadedDocs ApplicationDocument[] @relation("DocumentUploader")
489
+ // Documentation (new model)
490
+ uploadedDocs ApplicationDocument[] @relation("DocumentUploader")
491
+ documentApprovals DocumentApproval[] @relation("DocumentApprovalReviewer")
492
+ completedStages ApprovalStageProgress[] @relation("StageCompletedBy")
494
493
 
495
494
  // Payment method changes
496
495
  paymentMethodChangeRequests PaymentMethodChangeRequest[] @relation("ChangeRequestor")
@@ -521,12 +520,6 @@ model User {
521
520
  // Document reviews by this user
522
521
  documentReviews DocumentReview[] @relation("DocumentReviewer")
523
522
 
524
- // NEW: Document approval trail entries by this user
525
- documentApprovals DocumentApproval[] @relation("DocumentApprovalReviewer")
526
-
527
- // NEW: Approval stages completed by this user
528
- completedStages ApprovalStageProgress[] @relation("StageCompletedBy")
529
-
530
523
  // Organization memberships (user can be employee of banks/developers)
531
524
  organizationMemberships OrganizationMember[]
532
525
 
@@ -795,12 +788,11 @@ model Tenant {
795
788
  paymentPhases PaymentPhase[]
796
789
  questionnaireFields QuestionnaireField[]
797
790
  applicationEvents ApplicationEvent[]
798
- documentationSteps DocumentationStep[]
799
- documentationStepDocuments DocumentationStepDocument[]
800
- documentationStepApprovals DocumentationStepApproval[]
801
791
  paymentInstallments PaymentInstallment[]
802
792
  applicationPayments ApplicationPayment[]
803
793
  applicationDocuments ApplicationDocument[]
794
+ documentApprovals DocumentApproval[]
795
+ approvalStageProgress ApprovalStageProgress[]
804
796
  propertyMedia PropertyMedia[]
805
797
  propertyDocuments PropertyDocument[]
806
798
  propertyVariants PropertyVariant[]
@@ -819,10 +811,6 @@ model Tenant {
819
811
  questionnairePlans QuestionnairePlan[]
820
812
  documentReviews DocumentReview[]
821
813
 
822
- // NEW: Approval stage progress and document approvals
823
- approvalStageProgress ApprovalStageProgress[]
824
- documentApprovals DocumentApproval[]
825
-
826
814
  // Organizations (Banks, Developers) operating on this tenant
827
815
  organizations Organization[]
828
816
 
@@ -1299,13 +1287,10 @@ model DocumentationPlan {
1299
1287
  createdAt DateTime @default(now())
1300
1288
  updatedAt DateTime @updatedAt
1301
1289
 
1302
- // Steps that make up this plan (DEPRECATED - use documentDefinitions + approvalStages)
1303
- steps DocumentationPlanStep[]
1304
-
1305
- // NEW: Document definitions (what documents to collect)
1290
+ // Document definitions (what documents to collect)
1306
1291
  documentDefinitions DocumentDefinition[]
1307
1292
 
1308
- // NEW: Approval stages (sequential workflow for reviewing documents)
1293
+ // Approval stages (sequential workflow for reviewing documents)
1309
1294
  approvalStages ApprovalStage[]
1310
1295
 
1311
1296
  // Used by property payment method phases (templates)
@@ -1318,70 +1303,6 @@ model DocumentationPlan {
1318
1303
  @@map("documentation_plans")
1319
1304
  }
1320
1305
 
1321
- // Step template within a DocumentationPlan
1322
- model DocumentationPlanStep {
1323
- id String @id @default(cuid())
1324
- planId String
1325
- plan DocumentationPlan @relation(fields: [planId], references: [id], onDelete: Cascade)
1326
-
1327
- name String
1328
- stepType StepType
1329
- order Int
1330
-
1331
- // Optional: which document type this step handles (for UPLOAD steps)
1332
- documentType String?
1333
- // Human-readable document name (e.g., "Valid ID Card" for ID_CARD)
1334
- // If not provided, step name can be auto-generated: "Upload ${documentName}"
1335
- documentName String?
1336
- metadata Json?
1337
-
1338
- // Document validation rules (for UPLOAD steps)
1339
- isRequired Boolean @default(true)
1340
- description String? @db.Text // Instructions for the user
1341
- maxSizeBytes Int? // Max file size allowed (e.g., 5242880 for 5MB)
1342
- allowedMimeTypes String? // CSV: application/pdf,image/jpeg,image/png
1343
- expiryDays Int? // Document must not be older than X days
1344
- requiresManualReview Boolean @default(false)
1345
- minFiles Int @default(1) // Minimum number of files required
1346
- maxFiles Int @default(1) // Maximum number of files allowed
1347
-
1348
- // Conditional logic - when is this step required?
1349
- // NULL = always required (unconditional)
1350
- // Examples:
1351
- // { "questionKey": "mortgage_type", "operator": "EQUALS", "value": "JOINT" }
1352
- // { "questionKey": "employment_status", "operator": "IN", "values": ["SELF_EMPLOYED", "BUSINESS_OWNER"] }
1353
- // { "all": [{ "questionKey": "has_spouse", "operator": "EQUALS", "value": "YES" }, { "questionKey": "spouse_employed", "operator": "EQUALS", "value": "YES" }] }
1354
- condition Json?
1355
-
1356
- // =========================================================================
1357
- // MULTI-PARTY REVIEW CONFIGURATION (for UPLOAD steps)
1358
- // =========================================================================
1359
- // Defines which parties must review documents uploaded in this step
1360
- // Format: [{ party: "INTERNAL", required: true }, { party: "BANK", required: true }]
1361
- // If null, defaults to single internal review (backward compatible)
1362
- reviewRequirements Json?
1363
-
1364
- // Review order: 'SEQUENTIAL' = parties review in order, 'PARALLEL' = all review simultaneously
1365
- reviewOrder String? // 'SEQUENTIAL' | 'PARALLEL'
1366
-
1367
- // =========================================================================
1368
- // GATE STEP CONFIGURATION (only applicable when stepType = GATE)
1369
- // =========================================================================
1370
- gateActor GateActor? // Who must perform the action
1371
- gateAction GateAction? // What action is required
1372
- gateRoleId String? // If gateActor = SPECIFIC_ROLE, which role
1373
- gateInstructions String? @db.Text // Instructions shown to actor
1374
- allowReject Boolean @default(true) // Can the actor reject?
1375
- rejectBehavior GateRejectBehavior? // What happens on reject
1376
- requiresComment Boolean @default(false) // Must actor provide a comment?
1377
-
1378
- createdAt DateTime @default(now())
1379
- updatedAt DateTime @updatedAt
1380
-
1381
- @@index([planId])
1382
- @@map("documentation_plan_steps")
1383
- }
1384
-
1385
1306
  // =============================================================================
1386
1307
  // DOCUMENT DEFINITION - What documents to collect (template)
1387
1308
  // =============================================================================
@@ -2235,7 +2156,7 @@ model QuestionnairePhase {
2235
2156
  // =============================================================================
2236
2157
  // DOCUMENTATION PHASE DATA - Extension for DOCUMENTATION phases
2237
2158
  // =============================================================================
2238
- // Manages document upload/approval workflow with FSM steps
2159
+ // Manages document upload/approval workflow with sequential approval stages
2239
2160
  // =============================================================================
2240
2161
 
2241
2162
  model DocumentationPhase {
@@ -2249,41 +2170,30 @@ model DocumentationPhase {
2249
2170
  documentationPlanId String?
2250
2171
  documentationPlan DocumentationPlan? @relation(fields: [documentationPlanId], references: [id])
2251
2172
 
2252
- // Source questionnaire for conditional step evaluation
2253
- // Links to the questionnaire phase whose answers determine which steps apply
2173
+ // Source questionnaire for conditional document evaluation
2174
+ // Links to the questionnaire phase whose answers determine which documents are required
2254
2175
  sourceQuestionnairePhaseId String?
2255
2176
  sourceQuestionnairePhase QuestionnairePhase? @relation("SourceQuestionnaire", fields: [sourceQuestionnairePhaseId], references: [id])
2256
2177
 
2257
- // Current step pointer for UX and orchestration
2258
- currentStepId String?
2259
- currentStep DocumentationStep? @relation("CurrentStep", fields: [currentStepId], references: [id])
2178
+ // Current approval stage pointer for UX and orchestration
2179
+ currentStageOrder Int @default(1)
2260
2180
 
2261
2181
  // Progress counters
2262
2182
  approvedDocumentsCount Int @default(0)
2263
2183
  requiredDocumentsCount Int @default(0)
2264
- completedStepsCount Int @default(0)
2265
- totalStepsCount Int @default(0)
2266
-
2267
- // Completion criteria
2268
- minimumCompletionPercentage Float?
2269
- completionCriterion CompletionCriterion?
2270
2184
 
2271
2185
  // Snapshots for audit
2272
- stepDefinitionsSnapshot Json?
2273
- requiredDocumentSnapshot Json?
2186
+ documentDefinitionsSnapshot Json?
2187
+ approvalStagesSnapshot Json?
2274
2188
 
2275
2189
  createdAt DateTime @default(now())
2276
2190
  updatedAt DateTime @updatedAt
2277
2191
 
2278
- // Child records
2279
- steps DocumentationStep[]
2280
-
2281
- // NEW: Approval stage progress (tracks which stages are completed)
2192
+ // Approval stage progress (tracks which stages are completed)
2282
2193
  stageProgress ApprovalStageProgress[]
2283
2194
 
2284
2195
  @@index([tenantId])
2285
2196
  @@index([phaseId])
2286
- @@index([currentStepId])
2287
2197
  @@index([sourceQuestionnairePhaseId])
2288
2198
  @@map("documentation_phases")
2289
2199
  }
@@ -2433,140 +2343,6 @@ model ApplicationEvent {
2433
2343
  @@map("application_events")
2434
2344
  }
2435
2345
 
2436
- // Steps within a DOCUMENTATION phase (FSM for document collection/approval)
2437
- model DocumentationStep {
2438
- id String @id @default(cuid())
2439
- tenantId String
2440
- tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
2441
- documentationPhaseId String
2442
- documentationPhase DocumentationPhase @relation(fields: [documentationPhaseId], references: [id], onDelete: Cascade)
2443
-
2444
- name String
2445
- // Human-readable document name (e.g., "Valid ID Card" for ID_CARD)
2446
- documentName String?
2447
- description String? @db.Text
2448
- stepType StepType
2449
- order Int
2450
-
2451
- status StepStatus @default(PENDING)
2452
-
2453
- // =========================================================================
2454
- // USER ACTION TRACKING - For rejection/resubmission flows
2455
- // =========================================================================
2456
- // When status is NEEDS_RESUBMISSION or ACTION_REQUIRED, this explains why.
2457
- // Populated from DocumentationStepApproval.comment on rejection.
2458
- actionReason String? @db.Text
2459
-
2460
- // Number of times this step has been submitted (for tracking resubmissions)
2461
- submissionCount Int @default(0)
2462
-
2463
- // Last submission timestamp (for tracking resubmission timing)
2464
- lastSubmittedAt DateTime?
2465
-
2466
- // Configuration metadata (for GENERATE_DOCUMENT steps, etc.)
2467
- metadata Json?
2468
-
2469
- // Document validation rules (copied from plan for UPLOAD steps)
2470
- requiresManualReview Boolean @default(false)
2471
-
2472
- // Conditional step logic (copied from plan)
2473
- // When set, this step is only applicable if the condition evaluates to true
2474
- // Format: { "questionKey": "mortgage_type", "operator": "EQUALS", "value": "JOINT" }
2475
- // Or: { "questionKey": "employment_status", "operator": "IN", "values": ["SELF_EMPLOYED", "BUSINESS_OWNER"] }
2476
- condition Json?
2477
-
2478
- // =========================================================================
2479
- // MULTI-PARTY REVIEW CONFIGURATION (for UPLOAD steps)
2480
- // =========================================================================
2481
- // Defines which parties must review documents uploaded in this step
2482
- // Format: [{ party: "INTERNAL", required: true }, { party: "BANK", required: true }]
2483
- // If null, defaults to single internal review (backward compatible)
2484
- reviewRequirements Json?
2485
-
2486
- // Review order: 'SEQUENTIAL' = parties review in order, 'PARALLEL' = all review simultaneously
2487
- reviewOrder String? // 'SEQUENTIAL' | 'PARALLEL'
2488
-
2489
- // Assignment
2490
- assigneeId String?
2491
- assignee User? @relation("DocumentationStepAssignee", fields: [assigneeId], references: [id])
2492
-
2493
- // Required document types for UPLOAD steps (normalized)
2494
- requiredDocuments DocumentationStepDocument[]
2495
-
2496
- // =========================================================================
2497
- // GATE STEP CONFIGURATION (only applicable when stepType = GATE)
2498
- // =========================================================================
2499
- gateActor GateActor? // Who must perform the action
2500
- gateAction GateAction? // What action is required
2501
- gateRoleId String? // If gateActor = SPECIFIC_ROLE, which role
2502
- gateInstructions String? @db.Text // Instructions shown to actor
2503
- allowReject Boolean @default(true) // Can the actor reject?
2504
- rejectBehavior GateRejectBehavior? // What happens on reject
2505
- requiresComment Boolean @default(false) // Must actor provide a comment?
2506
-
2507
- // Gate action tracking
2508
- gateActedAt DateTime? // When the gate action was performed
2509
- gateActedById String? // Who performed the gate action
2510
- gateActedBy User? @relation("GateActedBy", fields: [gateActedById], references: [id])
2511
- gateDecision String? // APPROVED, REJECTED, ACKNOWLEDGED, etc.
2512
- gateComment String? @db.Text // Comment from actor
2513
-
2514
- // Timing
2515
- dueDate DateTime?
2516
- completedAt DateTime?
2517
-
2518
- createdAt DateTime @default(now())
2519
- updatedAt DateTime @updatedAt
2520
-
2521
- approvals DocumentationStepApproval[]
2522
- currentForPhase DocumentationPhase[] @relation("CurrentStep")
2523
-
2524
- @@index([tenantId])
2525
- @@index([documentationPhaseId])
2526
- @@index([status])
2527
- @@index([order])
2528
- @@map("documentation_steps")
2529
- }
2530
-
2531
- // Required documents for a step (normalized from CSV)
2532
- model DocumentationStepDocument {
2533
- id String @id @default(cuid())
2534
- tenantId String
2535
- tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
2536
- stepId String
2537
- step DocumentationStep @relation(fields: [stepId], references: [id], onDelete: Cascade)
2538
-
2539
- documentType String
2540
- isRequired Boolean @default(true)
2541
-
2542
- createdAt DateTime @default(now())
2543
-
2544
- @@index([tenantId])
2545
- @@index([stepId, documentType])
2546
- @@map("documentation_step_documents")
2547
- }
2548
-
2549
- // Approvals for documentation steps
2550
- model DocumentationStepApproval {
2551
- id String @id @default(cuid())
2552
- tenantId String
2553
- tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
2554
- stepId String
2555
- step DocumentationStep @relation(fields: [stepId], references: [id], onDelete: Cascade)
2556
- approverId String?
2557
- approver User? @relation("DocumentationStepApprover", fields: [approverId], references: [id])
2558
-
2559
- decision ApprovalDecision
2560
- comment String? @db.Text
2561
- decidedAt DateTime @default(now())
2562
-
2563
- createdAt DateTime @default(now())
2564
-
2565
- @@index([tenantId])
2566
- @@index([stepId])
2567
- @@map("documentation_step_approvals")
2568
- }
2569
-
2570
2346
  // Installments within a PAYMENT phase
2571
2347
  model PaymentInstallment {
2572
2348
  id String @id @default(cuid())