@nathapp/nestjs-account-prisma 0.0.0-stage → 1.1.0
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/README.md +149 -2
- package/dist/account-prisma.module.d.ts +7 -0
- package/dist/account-prisma.module.js +78 -0
- package/dist/account-prisma.module.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +45 -0
- package/dist/index.js.map +1 -0
- package/dist/prisma-account.repository.d.ts +24 -0
- package/dist/prisma-account.repository.js +99 -0
- package/dist/prisma-account.repository.js.map +1 -0
- package/dist/prisma-audit-log.repository.d.ts +41 -0
- package/dist/prisma-audit-log.repository.js +153 -0
- package/dist/prisma-audit-log.repository.js.map +1 -0
- package/dist/prisma-invitation.repository.d.ts +41 -0
- package/dist/prisma-invitation.repository.js +138 -0
- package/dist/prisma-invitation.repository.js.map +1 -0
- package/dist/prisma-membership-role.repository.d.ts +11 -0
- package/dist/prisma-membership-role.repository.js +80 -0
- package/dist/prisma-membership-role.repository.js.map +1 -0
- package/dist/prisma-membership.repository.d.ts +24 -0
- package/dist/prisma-membership.repository.js +75 -0
- package/dist/prisma-membership.repository.js.map +1 -0
- package/dist/prisma-model.types.d.ts +46 -0
- package/dist/prisma-model.types.js +20 -0
- package/dist/prisma-model.types.js.map +1 -0
- package/dist/prisma-onboarding-flow.repository.d.ts +23 -0
- package/dist/prisma-onboarding-flow.repository.js +75 -0
- package/dist/prisma-onboarding-flow.repository.js.map +1 -0
- package/dist/prisma-onboarding-progress.repository.d.ts +22 -0
- package/dist/prisma-onboarding-progress.repository.js +84 -0
- package/dist/prisma-onboarding-progress.repository.js.map +1 -0
- package/dist/prisma-ownership-transfer.repository.d.ts +33 -0
- package/dist/prisma-ownership-transfer.repository.js +95 -0
- package/dist/prisma-ownership-transfer.repository.js.map +1 -0
- package/dist/prisma-permission.repository.d.ts +14 -0
- package/dist/prisma-permission.repository.js +86 -0
- package/dist/prisma-permission.repository.js.map +1 -0
- package/dist/prisma-profile.repository.d.ts +23 -0
- package/dist/prisma-profile.repository.js +80 -0
- package/dist/prisma-profile.repository.js.map +1 -0
- package/dist/prisma-provider.d.ts +5 -0
- package/dist/prisma-provider.js +8 -0
- package/dist/prisma-provider.js.map +1 -0
- package/dist/prisma-role.repository.d.ts +27 -0
- package/dist/prisma-role.repository.js +109 -0
- package/dist/prisma-role.repository.js.map +1 -0
- package/dist/prisma-tenant-app.repository.d.ts +18 -0
- package/dist/prisma-tenant-app.repository.js +68 -0
- package/dist/prisma-tenant-app.repository.js.map +1 -0
- package/package.json +39 -4
- package/prisma/account.prisma +261 -0
- package/prisma/migrations/20260714_ownership_transfer_pending_unique/migration.mysql.sql +9 -0
- package/prisma/migrations/20260714_ownership_transfer_pending_unique/migration.sql +4 -0
- package/prisma/sql/long-text-columns.mysql.sql +13 -0
package/README.md
CHANGED
|
@@ -1,3 +1,150 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @nathapp/nestjs-account-prisma
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Prisma adapter for `@nathapp/nestjs-account`. Binds the core package's repository
|
|
4
|
+
tokens to `AbstractPrismaRepository`-based implementations.
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```shell
|
|
9
|
+
npm i @nathapp/nestjs-account-prisma
|
|
10
|
+
npm i -D prisma && npx prisma init
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Schema
|
|
14
|
+
|
|
15
|
+
Append the 13 models from the packaged fragment
|
|
16
|
+
`node_modules/@nathapp/nestjs-account-prisma/prisma/account.prisma` to your app's
|
|
17
|
+
`schema.prisma`. The fragment carries no `datasource` or `generator` block — it
|
|
18
|
+
is models only. Every `DateTime` in it uses `@db.Timestamptz(6)` (PostgreSQL
|
|
19
|
+
`timestamptz`); bare `DateTime` is not supported.
|
|
20
|
+
|
|
21
|
+
**PostgreSQL and MySQL.** The fragment is authored for PostgreSQL 16 and also
|
|
22
|
+
supports MySQL 8.0. For MySQL, assemble it with `@db.Timestamptz(6)` rewritten
|
|
23
|
+
to `@db.DateTime(6)` (the only change; see the `@nathapp/nestjs-iam-prisma`
|
|
24
|
+
README, "Schema assembly and database support") and keep the MySQL server and
|
|
25
|
+
sessions on UTC (`time_zone = '+00:00'`), because `DATETIME(6)` stores no
|
|
26
|
+
timezone. Upgrading a MySQL database built from an earlier fragment: apply
|
|
27
|
+
`prisma/sql/long-text-columns.mysql.sql` (PostgreSQL needs nothing). Each
|
|
28
|
+
packaged migration has a `migration.mysql.sql` twin next to its `migration.sql`;
|
|
29
|
+
on MySQL the single-pending-transfer guard is a functional unique index.
|
|
30
|
+
|
|
31
|
+
Two of the models are join tables (`RolePermission`, `MembershipRole`) that exist
|
|
32
|
+
to support the `ROLE_REPOSITORY` and `MEMBERSHIP_ROLE_REPOSITORY` bindings.
|
|
33
|
+
|
|
34
|
+
`prisma/migrations/` in this package holds one incremental patch,
|
|
35
|
+
`20260714_ownership_transfer_pending_unique`, which adds a partial unique index
|
|
36
|
+
enforcing a single pending ownership transfer per account:
|
|
37
|
+
|
|
38
|
+
```sql
|
|
39
|
+
CREATE UNIQUE INDEX ownership_transfers_one_pending_per_account
|
|
40
|
+
ON ownership_transfers (account_id)
|
|
41
|
+
WHERE status = 1;
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
It is a delta, not a complete initial migration set, and Prisma will not apply it
|
|
45
|
+
for you — the consumer's migration history lives in the consumer's own project.
|
|
46
|
+
Apply it by hand when upgrading an existing database, after
|
|
47
|
+
`prisma migrate dev` has produced your own migration from the fragment.
|
|
48
|
+
|
|
49
|
+
## Register
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
import { Module } from '@nestjs/common';
|
|
53
|
+
import { PrismaPg } from '@prisma/adapter-pg'; // MySQL: PrismaMariaDb from '@prisma/adapter-mariadb' (host/port/user/password/database, no connectionString)
|
|
54
|
+
import { PrismaClient } from './generated/prisma/client'; // your generator `output`
|
|
55
|
+
import { PrismaModule } from '@nathapp/nestjs-prisma';
|
|
56
|
+
import { AccountPrismaModule } from '@nathapp/nestjs-account-prisma';
|
|
57
|
+
|
|
58
|
+
@Module({
|
|
59
|
+
imports: [
|
|
60
|
+
PrismaModule.forRoot({
|
|
61
|
+
client: PrismaClient,
|
|
62
|
+
clientOptions: { adapter: new PrismaPg({ connectionString: process.env.DATABASE_URL! }) },
|
|
63
|
+
transaction: true,
|
|
64
|
+
}),
|
|
65
|
+
AccountPrismaModule.register(),
|
|
66
|
+
],
|
|
67
|
+
})
|
|
68
|
+
export class AppModule {}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
`register()` takes an optional options object:
|
|
72
|
+
|
|
73
|
+
| Option | Type | Default | Meaning |
|
|
74
|
+
|---|---|---|---|
|
|
75
|
+
| `global` | `boolean` | `true` | Register as a global module so the repository tokens resolve anywhere. |
|
|
76
|
+
|
|
77
|
+
`register()` is the only import form for this adapter. There is no `registerAsync`.
|
|
78
|
+
|
|
79
|
+
### If you already wrap this adapter in `@Global()`
|
|
80
|
+
|
|
81
|
+
Pass `global: false`. Otherwise the adapter's own global exports are injected
|
|
82
|
+
**in addition to** your override, and last-registration-wins silently decides
|
|
83
|
+
which implementation is used:
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
import { Global, Module } from '@nestjs/common';
|
|
87
|
+
import { ACCOUNT_REPOSITORY } from '@nathapp/nestjs-account';
|
|
88
|
+
import { AccountPrismaModule } from '@nathapp/nestjs-account-prisma';
|
|
89
|
+
import { SoftDeleteAccountRepository } from './soft-delete-account.repository';
|
|
90
|
+
|
|
91
|
+
@Global()
|
|
92
|
+
@Module({
|
|
93
|
+
imports: [AccountPrismaModule.register({ global: false })],
|
|
94
|
+
providers: [{ provide: ACCOUNT_REPOSITORY, useClass: SoftDeleteAccountRepository }],
|
|
95
|
+
exports: [ACCOUNT_REPOSITORY],
|
|
96
|
+
})
|
|
97
|
+
export class PrismaOverridesModule {}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
`global: false` only helps if the adapter is registered once. A second, global
|
|
101
|
+
`register()` elsewhere in the app keeps its global exports, and `global: false`
|
|
102
|
+
here does not remove them — so the collision this section exists to prevent is
|
|
103
|
+
still there. Register the adapter in exactly one place.
|
|
104
|
+
|
|
105
|
+
The `global` option carries no documentation in the published type definitions
|
|
106
|
+
(`removeComments: true` strips the JSDoc from the emitted `.d.ts`), so this README
|
|
107
|
+
is where it is described. The options object is typed as `PrismaAdapterModuleOptions`,
|
|
108
|
+
which is exported from this package if you need to name the type.
|
|
109
|
+
|
|
110
|
+
## Transactions
|
|
111
|
+
|
|
112
|
+
Multi-write flows need `PrismaModule.forRoot({ client: PrismaClient, transaction: true })`
|
|
113
|
+
with `PrismaClient` imported from your generated client (Prisma 7 `prisma-client` generator).
|
|
114
|
+
Every repository resolves its client per operation from the `TRANSACTION_MANAGER`
|
|
115
|
+
token, and the two `PrismaModule` registration paths fail differently when
|
|
116
|
+
`transaction` is omitted:
|
|
117
|
+
|
|
118
|
+
- `PrismaModule.forRoot()` binds `TRANSACTION_MANAGER` only when `transaction: true`
|
|
119
|
+
is set. Without it nothing is bound, the repositories cannot resolve their
|
|
120
|
+
dependency, and Nest fails at boot.
|
|
121
|
+
- `PrismaModule.forRootAsync()` always binds the token, but with a manager whose
|
|
122
|
+
`run()` and `getClient()` throw and whose `isInTransaction()` returns `false`, so
|
|
123
|
+
the app boots and fails on first use instead.
|
|
124
|
+
|
|
125
|
+
Neither path is a silent passthrough: a real transaction manager either joins the
|
|
126
|
+
transaction already in scope or opens a Prisma interactive transaction.
|
|
127
|
+
|
|
128
|
+
Both of those are `PrismaModule` from `@nathapp/nestjs-prisma`. These adapters
|
|
129
|
+
expose only the synchronous `register()`; they have no `registerAsync`.
|
|
130
|
+
|
|
131
|
+
## Tokens bound
|
|
132
|
+
|
|
133
|
+
| Token | Implementation |
|
|
134
|
+
|---|---|
|
|
135
|
+
| `ACCOUNT_REPOSITORY` | `PrismaAccountRepository` |
|
|
136
|
+
| `MEMBERSHIP_REPOSITORY` | `PrismaMembershipRepository` |
|
|
137
|
+
| `ROLE_REPOSITORY` | `PrismaRoleRepository` |
|
|
138
|
+
| `PERMISSION_REPOSITORY` | `PrismaPermissionRepository` |
|
|
139
|
+
| `INVITATION_REPOSITORY` | `PrismaInvitationRepository` |
|
|
140
|
+
| `PROFILE_REPOSITORY` | `PrismaProfileRepository` |
|
|
141
|
+
| `ONBOARDING_FLOW_REPOSITORY` | `PrismaOnboardingFlowRepository` |
|
|
142
|
+
| `ONBOARDING_PROGRESS_REPOSITORY` | `PrismaOnboardingProgressRepository` |
|
|
143
|
+
| `TENANT_APP_REPOSITORY` | `PrismaTenantAppRepository` |
|
|
144
|
+
| `MEMBERSHIP_ROLE_REPOSITORY` | `PrismaMembershipRoleRepository` |
|
|
145
|
+
| `AUDIT_LOG_REPOSITORY` | `PrismaAuditLogRepository` |
|
|
146
|
+
| `OWNERSHIP_TRANSFER_REPOSITORY` | `PrismaOwnershipTransferRepository` |
|
|
147
|
+
|
|
148
|
+
Onboarding is split across two tokens — `ONBOARDING_FLOW_REPOSITORY` for flow
|
|
149
|
+
definitions and `ONBOARDING_PROGRESS_REPOSITORY` for per-account progress — not
|
|
150
|
+
one combined token.
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var AccountPrismaModule_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.AccountPrismaModule = void 0;
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const nestjs_account_1 = require("@nathapp/nestjs-account");
|
|
13
|
+
const prisma_account_repository_1 = require("./prisma-account.repository");
|
|
14
|
+
const prisma_membership_repository_1 = require("./prisma-membership.repository");
|
|
15
|
+
const prisma_role_repository_1 = require("./prisma-role.repository");
|
|
16
|
+
const prisma_permission_repository_1 = require("./prisma-permission.repository");
|
|
17
|
+
const prisma_invitation_repository_1 = require("./prisma-invitation.repository");
|
|
18
|
+
const prisma_profile_repository_1 = require("./prisma-profile.repository");
|
|
19
|
+
const prisma_onboarding_flow_repository_1 = require("./prisma-onboarding-flow.repository");
|
|
20
|
+
const prisma_onboarding_progress_repository_1 = require("./prisma-onboarding-progress.repository");
|
|
21
|
+
const prisma_tenant_app_repository_1 = require("./prisma-tenant-app.repository");
|
|
22
|
+
const prisma_membership_role_repository_1 = require("./prisma-membership-role.repository");
|
|
23
|
+
const prisma_audit_log_repository_1 = require("./prisma-audit-log.repository");
|
|
24
|
+
const prisma_ownership_transfer_repository_1 = require("./prisma-ownership-transfer.repository");
|
|
25
|
+
let AccountPrismaModule = AccountPrismaModule_1 = class AccountPrismaModule {
|
|
26
|
+
static register(options) {
|
|
27
|
+
var _a;
|
|
28
|
+
return {
|
|
29
|
+
module: AccountPrismaModule_1,
|
|
30
|
+
global: (_a = options === null || options === void 0 ? void 0 : options.global) !== null && _a !== void 0 ? _a : true,
|
|
31
|
+
providers: [
|
|
32
|
+
prisma_account_repository_1.PrismaAccountRepository,
|
|
33
|
+
{ provide: nestjs_account_1.ACCOUNT_REPOSITORY, useExisting: prisma_account_repository_1.PrismaAccountRepository },
|
|
34
|
+
prisma_membership_repository_1.PrismaMembershipRepository,
|
|
35
|
+
{ provide: nestjs_account_1.MEMBERSHIP_REPOSITORY, useExisting: prisma_membership_repository_1.PrismaMembershipRepository },
|
|
36
|
+
prisma_role_repository_1.PrismaRoleRepository,
|
|
37
|
+
{ provide: nestjs_account_1.ROLE_REPOSITORY, useExisting: prisma_role_repository_1.PrismaRoleRepository },
|
|
38
|
+
prisma_permission_repository_1.PrismaPermissionRepository,
|
|
39
|
+
{ provide: nestjs_account_1.PERMISSION_REPOSITORY, useExisting: prisma_permission_repository_1.PrismaPermissionRepository },
|
|
40
|
+
prisma_invitation_repository_1.PrismaInvitationRepository,
|
|
41
|
+
{ provide: nestjs_account_1.INVITATION_REPOSITORY, useExisting: prisma_invitation_repository_1.PrismaInvitationRepository },
|
|
42
|
+
prisma_profile_repository_1.PrismaProfileRepository,
|
|
43
|
+
{ provide: nestjs_account_1.PROFILE_REPOSITORY, useExisting: prisma_profile_repository_1.PrismaProfileRepository },
|
|
44
|
+
prisma_onboarding_flow_repository_1.PrismaOnboardingFlowRepository,
|
|
45
|
+
{ provide: nestjs_account_1.ONBOARDING_FLOW_REPOSITORY, useExisting: prisma_onboarding_flow_repository_1.PrismaOnboardingFlowRepository },
|
|
46
|
+
prisma_onboarding_progress_repository_1.PrismaOnboardingProgressRepository,
|
|
47
|
+
{ provide: nestjs_account_1.ONBOARDING_PROGRESS_REPOSITORY, useExisting: prisma_onboarding_progress_repository_1.PrismaOnboardingProgressRepository },
|
|
48
|
+
prisma_tenant_app_repository_1.PrismaTenantAppRepository,
|
|
49
|
+
{ provide: nestjs_account_1.TENANT_APP_REPOSITORY, useExisting: prisma_tenant_app_repository_1.PrismaTenantAppRepository },
|
|
50
|
+
prisma_membership_role_repository_1.PrismaMembershipRoleRepository,
|
|
51
|
+
{ provide: nestjs_account_1.MEMBERSHIP_ROLE_REPOSITORY, useExisting: prisma_membership_role_repository_1.PrismaMembershipRoleRepository },
|
|
52
|
+
prisma_audit_log_repository_1.PrismaAuditLogRepository,
|
|
53
|
+
{ provide: nestjs_account_1.AUDIT_LOG_REPOSITORY, useExisting: prisma_audit_log_repository_1.PrismaAuditLogRepository },
|
|
54
|
+
prisma_ownership_transfer_repository_1.PrismaOwnershipTransferRepository,
|
|
55
|
+
{ provide: nestjs_account_1.OWNERSHIP_TRANSFER_REPOSITORY, useExisting: prisma_ownership_transfer_repository_1.PrismaOwnershipTransferRepository },
|
|
56
|
+
],
|
|
57
|
+
exports: [
|
|
58
|
+
nestjs_account_1.ACCOUNT_REPOSITORY,
|
|
59
|
+
nestjs_account_1.MEMBERSHIP_REPOSITORY,
|
|
60
|
+
nestjs_account_1.ROLE_REPOSITORY,
|
|
61
|
+
nestjs_account_1.PERMISSION_REPOSITORY,
|
|
62
|
+
nestjs_account_1.INVITATION_REPOSITORY,
|
|
63
|
+
nestjs_account_1.PROFILE_REPOSITORY,
|
|
64
|
+
nestjs_account_1.ONBOARDING_FLOW_REPOSITORY,
|
|
65
|
+
nestjs_account_1.ONBOARDING_PROGRESS_REPOSITORY,
|
|
66
|
+
nestjs_account_1.TENANT_APP_REPOSITORY,
|
|
67
|
+
nestjs_account_1.MEMBERSHIP_ROLE_REPOSITORY,
|
|
68
|
+
nestjs_account_1.AUDIT_LOG_REPOSITORY,
|
|
69
|
+
nestjs_account_1.OWNERSHIP_TRANSFER_REPOSITORY,
|
|
70
|
+
],
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
exports.AccountPrismaModule = AccountPrismaModule;
|
|
75
|
+
exports.AccountPrismaModule = AccountPrismaModule = AccountPrismaModule_1 = __decorate([
|
|
76
|
+
(0, common_1.Module)({})
|
|
77
|
+
], AccountPrismaModule);
|
|
78
|
+
//# sourceMappingURL=account-prisma.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-prisma.module.js","sourceRoot":"","sources":["../lib/account-prisma.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAuD;AACvD,4DAaiC;AACjC,2EAAsE;AACtE,iFAA4E;AAC5E,qEAAgE;AAChE,iFAA4E;AAC5E,iFAA4E;AAC5E,2EAAsE;AACtE,2FAAqF;AACrF,mGAA6F;AAC7F,iF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6B,EAAE,WAAW,EAAE,wEAAiC,EAAE;aAC3F;YACD,OAAO,EAAE;gBACP,mCAAkB;gBAClB,sCAAqB;gBACrB,gCAAe;gBACf,sCAAqB;gBACrB,sCAAqB;gBACrB,mCAAkB;gBAClB,2CAA0B;gBAC1B,+CAA8B;gBAC9B,sCAAqB;gBACrB,2CAA0B;gBAC1B,qCAAoB;gBACpB,8CAA6B;aAC9B;SACF,CAAC;IACJ,CAAC;CACF,CAAA;AA/CY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,mBAAmB,CA+C/B"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from '@nathapp/nestjs-account';
|
|
2
|
+
export { PrismaAccountRepository } from './prisma-account.repository';
|
|
3
|
+
export { PrismaMembershipRepository } from './prisma-membership.repository';
|
|
4
|
+
export { PrismaRoleRepository } from './prisma-role.repository';
|
|
5
|
+
export { PrismaPermissionRepository } from './prisma-permission.repository';
|
|
6
|
+
export { PrismaInvitationRepository } from './prisma-invitation.repository';
|
|
7
|
+
export { PrismaProfileRepository } from './prisma-profile.repository';
|
|
8
|
+
export { PrismaOnboardingFlowRepository } from './prisma-onboarding-flow.repository';
|
|
9
|
+
export { PrismaOnboardingProgressRepository } from './prisma-onboarding-progress.repository';
|
|
10
|
+
export { PrismaTenantAppRepository } from './prisma-tenant-app.repository';
|
|
11
|
+
export { PrismaMembershipRoleRepository } from './prisma-membership-role.repository';
|
|
12
|
+
export { PrismaAuditLogRepository } from './prisma-audit-log.repository';
|
|
13
|
+
export { PrismaOwnershipTransferRepository } from './prisma-ownership-transfer.repository';
|
|
14
|
+
export { AccountPrismaModule, type PrismaAdapterModuleOptions } from './account-prisma.module';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.AccountPrismaModule = exports.PrismaOwnershipTransferRepository = exports.PrismaAuditLogRepository = exports.PrismaMembershipRoleRepository = exports.PrismaTenantAppRepository = exports.PrismaOnboardingProgressRepository = exports.PrismaOnboardingFlowRepository = exports.PrismaProfileRepository = exports.PrismaInvitationRepository = exports.PrismaPermissionRepository = exports.PrismaRoleRepository = exports.PrismaMembershipRepository = exports.PrismaAccountRepository = void 0;
|
|
18
|
+
__exportStar(require("@nathapp/nestjs-account"), exports);
|
|
19
|
+
var prisma_account_repository_1 = require("./prisma-account.repository");
|
|
20
|
+
Object.defineProperty(exports, "PrismaAccountRepository", { enumerable: true, get: function () { return prisma_account_repository_1.PrismaAccountRepository; } });
|
|
21
|
+
var prisma_membership_repository_1 = require("./prisma-membership.repository");
|
|
22
|
+
Object.defineProperty(exports, "PrismaMembershipRepository", { enumerable: true, get: function () { return prisma_membership_repository_1.PrismaMembershipRepository; } });
|
|
23
|
+
var prisma_role_repository_1 = require("./prisma-role.repository");
|
|
24
|
+
Object.defineProperty(exports, "PrismaRoleRepository", { enumerable: true, get: function () { return prisma_role_repository_1.PrismaRoleRepository; } });
|
|
25
|
+
var prisma_permission_repository_1 = require("./prisma-permission.repository");
|
|
26
|
+
Object.defineProperty(exports, "PrismaPermissionRepository", { enumerable: true, get: function () { return prisma_permission_repository_1.PrismaPermissionRepository; } });
|
|
27
|
+
var prisma_invitation_repository_1 = require("./prisma-invitation.repository");
|
|
28
|
+
Object.defineProperty(exports, "PrismaInvitationRepository", { enumerable: true, get: function () { return prisma_invitation_repository_1.PrismaInvitationRepository; } });
|
|
29
|
+
var prisma_profile_repository_1 = require("./prisma-profile.repository");
|
|
30
|
+
Object.defineProperty(exports, "PrismaProfileRepository", { enumerable: true, get: function () { return prisma_profile_repository_1.PrismaProfileRepository; } });
|
|
31
|
+
var prisma_onboarding_flow_repository_1 = require("./prisma-onboarding-flow.repository");
|
|
32
|
+
Object.defineProperty(exports, "PrismaOnboardingFlowRepository", { enumerable: true, get: function () { return prisma_onboarding_flow_repository_1.PrismaOnboardingFlowRepository; } });
|
|
33
|
+
var prisma_onboarding_progress_repository_1 = require("./prisma-onboarding-progress.repository");
|
|
34
|
+
Object.defineProperty(exports, "PrismaOnboardingProgressRepository", { enumerable: true, get: function () { return prisma_onboarding_progress_repository_1.PrismaOnboardingProgressRepository; } });
|
|
35
|
+
var prisma_tenant_app_repository_1 = require("./prisma-tenant-app.repository");
|
|
36
|
+
Object.defineProperty(exports, "PrismaTenantAppRepository", { enumerable: true, get: function () { return prisma_tenant_app_repository_1.PrismaTenantAppRepository; } });
|
|
37
|
+
var prisma_membership_role_repository_1 = require("./prisma-membership-role.repository");
|
|
38
|
+
Object.defineProperty(exports, "PrismaMembershipRoleRepository", { enumerable: true, get: function () { return prisma_membership_role_repository_1.PrismaMembershipRoleRepository; } });
|
|
39
|
+
var prisma_audit_log_repository_1 = require("./prisma-audit-log.repository");
|
|
40
|
+
Object.defineProperty(exports, "PrismaAuditLogRepository", { enumerable: true, get: function () { return prisma_audit_log_repository_1.PrismaAuditLogRepository; } });
|
|
41
|
+
var prisma_ownership_transfer_repository_1 = require("./prisma-ownership-transfer.repository");
|
|
42
|
+
Object.defineProperty(exports, "PrismaOwnershipTransferRepository", { enumerable: true, get: function () { return prisma_ownership_transfer_repository_1.PrismaOwnershipTransferRepository; } });
|
|
43
|
+
var account_prisma_module_1 = require("./account-prisma.module");
|
|
44
|
+
Object.defineProperty(exports, "AccountPrismaModule", { enumerable: true, get: function () { return account_prisma_module_1.AccountPrismaModule; } });
|
|
45
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AACA,0DAAwC;AAGxC,yEAAsE;AAA7D,oIAAA,uBAAuB,OAAA;AAChC,+EAA4E;AAAnE,0IAAA,0BAA0B,OAAA;AACnC,mEAAgE;AAAvD,8HAAA,oBAAoB,OAAA;AAC7B,+EAA4E;AAAnE,0IAAA,0BAA0B,OAAA;AACnC,+EAA4E;AAAnE,0IAAA,0BAA0B,OAAA;AACnC,yEAAsE;AAA7D,oIAAA,uBAAuB,OAAA;AAChC,yFAAqF;AAA5E,mJAAA,8BAA8B,OAAA;AACvC,iGAA6F;AAApF,2JAAA,kCAAkC,OAAA;AAC3C,+EAA2E;AAAlE,yIAAA,yBAAyB,OAAA;AAClC,yFAAqF;AAA5E,mJAAA,8BAA8B,OAAA;AACvC,6EAAyE;AAAhE,uIAAA,wBAAwB,OAAA;AACjC,+FAA2F;AAAlF,yJAAA,iCAAiC,OAAA;AAG1C,iEAA+F;AAAtF,4HAAA,mBAAmB,OAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { AbstractPrismaRepository, PrismaClientLike } from '@nathapp/nestjs-prisma';
|
|
2
|
+
import { ITransactionManager, IPageResult } from '@nathapp/nestjs-data';
|
|
3
|
+
import { IAccountRepository, IAccount, AccountStatus, AccountQuery } from '@nathapp/nestjs-account';
|
|
4
|
+
import { PrismaAccountModel } from './prisma-model.types';
|
|
5
|
+
export declare class PrismaAccountRepository extends AbstractPrismaRepository<IAccount, IAccount, string> implements IAccountRepository {
|
|
6
|
+
constructor(tx: ITransactionManager);
|
|
7
|
+
protected modelDelegate(client: PrismaClientLike): PrismaAccountModel<IAccount>;
|
|
8
|
+
private get accountModel();
|
|
9
|
+
protected toDomain(e: IAccount): IAccount;
|
|
10
|
+
protected toPersistenceCreate(d: IAccount): {
|
|
11
|
+
id: string;
|
|
12
|
+
tenantId: string;
|
|
13
|
+
appId: string;
|
|
14
|
+
type: string;
|
|
15
|
+
name: string;
|
|
16
|
+
status: AccountStatus;
|
|
17
|
+
ownerId: string;
|
|
18
|
+
metadata: Record<string, unknown>;
|
|
19
|
+
};
|
|
20
|
+
protected toPersistenceUpdate(p: Partial<IAccount>): Record<string, unknown>;
|
|
21
|
+
softDelete(id: string): Promise<void>;
|
|
22
|
+
findByUserId(userId: string, tenantId: string): Promise<IAccount[]>;
|
|
23
|
+
findByTenant(query: AccountQuery): Promise<IPageResult<IAccount>>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.PrismaAccountRepository = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const nestjs_prisma_1 = require("@nathapp/nestjs-prisma");
|
|
18
|
+
const nestjs_data_1 = require("@nathapp/nestjs-data");
|
|
19
|
+
const nestjs_account_1 = require("@nathapp/nestjs-account");
|
|
20
|
+
const prisma_model_types_1 = require("./prisma-model.types");
|
|
21
|
+
let PrismaAccountRepository = class PrismaAccountRepository extends nestjs_prisma_1.AbstractPrismaRepository {
|
|
22
|
+
constructor(tx) { super(tx); }
|
|
23
|
+
modelDelegate(client) {
|
|
24
|
+
return (0, prisma_model_types_1.getPrismaAccountModel)(client, 'account');
|
|
25
|
+
}
|
|
26
|
+
get accountModel() {
|
|
27
|
+
return this.modelDelegate(this.tx.getClient());
|
|
28
|
+
}
|
|
29
|
+
toDomain(e) {
|
|
30
|
+
return {
|
|
31
|
+
id: e.id,
|
|
32
|
+
tenantId: e.tenantId,
|
|
33
|
+
appId: e.appId,
|
|
34
|
+
type: e.type,
|
|
35
|
+
name: e.name,
|
|
36
|
+
status: e.status,
|
|
37
|
+
ownerId: e.ownerId,
|
|
38
|
+
metadata: e.metadata,
|
|
39
|
+
createdAt: e.createdAt,
|
|
40
|
+
updatedAt: e.updatedAt,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
toPersistenceCreate(d) {
|
|
44
|
+
var _a, _b;
|
|
45
|
+
return {
|
|
46
|
+
id: d.id,
|
|
47
|
+
tenantId: d.tenantId,
|
|
48
|
+
appId: d.appId,
|
|
49
|
+
type: d.type,
|
|
50
|
+
name: d.name,
|
|
51
|
+
status: (_a = d.status) !== null && _a !== void 0 ? _a : nestjs_account_1.AccountStatus.ACTIVE,
|
|
52
|
+
ownerId: d.ownerId,
|
|
53
|
+
metadata: (_b = d.metadata) !== null && _b !== void 0 ? _b : {},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
toPersistenceUpdate(p) {
|
|
57
|
+
const out = {};
|
|
58
|
+
if (p.name !== undefined)
|
|
59
|
+
out.name = p.name;
|
|
60
|
+
if (p.status !== undefined)
|
|
61
|
+
out.status = p.status;
|
|
62
|
+
if (p.ownerId !== undefined)
|
|
63
|
+
out.ownerId = p.ownerId;
|
|
64
|
+
if (p.metadata !== undefined)
|
|
65
|
+
out.metadata = p.metadata;
|
|
66
|
+
return out;
|
|
67
|
+
}
|
|
68
|
+
async softDelete(id) {
|
|
69
|
+
await this.model.update({ where: { id }, data: { status: nestjs_account_1.AccountStatus.CLOSED } });
|
|
70
|
+
}
|
|
71
|
+
async findByUserId(userId, tenantId) {
|
|
72
|
+
const rows = await this.accountModel.findMany({
|
|
73
|
+
where: { tenantId, memberships: { some: { userId, status: nestjs_account_1.MembershipStatus.ACTIVE } } },
|
|
74
|
+
});
|
|
75
|
+
return rows.map((row) => this.toDomain(row));
|
|
76
|
+
}
|
|
77
|
+
async findByTenant(query) {
|
|
78
|
+
var _a;
|
|
79
|
+
const where = { tenantId: query.tenantId };
|
|
80
|
+
if (query.appId)
|
|
81
|
+
where.appId = query.appId;
|
|
82
|
+
if (query.type)
|
|
83
|
+
where.type = query.type;
|
|
84
|
+
if (query.status !== undefined)
|
|
85
|
+
where.status = query.status;
|
|
86
|
+
const orderBy = query.sortBy
|
|
87
|
+
? { [query.sortBy]: (_a = query.sortOrder) !== null && _a !== void 0 ? _a : 'asc' }
|
|
88
|
+
: { createdAt: 'desc' };
|
|
89
|
+
const result = await (0, nestjs_prisma_1.Paginate)(this.accountModel, query, { where, orderBy });
|
|
90
|
+
return result.remap((row) => this.toDomain(row));
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
exports.PrismaAccountRepository = PrismaAccountRepository;
|
|
94
|
+
exports.PrismaAccountRepository = PrismaAccountRepository = __decorate([
|
|
95
|
+
(0, common_1.Injectable)(),
|
|
96
|
+
__param(0, (0, common_1.Inject)(nestjs_data_1.TRANSACTION_MANAGER)),
|
|
97
|
+
__metadata("design:paramtypes", [Object])
|
|
98
|
+
], PrismaAccountRepository);
|
|
99
|
+
//# sourceMappingURL=prisma-account.repository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prisma-account.repository.js","sourceRoot":"","sources":["../lib/prisma-account.repository.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAoD;AACpD,0DAA8F;AAC9F,sDAA6F;AAC7F,4DAMiC;AACjC,6DAAiF;AAG1E,IAAM,uBAAuB,GAA7B,MAAM,uBACX,SAAQ,wCAAoD;IAG5D,YAAyC,EAAuB,IAAI,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAEtE,aAAa,CAAC,MAAwB;QAC9C,OAAO,IAAA,0CAAqB,EAAW,MAAM,EAAE,SAAS,CAAC,CAAC;IAC5D,CAAC;IAED,IAAY,YAAY;QACtB,OAAO,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC,SAAS,EAAoB,CAAC,CAAC;IACnE,CAAC;IAES,QAAQ,CAAC,CAAW;QAC5B,OAAO;YACL,EAAE,EAAE,CAAC,CAAC,EAAE;YACR,QAAQ,EAAE,CAAC,CAAC,QAAQ;YACpB,KAAK,EAAE,CAAC,CAAC,KAAK;YACd,IAAI,EAAE,CAAC,CAAC,IAAI;YACZ,IAAI,EAAE,CAAC,CAAC,IAAI;YACZ,MAAM,EAAE,CAAC,CAAC,MAAuB;YACjC,OAAO,EAAE,CAAC,CAAC,OAAO;YAClB,QAAQ,EAAE,CAAC,CAAC,QAAQ;YACpB,SAAS,EAAE,CAAC,CAAC,SAAS;YACtB,SAAS,EAAE,CAAC,CAAC,SAAS;SACvB,CAAC;IACJ,CAAC;IAES,mBAAmB,CAAC,CAAW;;QACvC,OAAO;YACL,EAAE,EAAE,CAAC,CAAC,EAAE;YACR,QAAQ,EAAE,CAAC,CAAC,QAAQ;YACpB,KAAK,EAAE,CAAC,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nathapp/nestjs-data';
|
|
3
|
+
import { AuditLogEntry, CreateAuditLogEntryData, IAuditLogRepository, AuditLogFilter } from '@nathapp/nestjs-account';
|
|
4
|
+
interface AuditLogModel {
|
|
5
|
+
findUnique(args: {
|
|
6
|
+
where: {
|
|
7
|
+
id: string;
|
|
8
|
+
};
|
|
9
|
+
}): Promise<AuditLogEntry | null>;
|
|
10
|
+
create(args: {
|
|
11
|
+
data: Record<string, unknown>;
|
|
12
|
+
}): Promise<AuditLogEntry>;
|
|
13
|
+
findMany(args?: {
|
|
14
|
+
where?: Record<string, unknown>;
|
|
15
|
+
orderBy?: Record<string, unknown>;
|
|
16
|
+
skip?: number;
|
|
17
|
+
take?: number;
|
|
18
|
+
}): Promise<AuditLogEntry[]>;
|
|
19
|
+
count(args?: {
|
|
20
|
+
where?: Record<string, unknown>;
|
|
21
|
+
}): Promise<number>;
|
|
22
|
+
}
|
|
23
|
+
export declare class PrismaAuditLogRepository implements IAuditLogRepository {
|
|
24
|
+
protected readonly tx: ITransactionManager;
|
|
25
|
+
constructor(tx: ITransactionManager);
|
|
26
|
+
protected modelDelegate(client: PrismaClientLike): AuditLogModel;
|
|
27
|
+
protected get model(): AuditLogModel;
|
|
28
|
+
protected toPersistenceCreate(d: CreateAuditLogEntryData): Record<string, unknown>;
|
|
29
|
+
protected toDomain(e: AuditLogEntry): AuditLogEntry;
|
|
30
|
+
protected toPersistenceUpdate(_patch?: Partial<AuditLogEntry>): Record<string, unknown>;
|
|
31
|
+
create(data: CreateAuditLogEntryData): Promise<AuditLogEntry>;
|
|
32
|
+
findById(id: string): Promise<AuditLogEntry | null>;
|
|
33
|
+
update(_id: string, _patch: Partial<AuditLogEntry>): Promise<AuditLogEntry>;
|
|
34
|
+
delete(_id: string): Promise<void>;
|
|
35
|
+
findByAccount(accountId: string, tenantId: string, filter: AuditLogFilter): Promise<IPageResult<AuditLogEntry>>;
|
|
36
|
+
findByTenant(tenantId: string, filter: AuditLogFilter): Promise<IPageResult<AuditLogEntry>>;
|
|
37
|
+
private buildAccountWhere;
|
|
38
|
+
private buildTenantWhere;
|
|
39
|
+
private applyOptionalFilters;
|
|
40
|
+
}
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.PrismaAuditLogRepository = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const nestjs_prisma_1 = require("@nathapp/nestjs-prisma");
|
|
18
|
+
const nestjs_data_1 = require("@nathapp/nestjs-data");
|
|
19
|
+
function getAuditLogModel(client) {
|
|
20
|
+
const candidate = client.auditLogEntry;
|
|
21
|
+
if (typeof candidate !== 'object' || candidate === null ||
|
|
22
|
+
!('findUnique' in candidate) || typeof candidate.findUnique !== 'function' ||
|
|
23
|
+
!('create' in candidate) || typeof candidate.create !== 'function' ||
|
|
24
|
+
!('findMany' in candidate) || typeof candidate.findMany !== 'function' ||
|
|
25
|
+
!('count' in candidate) || typeof candidate.count !== 'function') {
|
|
26
|
+
throw new TypeError('Prisma client auditLogEntry delegate must support findUnique, create, findMany and count');
|
|
27
|
+
}
|
|
28
|
+
return candidate;
|
|
29
|
+
}
|
|
30
|
+
let PrismaAuditLogRepository = class PrismaAuditLogRepository {
|
|
31
|
+
constructor(tx) {
|
|
32
|
+
this.tx = tx;
|
|
33
|
+
}
|
|
34
|
+
modelDelegate(client) {
|
|
35
|
+
return getAuditLogModel(client);
|
|
36
|
+
}
|
|
37
|
+
get model() {
|
|
38
|
+
return this.modelDelegate(this.tx.getClient());
|
|
39
|
+
}
|
|
40
|
+
toPersistenceCreate(d) {
|
|
41
|
+
const out = {
|
|
42
|
+
action: d.action,
|
|
43
|
+
actorType: d.actorType,
|
|
44
|
+
userFacing: d.userFacing,
|
|
45
|
+
};
|
|
46
|
+
if (d.tenantId !== undefined)
|
|
47
|
+
out.tenantId = d.tenantId;
|
|
48
|
+
if (d.accountId !== undefined)
|
|
49
|
+
out.accountId = d.accountId;
|
|
50
|
+
if (d.actorId !== undefined)
|
|
51
|
+
out.actorId = d.actorId;
|
|
52
|
+
if (d.targetType !== undefined)
|
|
53
|
+
out.targetType = d.targetType;
|
|
54
|
+
if (d.targetId !== undefined)
|
|
55
|
+
out.targetId = d.targetId;
|
|
56
|
+
if (d.metadata !== undefined)
|
|
57
|
+
out.metadata = d.metadata;
|
|
58
|
+
if (d.ipAddress !== undefined)
|
|
59
|
+
out.ipAddress = d.ipAddress;
|
|
60
|
+
if (d.userAgent !== undefined)
|
|
61
|
+
out.userAgent = d.userAgent;
|
|
62
|
+
return out;
|
|
63
|
+
}
|
|
64
|
+
toDomain(e) {
|
|
65
|
+
return {
|
|
66
|
+
id: e.id,
|
|
67
|
+
tenantId: e.tenantId,
|
|
68
|
+
action: e.action,
|
|
69
|
+
actorType: e.actorType,
|
|
70
|
+
userFacing: e.userFacing,
|
|
71
|
+
createdAt: e.createdAt,
|
|
72
|
+
...(e.accountId !== undefined && { accountId: e.accountId }),
|
|
73
|
+
...(e.actorId !== undefined && { actorId: e.actorId }),
|
|
74
|
+
...(e.targetType !== undefined && { targetType: e.targetType }),
|
|
75
|
+
...(e.targetId !== undefined && { targetId: e.targetId }),
|
|
76
|
+
...(e.metadata !== undefined && { metadata: e.metadata }),
|
|
77
|
+
...(e.ipAddress !== undefined && { ipAddress: e.ipAddress }),
|
|
78
|
+
...(e.userAgent !== undefined && { userAgent: e.userAgent }),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
toPersistenceUpdate(_patch) {
|
|
82
|
+
throw new Error('AuditLogEntry is append-only; update is not allowed');
|
|
83
|
+
}
|
|
84
|
+
async create(data) {
|
|
85
|
+
const row = await this.model.create({ data: this.toPersistenceCreate(data) });
|
|
86
|
+
return this.toDomain(row);
|
|
87
|
+
}
|
|
88
|
+
async findById(id) {
|
|
89
|
+
const row = await this.model.findUnique({ where: { id } });
|
|
90
|
+
return row ? this.toDomain(row) : null;
|
|
91
|
+
}
|
|
92
|
+
async update(_id, _patch) {
|
|
93
|
+
throw new Error('AuditLogEntry is append-only; update is not allowed');
|
|
94
|
+
}
|
|
95
|
+
async delete(_id) {
|
|
96
|
+
throw new Error('AuditLogEntry is append-only; delete is not allowed');
|
|
97
|
+
}
|
|
98
|
+
async findByAccount(accountId, tenantId, filter) {
|
|
99
|
+
const { current, size, where } = this.buildAccountWhere(accountId, tenantId, filter);
|
|
100
|
+
const result = await (0, nestjs_prisma_1.Paginate)(this.model, { current, size }, {
|
|
101
|
+
where,
|
|
102
|
+
orderBy: { createdAt: 'desc' },
|
|
103
|
+
});
|
|
104
|
+
return result.remap((row) => this.toDomain(row));
|
|
105
|
+
}
|
|
106
|
+
async findByTenant(tenantId, filter) {
|
|
107
|
+
const { current, size, where } = this.buildTenantWhere(tenantId, filter);
|
|
108
|
+
const result = await (0, nestjs_prisma_1.Paginate)(this.model, { current, size }, {
|
|
109
|
+
where,
|
|
110
|
+
orderBy: { createdAt: 'desc' },
|
|
111
|
+
});
|
|
112
|
+
return result.remap((row) => this.toDomain(row));
|
|
113
|
+
}
|
|
114
|
+
buildAccountWhere(accountId, tenantId, filter) {
|
|
115
|
+
var _a, _b;
|
|
116
|
+
const where = { accountId, tenantId, userFacing: true };
|
|
117
|
+
this.applyOptionalFilters(where, filter, ['accountId', 'tenantId', 'userFacing']);
|
|
118
|
+
return { current: (_a = filter.current) !== null && _a !== void 0 ? _a : 1, size: (_b = filter.size) !== null && _b !== void 0 ? _b : 20, where };
|
|
119
|
+
}
|
|
120
|
+
buildTenantWhere(tenantId, filter) {
|
|
121
|
+
var _a, _b;
|
|
122
|
+
const where = { tenantId };
|
|
123
|
+
this.applyOptionalFilters(where, filter, ['tenantId']);
|
|
124
|
+
return { current: (_a = filter.current) !== null && _a !== void 0 ? _a : 1, size: (_b = filter.size) !== null && _b !== void 0 ? _b : 20, where };
|
|
125
|
+
}
|
|
126
|
+
applyOptionalFilters(where, filter, skip) {
|
|
127
|
+
if (filter.accountId !== undefined && !skip.includes('accountId'))
|
|
128
|
+
where.accountId = filter.accountId;
|
|
129
|
+
if (filter.actorId !== undefined)
|
|
130
|
+
where.actorId = filter.actorId;
|
|
131
|
+
if (filter.action !== undefined)
|
|
132
|
+
where.action = filter.action;
|
|
133
|
+
if (filter.actorType !== undefined)
|
|
134
|
+
where.actorType = filter.actorType;
|
|
135
|
+
if (filter.userFacing !== undefined && !skip.includes('userFacing'))
|
|
136
|
+
where.userFacing = filter.userFacing;
|
|
137
|
+
if (filter.from !== undefined || filter.to !== undefined) {
|
|
138
|
+
const range = {};
|
|
139
|
+
if (filter.from !== undefined)
|
|
140
|
+
range.gte = filter.from;
|
|
141
|
+
if (filter.to !== undefined)
|
|
142
|
+
range.lte = filter.to;
|
|
143
|
+
where.createdAt = range;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
exports.PrismaAuditLogRepository = PrismaAuditLogRepository;
|
|
148
|
+
exports.PrismaAuditLogRepository = PrismaAuditLogRepository = __decorate([
|
|
149
|
+
(0, common_1.Injectable)(),
|
|
150
|
+
__param(0, (0, common_1.Inject)(nestjs_data_1.TRANSACTION_MANAGER)),
|
|
151
|
+
__metadata("design:paramtypes", [Object])
|
|
152
|
+
], PrismaAuditLogRepository);
|
|
153
|
+
//# sourceMappingURL=prisma-audit-log.repository.js.map
|