@valentine-efagene/qshelter-common 2.0.73 → 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.
@@ -52,4 +52,5 @@ export type * from './models/WorkflowEvent.js';
52
52
  export type * from './models/EventHandlerExecution.js';
53
53
  export type * from './models/DomainEvent.js';
54
54
  export type * from './models/PropertyTransferRequest.js';
55
+ export type * from './models/ApprovalRequest.js';
55
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.73",
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,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;
@@ -306,6 +306,11 @@ model User {
306
306
  transferRequestsSubmitted PropertyTransferRequest[] @relation("TransferRequestor")
307
307
  transferRequestsReviewed PropertyTransferRequest[] @relation("TransferReviewer")
308
308
 
309
+ // Unified approval requests
310
+ approvalRequestsSubmitted ApprovalRequest[] @relation("ApprovalRequestor")
311
+ approvalRequestsAssigned ApprovalRequest[] @relation("ApprovalAssignee")
312
+ approvalRequestsReviewed ApprovalRequest[] @relation("ApprovalReviewer")
313
+
309
314
  @@index([email])
310
315
  @@index([tenantId])
311
316
  @@map("users")
@@ -398,6 +403,9 @@ model Tenant {
398
403
  // Property transfer requests
399
404
  propertyTransferRequests PropertyTransferRequest[]
400
405
 
406
+ // Unified approval requests
407
+ approvalRequests ApprovalRequest[]
408
+
401
409
  @@index([subdomain])
402
410
  @@map("tenants")
403
411
  }
@@ -2064,3 +2072,91 @@ model PropertyTransferRequest {
2064
2072
  @@index([status])
2065
2073
  @@map("property_transfer_requests")
2066
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
+ }