@valentine-efagene/qshelter-common 2.0.60 → 2.0.61
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.
- package/dist/src/prisma/tenant.js +33 -28
- package/package.json +1 -1
|
@@ -1,42 +1,47 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* INVERTED APPROACH: All models are tenant-scoped by default.
|
|
3
|
+
* Only list models that are explicitly GLOBAL (no tenant scoping).
|
|
3
4
|
*
|
|
4
|
-
*
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
* Models
|
|
8
|
-
*
|
|
5
|
+
* This reduces the risk of accidentally omitting a new model from tenant scoping.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Models that are intentionally GLOBAL and should NOT be tenant-scoped.
|
|
9
|
+
* These models either:
|
|
10
|
+
* - Don't have a tenantId field (system tables)
|
|
11
|
+
* - Have optional tenantId but are designed to work across tenants (User)
|
|
9
12
|
*/
|
|
10
|
-
const
|
|
11
|
-
//
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
// Prequalification & underwriting domain
|
|
24
|
-
"prequalification",
|
|
25
|
-
"underwritingDecision",
|
|
26
|
-
// Payment method changes
|
|
27
|
-
"paymentMethodChangeRequest",
|
|
13
|
+
const GLOBAL_MODELS = [
|
|
14
|
+
// User can exist across tenants or without a tenant
|
|
15
|
+
"user",
|
|
16
|
+
// System/infrastructure tables without tenantId
|
|
17
|
+
"tenant",
|
|
18
|
+
"role",
|
|
19
|
+
"permission",
|
|
20
|
+
"rolePermission",
|
|
21
|
+
"userRole",
|
|
22
|
+
"refreshToken",
|
|
23
|
+
"passwordReset",
|
|
24
|
+
"wallet",
|
|
25
|
+
"domainEvent",
|
|
28
26
|
];
|
|
29
27
|
/**
|
|
30
|
-
* Models that
|
|
31
|
-
*
|
|
28
|
+
* Models that have OPTIONAL tenant scoping (nullable tenantId).
|
|
29
|
+
* These can be global templates (tenantId = null) or tenant-specific.
|
|
30
|
+
* Queries will return both global AND tenant-specific records.
|
|
32
31
|
*/
|
|
33
32
|
const OPTIONAL_TENANT_MODELS = ["paymentPlan"];
|
|
34
|
-
function
|
|
35
|
-
return
|
|
33
|
+
function isGlobalModel(model) {
|
|
34
|
+
return GLOBAL_MODELS.includes(model);
|
|
36
35
|
}
|
|
37
36
|
function isOptionalTenantModel(model) {
|
|
38
37
|
return OPTIONAL_TENANT_MODELS.includes(model);
|
|
39
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* A model is tenant-scoped by default unless explicitly listed as global.
|
|
41
|
+
*/
|
|
42
|
+
function isTenantScopedModel(model) {
|
|
43
|
+
return !isGlobalModel(model);
|
|
44
|
+
}
|
|
40
45
|
/**
|
|
41
46
|
* Creates a tenant-scoped Prisma client that automatically:
|
|
42
47
|
* 1. Filters all queries on tenant-scoped models by tenantId
|
package/package.json
CHANGED