@valentine-efagene/qshelter-common 2.0.72 → 2.0.74

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 (25) hide show
  1. package/dist/generated/client/browser.d.ts +10 -0
  2. package/dist/generated/client/client.d.ts +10 -0
  3. package/dist/generated/client/commonInputTypes.d.ts +150 -0
  4. package/dist/generated/client/enums.d.ts +35 -0
  5. package/dist/generated/client/enums.js +32 -1
  6. package/dist/generated/client/internal/class.d.ts +22 -0
  7. package/dist/generated/client/internal/class.js +2 -2
  8. package/dist/generated/client/internal/prismaNamespace.d.ts +227 -1
  9. package/dist/generated/client/internal/prismaNamespace.js +75 -3
  10. package/dist/generated/client/internal/prismaNamespaceBrowser.d.ts +76 -0
  11. package/dist/generated/client/internal/prismaNamespaceBrowser.js +75 -3
  12. package/dist/generated/client/models/ApprovalRequest.d.ts +2214 -0
  13. package/dist/generated/client/models/ApprovalRequest.js +1 -0
  14. package/dist/generated/client/models/Contract.d.ts +1522 -280
  15. package/dist/generated/client/models/PropertyTransferRequest.d.ts +2535 -0
  16. package/dist/generated/client/models/PropertyTransferRequest.js +1 -0
  17. package/dist/generated/client/models/PropertyUnit.d.ts +147 -0
  18. package/dist/generated/client/models/Tenant.d.ts +446 -0
  19. package/dist/generated/client/models/User.d.ts +1664 -23
  20. package/dist/generated/client/models.d.ts +2 -0
  21. package/package.json +1 -1
  22. package/prisma/migrations/20260106062140_add_step_event_attachments/migration.sql +22 -0
  23. package/prisma/migrations/20260107121844_add_property_transfer_requests/migration.sql +64 -0
  24. package/prisma/migrations/20260107172301_add_approval_request_model/migration.sql +46 -0
  25. package/prisma/schema.prisma +186 -0
@@ -51,4 +51,6 @@ export type * from './models/EventHandler.js';
51
51
  export type * from './models/WorkflowEvent.js';
52
52
  export type * from './models/EventHandlerExecution.js';
53
53
  export type * from './models/DomainEvent.js';
54
+ export type * from './models/PropertyTransferRequest.js';
55
+ export type * from './models/ApprovalRequest.js';
54
56
  export type * from './commonInputTypes.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valentine-efagene/qshelter-common",
3
- "version": "2.0.72",
3
+ "version": "2.0.74",
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,22 @@
1
+ -- CreateTable
2
+ CREATE TABLE `step_event_attachments` (
3
+ `id` VARCHAR(191) NOT NULL,
4
+ `stepId` VARCHAR(191) NOT NULL,
5
+ `trigger` ENUM('ON_COMPLETE', 'ON_REJECT', 'ON_SUBMIT', 'ON_RESUBMIT', 'ON_START') NOT NULL,
6
+ `handlerId` VARCHAR(191) NOT NULL,
7
+ `priority` INTEGER NOT NULL DEFAULT 100,
8
+ `enabled` BOOLEAN NOT NULL DEFAULT true,
9
+ `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
10
+ `updatedAt` DATETIME(3) NOT NULL,
11
+
12
+ INDEX `step_event_attachments_stepId_idx`(`stepId`),
13
+ INDEX `step_event_attachments_handlerId_idx`(`handlerId`),
14
+ UNIQUE INDEX `step_event_attachments_stepId_handlerId_trigger_key`(`stepId`, `handlerId`, `trigger`),
15
+ PRIMARY KEY (`id`)
16
+ ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
17
+
18
+ -- AddForeignKey
19
+ ALTER TABLE `step_event_attachments` ADD CONSTRAINT `step_event_attachments_stepId_fkey` FOREIGN KEY (`stepId`) REFERENCES `payment_method_phase_steps`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
20
+
21
+ -- AddForeignKey
22
+ ALTER TABLE `step_event_attachments` ADD CONSTRAINT `step_event_attachments_handlerId_fkey` FOREIGN KEY (`handlerId`) REFERENCES `event_handlers`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
@@ -0,0 +1,64 @@
1
+ /*
2
+ Warnings:
3
+
4
+ - A unique constraint covering the columns `[transferredFromId]` on the table `contracts` will be added. If there are existing duplicate values, this will fail.
5
+
6
+ */
7
+ -- AlterTable
8
+ ALTER TABLE `contracts` ADD COLUMN `transferredFromId` VARCHAR(191) NULL,
9
+ MODIFY `status` ENUM('DRAFT', 'PENDING', 'ACTIVE', 'COMPLETED', 'CANCELLED', 'TERMINATED', 'TRANSFERRED') NOT NULL DEFAULT 'DRAFT',
10
+ MODIFY `state` ENUM('DRAFT', 'PENDING', 'ACTIVE', 'COMPLETED', 'CANCELLED', 'TERMINATED', 'TRANSFERRED') NOT NULL DEFAULT 'DRAFT';
11
+
12
+ -- CreateTable
13
+ CREATE TABLE `property_transfer_requests` (
14
+ `id` VARCHAR(191) NOT NULL,
15
+ `tenantId` VARCHAR(191) NOT NULL,
16
+ `sourceContractId` VARCHAR(191) NOT NULL,
17
+ `targetPropertyUnitId` VARCHAR(191) NOT NULL,
18
+ `requestedById` VARCHAR(191) NOT NULL,
19
+ `reviewedById` VARCHAR(191) NULL,
20
+ `status` ENUM('PENDING', 'APPROVED', 'REJECTED', 'IN_PROGRESS', 'COMPLETED', 'FAILED') NOT NULL DEFAULT 'PENDING',
21
+ `reason` TEXT NULL,
22
+ `reviewNotes` TEXT NULL,
23
+ `priceAdjustmentHandling` VARCHAR(191) NULL,
24
+ `sourceTotalAmount` DOUBLE NULL,
25
+ `targetTotalAmount` DOUBLE NULL,
26
+ `priceAdjustment` DOUBLE NULL,
27
+ `paymentsMigrated` INTEGER NULL,
28
+ `targetContractId` VARCHAR(191) NULL,
29
+ `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
30
+ `reviewedAt` DATETIME(3) NULL,
31
+ `completedAt` DATETIME(3) NULL,
32
+ `updatedAt` DATETIME(3) NOT NULL,
33
+
34
+ INDEX `property_transfer_requests_tenantId_idx`(`tenantId`),
35
+ INDEX `property_transfer_requests_sourceContractId_idx`(`sourceContractId`),
36
+ INDEX `property_transfer_requests_targetPropertyUnitId_idx`(`targetPropertyUnitId`),
37
+ INDEX `property_transfer_requests_requestedById_idx`(`requestedById`),
38
+ INDEX `property_transfer_requests_status_idx`(`status`),
39
+ PRIMARY KEY (`id`)
40
+ ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
41
+
42
+ -- CreateIndex
43
+ CREATE UNIQUE INDEX `contracts_transferredFromId_key` ON `contracts`(`transferredFromId`);
44
+
45
+ -- AddForeignKey
46
+ ALTER TABLE `contracts` ADD CONSTRAINT `contracts_transferredFromId_fkey` FOREIGN KEY (`transferredFromId`) REFERENCES `contracts`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
47
+
48
+ -- AddForeignKey
49
+ ALTER TABLE `property_transfer_requests` ADD CONSTRAINT `property_transfer_requests_tenantId_fkey` FOREIGN KEY (`tenantId`) REFERENCES `tenants`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
50
+
51
+ -- AddForeignKey
52
+ ALTER TABLE `property_transfer_requests` ADD CONSTRAINT `property_transfer_requests_sourceContractId_fkey` FOREIGN KEY (`sourceContractId`) REFERENCES `contracts`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
53
+
54
+ -- AddForeignKey
55
+ ALTER TABLE `property_transfer_requests` ADD CONSTRAINT `property_transfer_requests_targetPropertyUnitId_fkey` FOREIGN KEY (`targetPropertyUnitId`) REFERENCES `property_units`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
56
+
57
+ -- AddForeignKey
58
+ ALTER TABLE `property_transfer_requests` ADD CONSTRAINT `property_transfer_requests_requestedById_fkey` FOREIGN KEY (`requestedById`) REFERENCES `users`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
59
+
60
+ -- AddForeignKey
61
+ ALTER TABLE `property_transfer_requests` ADD CONSTRAINT `property_transfer_requests_reviewedById_fkey` FOREIGN KEY (`reviewedById`) REFERENCES `users`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
62
+
63
+ -- AddForeignKey
64
+ ALTER TABLE `property_transfer_requests` ADD CONSTRAINT `property_transfer_requests_targetContractId_fkey` FOREIGN KEY (`targetContractId`) REFERENCES `contracts`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
@@ -0,0 +1,46 @@
1
+ -- CreateTable
2
+ CREATE TABLE `approval_requests` (
3
+ `id` VARCHAR(191) NOT NULL,
4
+ `tenantId` VARCHAR(191) NOT NULL,
5
+ `type` ENUM('PROPERTY_TRANSFER', 'PROPERTY_UPDATE', 'USER_WORKFLOW', 'CREDIT_CHECK', 'CONTRACT_TERMINATION', 'REFUND_APPROVAL') NOT NULL,
6
+ `status` ENUM('PENDING', 'IN_REVIEW', 'APPROVED', 'REJECTED', 'CANCELLED', 'EXPIRED') NOT NULL DEFAULT 'PENDING',
7
+ `priority` ENUM('LOW', 'NORMAL', 'HIGH', 'URGENT') NOT NULL DEFAULT 'NORMAL',
8
+ `entityType` VARCHAR(191) NOT NULL,
9
+ `entityId` VARCHAR(191) NOT NULL,
10
+ `title` VARCHAR(255) NOT NULL,
11
+ `description` TEXT NULL,
12
+ `payload` JSON NULL,
13
+ `requestedById` VARCHAR(191) NOT NULL,
14
+ `assigneeId` VARCHAR(191) NULL,
15
+ `reviewedById` VARCHAR(191) NULL,
16
+ `reviewNotes` TEXT NULL,
17
+ `decision` ENUM('APPROVED', 'REJECTED', 'REQUEST_CHANGES') NULL,
18
+ `expiresAt` DATETIME(3) NULL,
19
+ `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
20
+ `assignedAt` DATETIME(3) NULL,
21
+ `reviewedAt` DATETIME(3) NULL,
22
+ `completedAt` DATETIME(3) NULL,
23
+ `updatedAt` DATETIME(3) NOT NULL,
24
+
25
+ INDEX `approval_requests_tenantId_idx`(`tenantId`),
26
+ INDEX `approval_requests_type_idx`(`type`),
27
+ INDEX `approval_requests_status_idx`(`status`),
28
+ INDEX `approval_requests_priority_idx`(`priority`),
29
+ INDEX `approval_requests_entityType_entityId_idx`(`entityType`, `entityId`),
30
+ INDEX `approval_requests_requestedById_idx`(`requestedById`),
31
+ INDEX `approval_requests_assigneeId_idx`(`assigneeId`),
32
+ INDEX `approval_requests_createdAt_idx`(`createdAt`),
33
+ PRIMARY KEY (`id`)
34
+ ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
35
+
36
+ -- AddForeignKey
37
+ ALTER TABLE `approval_requests` ADD CONSTRAINT `approval_requests_tenantId_fkey` FOREIGN KEY (`tenantId`) REFERENCES `tenants`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
38
+
39
+ -- AddForeignKey
40
+ ALTER TABLE `approval_requests` ADD CONSTRAINT `approval_requests_requestedById_fkey` FOREIGN KEY (`requestedById`) REFERENCES `users`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
41
+
42
+ -- AddForeignKey
43
+ ALTER TABLE `approval_requests` ADD CONSTRAINT `approval_requests_assigneeId_fkey` FOREIGN KEY (`assigneeId`) REFERENCES `users`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
44
+
45
+ -- AddForeignKey
46
+ ALTER TABLE `approval_requests` ADD CONSTRAINT `approval_requests_reviewedById_fkey` FOREIGN KEY (`reviewedById`) REFERENCES `users`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
@@ -48,6 +48,16 @@ enum ContractStatus {
48
48
  COMPLETED
49
49
  CANCELLED
50
50
  TERMINATED
51
+ TRANSFERRED // Contract was transferred to a different property
52
+ }
53
+
54
+ enum TransferRequestStatus {
55
+ PENDING
56
+ APPROVED
57
+ REJECTED
58
+ IN_PROGRESS
59
+ COMPLETED
60
+ FAILED
51
61
  }
52
62
 
53
63
  enum PhaseStatus {
@@ -292,6 +302,15 @@ model User {
292
302
  offerLettersGenerated OfferLetter[] @relation("OfferLetterGenerator")
293
303
  offerLettersSent OfferLetter[] @relation("OfferLetterSender")
294
304
 
305
+ // Property transfer requests
306
+ transferRequestsSubmitted PropertyTransferRequest[] @relation("TransferRequestor")
307
+ transferRequestsReviewed PropertyTransferRequest[] @relation("TransferReviewer")
308
+
309
+ // Unified approval requests
310
+ approvalRequestsSubmitted ApprovalRequest[] @relation("ApprovalRequestor")
311
+ approvalRequestsAssigned ApprovalRequest[] @relation("ApprovalAssignee")
312
+ approvalRequestsReviewed ApprovalRequest[] @relation("ApprovalReviewer")
313
+
295
314
  @@index([email])
296
315
  @@index([tenantId])
297
316
  @@map("users")
@@ -381,6 +400,12 @@ model Tenant {
381
400
  eventHandlers EventHandler[]
382
401
  workflowEvents WorkflowEvent[]
383
402
 
403
+ // Property transfer requests
404
+ propertyTransferRequests PropertyTransferRequest[]
405
+
406
+ // Unified approval requests
407
+ approvalRequests ApprovalRequest[]
408
+
384
409
  @@index([subdomain])
385
410
  @@map("tenants")
386
411
  }
@@ -779,6 +804,9 @@ model PropertyUnit {
779
804
  // Relations
780
805
  contracts Contract[]
781
806
 
807
+ // Transfer requests targeting this unit
808
+ transferRequests PropertyTransferRequest[]
809
+
782
810
  @@unique([variantId, unitNumber])
783
811
  @@index([variantId])
784
812
  @@index([status])
@@ -1083,6 +1111,16 @@ model Contract {
1083
1111
  // Payment method change requests for this contract
1084
1112
  paymentMethodChangeRequests PaymentMethodChangeRequest[]
1085
1113
 
1114
+ // Transfer tracking - when a contract is transferred to a different property
1115
+ transferredFromId String? @unique // Source contract if this was created via transfer
1116
+ transferredFrom Contract? @relation("ContractTransfer", fields: [transferredFromId], references: [id])
1117
+ transferredTo Contract? @relation("ContractTransfer")
1118
+
1119
+ // Transfer requests where this contract is the source
1120
+ outgoingTransferRequests PropertyTransferRequest[] @relation("SourceContract")
1121
+ // Transfer requests where this contract is the target (created after approval)
1122
+ incomingTransferRequests PropertyTransferRequest[] @relation("TargetContract")
1123
+
1086
1124
  @@index([tenantId])
1087
1125
  @@index([propertyUnitId])
1088
1126
  @@index([buyerId])
@@ -1974,3 +2012,151 @@ model DomainEvent {
1974
2012
  @@index([occurredAt])
1975
2013
  @@map("domain_events")
1976
2014
  }
2015
+
2016
+ // =============================================================================
2017
+ // Property Transfer Request
2018
+ // =============================================================================
2019
+ // Allows a buyer to request transferring their contract to a different property
2020
+ // while preserving payments, completed workflow steps, and progress.
2021
+ // =============================================================================
2022
+
2023
+ model PropertyTransferRequest {
2024
+ id String @id @default(cuid())
2025
+ tenantId String
2026
+ tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
2027
+
2028
+ // Source contract being transferred
2029
+ sourceContractId String
2030
+ sourceContract Contract @relation("SourceContract", fields: [sourceContractId], references: [id], onDelete: Cascade)
2031
+
2032
+ // Target property unit
2033
+ targetPropertyUnitId String
2034
+ targetPropertyUnit PropertyUnit @relation(fields: [targetPropertyUnitId], references: [id])
2035
+
2036
+ // Requestor (buyer) and reviewer (admin)
2037
+ requestedById String
2038
+ requestedBy User @relation("TransferRequestor", fields: [requestedById], references: [id])
2039
+ reviewedById String?
2040
+ reviewedBy User? @relation("TransferReviewer", fields: [reviewedById], references: [id])
2041
+
2042
+ // Status and workflow
2043
+ status TransferRequestStatus @default(PENDING)
2044
+
2045
+ // Request details
2046
+ reason String? @db.Text // Buyer's reason for transfer
2047
+
2048
+ // Review details
2049
+ reviewNotes String? @db.Text // Admin notes on decision
2050
+ priceAdjustmentHandling String? // How to handle price difference: ADD_TO_MORTGAGE, REQUIRE_PAYMENT, CREDIT_BUYER
2051
+
2052
+ // Computed values
2053
+ sourceTotalAmount Float? // Original contract total
2054
+ targetTotalAmount Float? // New contract total (based on target property)
2055
+ priceAdjustment Float? // Difference (positive = buyer owes more)
2056
+ paymentsMigrated Int? // Number of payments migrated
2057
+
2058
+ // Result - new contract created after approval
2059
+ targetContractId String?
2060
+ targetContract Contract? @relation("TargetContract", fields: [targetContractId], references: [id])
2061
+
2062
+ // Timestamps
2063
+ createdAt DateTime @default(now())
2064
+ reviewedAt DateTime?
2065
+ completedAt DateTime?
2066
+ updatedAt DateTime @updatedAt
2067
+
2068
+ @@index([tenantId])
2069
+ @@index([sourceContractId])
2070
+ @@index([targetPropertyUnitId])
2071
+ @@index([requestedById])
2072
+ @@index([status])
2073
+ @@map("property_transfer_requests")
2074
+ }
2075
+
2076
+ // =============================================================================
2077
+ // UNIFIED APPROVAL REQUESTS
2078
+ // =============================================================================
2079
+
2080
+ enum ApprovalRequestType {
2081
+ PROPERTY_TRANSFER // Property unit transfer between contracts
2082
+ PROPERTY_UPDATE // Property/unit listing update requiring approval
2083
+ USER_WORKFLOW // User workflow step approval
2084
+ CREDIT_CHECK // Credit check result review
2085
+ CONTRACT_TERMINATION // Contract termination approval
2086
+ REFUND_APPROVAL // Refund request approval
2087
+ }
2088
+
2089
+ enum ApprovalRequestStatus {
2090
+ PENDING // Awaiting review
2091
+ IN_REVIEW // Assigned to reviewer
2092
+ APPROVED // Approved by reviewer
2093
+ REJECTED // Rejected by reviewer
2094
+ CANCELLED // Cancelled by requestor
2095
+ EXPIRED // Auto-expired (if TTL configured)
2096
+ }
2097
+
2098
+ enum ApprovalRequestPriority {
2099
+ LOW
2100
+ NORMAL
2101
+ HIGH
2102
+ URGENT
2103
+ }
2104
+
2105
+ // Polymorphic approval request model for unified admin dashboard
2106
+ model ApprovalRequest {
2107
+ id String @id @default(cuid())
2108
+ tenantId String
2109
+ tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
2110
+
2111
+ // Request type and status
2112
+ type ApprovalRequestType
2113
+ status ApprovalRequestStatus @default(PENDING)
2114
+ priority ApprovalRequestPriority @default(NORMAL)
2115
+
2116
+ // Polymorphic reference to the entity requiring approval
2117
+ entityType String // e.g., "PropertyTransferRequest", "PropertyUnit", "User"
2118
+ entityId String // ID of the referenced entity
2119
+
2120
+ // Request metadata
2121
+ title String @db.VarChar(255) // Human-readable title for the request
2122
+ description String? @db.Text // Detailed description
2123
+
2124
+ // Payload for any additional context (JSON)
2125
+ payload Json? // Flexible data storage for type-specific details
2126
+
2127
+ // Requestor - who created the request
2128
+ requestedById String
2129
+ requestedBy User @relation("ApprovalRequestor", fields: [requestedById], references: [id])
2130
+
2131
+ // Assignee - admin/reviewer assigned to handle this request
2132
+ assigneeId String?
2133
+ assignee User? @relation("ApprovalAssignee", fields: [assigneeId], references: [id])
2134
+
2135
+ // Reviewer - who made the final decision (may differ from assignee)
2136
+ reviewedById String?
2137
+ reviewedBy User? @relation("ApprovalReviewer", fields: [reviewedById], references: [id])
2138
+
2139
+ // Review details
2140
+ reviewNotes String? @db.Text // Reviewer's notes/comments
2141
+ decision ApprovalDecision? // APPROVED, REJECTED, REQUEST_CHANGES
2142
+
2143
+ // Expiration
2144
+ expiresAt DateTime? // Optional TTL for auto-expiration
2145
+
2146
+ // Timestamps
2147
+ createdAt DateTime @default(now())
2148
+ assignedAt DateTime? // When assigned to reviewer
2149
+ reviewedAt DateTime? // When decision was made
2150
+ completedAt DateTime? // When fully processed
2151
+ updatedAt DateTime @updatedAt
2152
+
2153
+ @@index([tenantId])
2154
+ @@index([type])
2155
+ @@index([status])
2156
+ @@index([priority])
2157
+ @@index([entityType, entityId])
2158
+ @@index([requestedById])
2159
+ @@index([assigneeId])
2160
+ @@index([createdAt])
2161
+ @@map("approval_requests")
2162
+ }