@forklaunch/implementation-iam-base 0.5.8 → 0.6.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/lib/domain/types/index.d.mts +195 -0
- package/lib/domain/types/index.d.ts +195 -0
- package/lib/domain/types/index.js +22 -0
- package/lib/domain/types/index.mjs +0 -0
- package/lib/eject/domain/types/index.ts +6 -0
- package/lib/eject/domain/types/organization.mapper.types.ts +29 -0
- package/lib/eject/domain/types/permission.mapper.types.ts +35 -0
- package/lib/eject/domain/types/role.mapper.types.ts +28 -0
- package/lib/eject/domain/types/user.mapper.types.ts +28 -0
- package/lib/eject/services/organization.service.ts +40 -80
- package/lib/eject/services/permission.service.ts +69 -116
- package/lib/eject/services/role.service.ts +40 -97
- package/lib/eject/services/user.service.ts +47 -95
- package/lib/services/index.d.mts +108 -356
- package/lib/services/index.d.ts +108 -356
- package/lib/services/index.js +106 -112
- package/lib/services/index.mjs +106 -100
- package/package.json +9 -9
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IdDto
|
|
1
|
+
import { IdDto } from '@forklaunch/common';
|
|
2
2
|
import {
|
|
3
3
|
evaluateTelemetryOptions,
|
|
4
4
|
MetricsDefinition,
|
|
@@ -7,25 +7,25 @@ import {
|
|
|
7
7
|
} from '@forklaunch/core/http';
|
|
8
8
|
import { OrganizationService } from '@forklaunch/interfaces-iam/interfaces';
|
|
9
9
|
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
transformIntoInternalMapper
|
|
14
|
-
} from '@forklaunch/internal';
|
|
10
|
+
CreateOrganizationDto,
|
|
11
|
+
UpdateOrganizationDto
|
|
12
|
+
} from '@forklaunch/interfaces-iam/types';
|
|
15
13
|
import { AnySchemaValidator } from '@forklaunch/validator';
|
|
16
14
|
import { EntityManager } from '@mikro-orm/core';
|
|
17
15
|
import { OrganizationDtos } from '../domain/types/iamDto.types';
|
|
18
16
|
import { OrganizationEntities } from '../domain/types/iamEntities.types';
|
|
17
|
+
import { OrganizationMappers } from '../domain/types/organization.mapper.types';
|
|
19
18
|
|
|
20
19
|
export class BaseOrganizationService<
|
|
21
20
|
SchemaValidator extends AnySchemaValidator,
|
|
22
|
-
OrganizationStatus,
|
|
23
|
-
MapperEntities extends
|
|
24
|
-
|
|
21
|
+
OrganizationStatus = unknown,
|
|
22
|
+
MapperEntities extends
|
|
23
|
+
OrganizationEntities<OrganizationStatus> = OrganizationEntities<OrganizationStatus>,
|
|
24
|
+
MapperDomains extends
|
|
25
25
|
OrganizationDtos<OrganizationStatus> = OrganizationDtos<OrganizationStatus>
|
|
26
26
|
> implements OrganizationService<OrganizationStatus>
|
|
27
27
|
{
|
|
28
|
-
protected _mappers: InternalMapper<InstanceTypeRecord<typeof this.mappers>>;
|
|
28
|
+
// protected _mappers: InternalMapper<InstanceTypeRecord<typeof this.mappers>>;
|
|
29
29
|
private evaluatedTelemetryOptions: {
|
|
30
30
|
logging?: boolean;
|
|
31
31
|
metrics?: boolean;
|
|
@@ -34,61 +34,21 @@ export class BaseOrganizationService<
|
|
|
34
34
|
public em: EntityManager;
|
|
35
35
|
protected openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>;
|
|
36
36
|
protected schemaValidator: SchemaValidator;
|
|
37
|
-
protected mappers:
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
>;
|
|
43
|
-
CreateOrganizationMapper: RequestMapperConstructor<
|
|
44
|
-
SchemaValidator,
|
|
45
|
-
MapperDtos['CreateOrganizationMapper'],
|
|
46
|
-
MapperEntities['CreateOrganizationMapper'],
|
|
47
|
-
(
|
|
48
|
-
dto: MapperDtos['CreateOrganizationMapper'],
|
|
49
|
-
em: EntityManager
|
|
50
|
-
) => Promise<MapperEntities['CreateOrganizationMapper']>
|
|
51
|
-
>;
|
|
52
|
-
UpdateOrganizationMapper: RequestMapperConstructor<
|
|
53
|
-
SchemaValidator,
|
|
54
|
-
MapperDtos['UpdateOrganizationMapper'],
|
|
55
|
-
MapperEntities['UpdateOrganizationMapper'],
|
|
56
|
-
(
|
|
57
|
-
dto: MapperDtos['UpdateOrganizationMapper'],
|
|
58
|
-
em: EntityManager
|
|
59
|
-
) => Promise<MapperEntities['UpdateOrganizationMapper']>
|
|
60
|
-
>;
|
|
61
|
-
};
|
|
37
|
+
protected mappers: OrganizationMappers<
|
|
38
|
+
OrganizationStatus,
|
|
39
|
+
MapperEntities,
|
|
40
|
+
MapperDomains
|
|
41
|
+
>;
|
|
62
42
|
|
|
63
43
|
constructor(
|
|
64
44
|
em: EntityManager,
|
|
65
45
|
openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>,
|
|
66
46
|
schemaValidator: SchemaValidator,
|
|
67
|
-
mappers:
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
>;
|
|
73
|
-
CreateOrganizationMapper: RequestMapperConstructor<
|
|
74
|
-
SchemaValidator,
|
|
75
|
-
MapperDtos['CreateOrganizationMapper'],
|
|
76
|
-
MapperEntities['CreateOrganizationMapper'],
|
|
77
|
-
(
|
|
78
|
-
dto: MapperDtos['CreateOrganizationMapper'],
|
|
79
|
-
em: EntityManager
|
|
80
|
-
) => Promise<MapperEntities['CreateOrganizationMapper']>
|
|
81
|
-
>;
|
|
82
|
-
UpdateOrganizationMapper: RequestMapperConstructor<
|
|
83
|
-
SchemaValidator,
|
|
84
|
-
MapperDtos['UpdateOrganizationMapper'],
|
|
85
|
-
MapperEntities['UpdateOrganizationMapper'],
|
|
86
|
-
(
|
|
87
|
-
dto: MapperDtos['UpdateOrganizationMapper'],
|
|
88
|
-
em: EntityManager
|
|
89
|
-
) => Promise<MapperEntities['UpdateOrganizationMapper']>
|
|
90
|
-
>;
|
|
91
|
-
},
|
|
47
|
+
mappers: OrganizationMappers<
|
|
48
|
+
OrganizationStatus,
|
|
49
|
+
MapperEntities,
|
|
50
|
+
MapperDomains
|
|
51
|
+
>,
|
|
92
52
|
options?: {
|
|
93
53
|
telemetry?: TelemetryOptions;
|
|
94
54
|
}
|
|
@@ -97,7 +57,6 @@ export class BaseOrganizationService<
|
|
|
97
57
|
this.openTelemetryCollector = openTelemetryCollector;
|
|
98
58
|
this.schemaValidator = schemaValidator;
|
|
99
59
|
this.mappers = mappers;
|
|
100
|
-
this._mappers = transformIntoInternalMapper(mappers, schemaValidator);
|
|
101
60
|
this.evaluatedTelemetryOptions = options?.telemetry
|
|
102
61
|
? evaluateTelemetryOptions(options.telemetry).enabled
|
|
103
62
|
: {
|
|
@@ -108,9 +67,10 @@ export class BaseOrganizationService<
|
|
|
108
67
|
}
|
|
109
68
|
|
|
110
69
|
async createOrganization(
|
|
111
|
-
organizationDto:
|
|
112
|
-
em?: EntityManager
|
|
113
|
-
|
|
70
|
+
organizationDto: CreateOrganizationDto,
|
|
71
|
+
em?: EntityManager,
|
|
72
|
+
...args: unknown[]
|
|
73
|
+
): Promise<MapperDomains['OrganizationMapper']> {
|
|
114
74
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
115
75
|
this.openTelemetryCollector.info(
|
|
116
76
|
'Creating organization',
|
|
@@ -118,11 +78,11 @@ export class BaseOrganizationService<
|
|
|
118
78
|
);
|
|
119
79
|
}
|
|
120
80
|
|
|
121
|
-
const organization =
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
81
|
+
const organization = await this.mappers.CreateOrganizationMapper.toEntity(
|
|
82
|
+
organizationDto,
|
|
83
|
+
em ?? this.em,
|
|
84
|
+
...args
|
|
85
|
+
);
|
|
126
86
|
|
|
127
87
|
if (em) {
|
|
128
88
|
await em.persist(organization);
|
|
@@ -130,13 +90,13 @@ export class BaseOrganizationService<
|
|
|
130
90
|
await this.em.persistAndFlush(organization);
|
|
131
91
|
}
|
|
132
92
|
|
|
133
|
-
return this.
|
|
93
|
+
return this.mappers.OrganizationMapper.toDto(organization);
|
|
134
94
|
}
|
|
135
95
|
|
|
136
96
|
async getOrganization(
|
|
137
97
|
idDto: IdDto,
|
|
138
98
|
em?: EntityManager
|
|
139
|
-
): Promise<
|
|
99
|
+
): Promise<MapperDomains['OrganizationMapper']> {
|
|
140
100
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
141
101
|
this.openTelemetryCollector.info('Getting organization', idDto);
|
|
142
102
|
}
|
|
@@ -149,15 +109,16 @@ export class BaseOrganizationService<
|
|
|
149
109
|
}
|
|
150
110
|
);
|
|
151
111
|
|
|
152
|
-
return this.
|
|
112
|
+
return this.mappers.OrganizationMapper.toDto(
|
|
153
113
|
organization as MapperEntities['OrganizationMapper']
|
|
154
114
|
);
|
|
155
115
|
}
|
|
156
116
|
|
|
157
117
|
async updateOrganization(
|
|
158
|
-
organizationDto:
|
|
159
|
-
em?: EntityManager
|
|
160
|
-
|
|
118
|
+
organizationDto: UpdateOrganizationDto,
|
|
119
|
+
em?: EntityManager,
|
|
120
|
+
...args: unknown[]
|
|
121
|
+
): Promise<MapperDomains['OrganizationMapper']> {
|
|
161
122
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
162
123
|
this.openTelemetryCollector.info(
|
|
163
124
|
'Updating organization',
|
|
@@ -166,9 +127,10 @@ export class BaseOrganizationService<
|
|
|
166
127
|
}
|
|
167
128
|
|
|
168
129
|
const updatedOrganization =
|
|
169
|
-
await this.
|
|
130
|
+
await this.mappers.UpdateOrganizationMapper.toEntity(
|
|
170
131
|
organizationDto,
|
|
171
|
-
em ?? this.em
|
|
132
|
+
em ?? this.em,
|
|
133
|
+
...args
|
|
172
134
|
);
|
|
173
135
|
|
|
174
136
|
if (em) {
|
|
@@ -177,9 +139,7 @@ export class BaseOrganizationService<
|
|
|
177
139
|
await this.em.persistAndFlush(updatedOrganization);
|
|
178
140
|
}
|
|
179
141
|
|
|
180
|
-
return this.
|
|
181
|
-
updatedOrganization
|
|
182
|
-
);
|
|
142
|
+
return this.mappers.OrganizationMapper.toDto(updatedOrganization);
|
|
183
143
|
}
|
|
184
144
|
|
|
185
145
|
async deleteOrganization(idDto: IdDto, em?: EntityManager): Promise<void> {
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
RoleService
|
|
4
4
|
} from '@forklaunch/interfaces-iam/interfaces';
|
|
5
5
|
|
|
6
|
-
import { IdDto, IdsDto
|
|
6
|
+
import { IdDto, IdsDto } from '@forklaunch/common';
|
|
7
7
|
import {
|
|
8
8
|
evaluateTelemetryOptions,
|
|
9
9
|
MetricsDefinition,
|
|
@@ -11,23 +11,21 @@ import {
|
|
|
11
11
|
TelemetryOptions
|
|
12
12
|
} from '@forklaunch/core/http';
|
|
13
13
|
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
transformIntoInternalMapper
|
|
18
|
-
} from '@forklaunch/internal';
|
|
14
|
+
CreatePermissionDto,
|
|
15
|
+
UpdatePermissionDto
|
|
16
|
+
} from '@forklaunch/interfaces-iam/types';
|
|
19
17
|
import { AnySchemaValidator } from '@forklaunch/validator';
|
|
20
18
|
import { EntityManager } from '@mikro-orm/core';
|
|
21
19
|
import { PermissionDtos } from '../domain/types/iamDto.types';
|
|
22
20
|
import { PermissionEntities } from '../domain/types/iamEntities.types';
|
|
21
|
+
import { PermissionMappers } from '../domain/types/permission.mapper.types';
|
|
23
22
|
|
|
24
23
|
export class BasePermissionService<
|
|
25
24
|
SchemaValidator extends AnySchemaValidator,
|
|
26
|
-
MapperEntities extends PermissionEntities,
|
|
27
|
-
|
|
25
|
+
MapperEntities extends PermissionEntities = PermissionEntities,
|
|
26
|
+
MapperDomains extends PermissionDtos = PermissionDtos
|
|
28
27
|
> implements PermissionService
|
|
29
28
|
{
|
|
30
|
-
protected _mappers: InternalMapper<InstanceTypeRecord<typeof this.mappers>>;
|
|
31
29
|
private evaluatedTelemetryOptions: {
|
|
32
30
|
logging?: boolean;
|
|
33
31
|
metrics?: boolean;
|
|
@@ -37,80 +35,14 @@ export class BasePermissionService<
|
|
|
37
35
|
protected roleServiceFactory: () => RoleService;
|
|
38
36
|
protected openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>;
|
|
39
37
|
protected schemaValidator: SchemaValidator;
|
|
40
|
-
protected mappers:
|
|
41
|
-
PermissionMapper: ResponseMapperConstructor<
|
|
42
|
-
SchemaValidator,
|
|
43
|
-
MapperDto['PermissionMapper'],
|
|
44
|
-
MapperEntities['PermissionMapper']
|
|
45
|
-
>;
|
|
46
|
-
CreatePermissionMapper: RequestMapperConstructor<
|
|
47
|
-
SchemaValidator,
|
|
48
|
-
MapperDto['CreatePermissionMapper'],
|
|
49
|
-
MapperEntities['CreatePermissionMapper'],
|
|
50
|
-
(
|
|
51
|
-
dto: MapperDto['CreatePermissionMapper'],
|
|
52
|
-
em: EntityManager
|
|
53
|
-
) => Promise<MapperEntities['CreatePermissionMapper']>
|
|
54
|
-
>;
|
|
55
|
-
UpdatePermissionMapper: RequestMapperConstructor<
|
|
56
|
-
SchemaValidator,
|
|
57
|
-
MapperDto['UpdatePermissionMapper'],
|
|
58
|
-
MapperEntities['UpdatePermissionMapper'],
|
|
59
|
-
(
|
|
60
|
-
dto: MapperDto['UpdatePermissionMapper'],
|
|
61
|
-
em: EntityManager
|
|
62
|
-
) => Promise<MapperEntities['UpdatePermissionMapper']>
|
|
63
|
-
>;
|
|
64
|
-
RoleEntityMapper: RequestMapperConstructor<
|
|
65
|
-
SchemaValidator,
|
|
66
|
-
MapperDto['RoleEntityMapper'],
|
|
67
|
-
MapperEntities['RoleEntityMapper'],
|
|
68
|
-
(
|
|
69
|
-
dto: MapperDto['RoleEntityMapper'],
|
|
70
|
-
em: EntityManager
|
|
71
|
-
) => Promise<MapperEntities['RoleEntityMapper']>
|
|
72
|
-
>;
|
|
73
|
-
};
|
|
38
|
+
protected mappers: PermissionMappers<MapperEntities, MapperDomains>;
|
|
74
39
|
|
|
75
40
|
constructor(
|
|
76
41
|
em: EntityManager,
|
|
77
42
|
roleServiceFactory: () => RoleService,
|
|
78
43
|
openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>,
|
|
79
44
|
schemaValidator: SchemaValidator,
|
|
80
|
-
mappers:
|
|
81
|
-
PermissionMapper: ResponseMapperConstructor<
|
|
82
|
-
SchemaValidator,
|
|
83
|
-
MapperDto['PermissionMapper'],
|
|
84
|
-
MapperEntities['PermissionMapper']
|
|
85
|
-
>;
|
|
86
|
-
CreatePermissionMapper: RequestMapperConstructor<
|
|
87
|
-
SchemaValidator,
|
|
88
|
-
MapperDto['CreatePermissionMapper'],
|
|
89
|
-
MapperEntities['CreatePermissionMapper'],
|
|
90
|
-
(
|
|
91
|
-
dto: MapperDto['CreatePermissionMapper'],
|
|
92
|
-
em: EntityManager
|
|
93
|
-
) => Promise<MapperEntities['CreatePermissionMapper']>
|
|
94
|
-
>;
|
|
95
|
-
UpdatePermissionMapper: RequestMapperConstructor<
|
|
96
|
-
SchemaValidator,
|
|
97
|
-
MapperDto['UpdatePermissionMapper'],
|
|
98
|
-
MapperEntities['UpdatePermissionMapper'],
|
|
99
|
-
(
|
|
100
|
-
dto: MapperDto['UpdatePermissionMapper'],
|
|
101
|
-
em: EntityManager
|
|
102
|
-
) => Promise<MapperEntities['UpdatePermissionMapper']>
|
|
103
|
-
>;
|
|
104
|
-
RoleEntityMapper: RequestMapperConstructor<
|
|
105
|
-
SchemaValidator,
|
|
106
|
-
MapperDto['RoleEntityMapper'],
|
|
107
|
-
MapperEntities['RoleEntityMapper'],
|
|
108
|
-
(
|
|
109
|
-
dto: MapperDto['RoleEntityMapper'],
|
|
110
|
-
em: EntityManager
|
|
111
|
-
) => Promise<MapperEntities['RoleEntityMapper']>
|
|
112
|
-
>;
|
|
113
|
-
},
|
|
45
|
+
mappers: PermissionMappers<MapperEntities, MapperDomains>,
|
|
114
46
|
options?: {
|
|
115
47
|
telemetry?: TelemetryOptions;
|
|
116
48
|
}
|
|
@@ -120,7 +52,6 @@ export class BasePermissionService<
|
|
|
120
52
|
this.openTelemetryCollector = openTelemetryCollector;
|
|
121
53
|
this.schemaValidator = schemaValidator;
|
|
122
54
|
this.mappers = mappers;
|
|
123
|
-
this._mappers = transformIntoInternalMapper(mappers, schemaValidator);
|
|
124
55
|
this.evaluatedTelemetryOptions = options?.telemetry
|
|
125
56
|
? evaluateTelemetryOptions(options.telemetry).enabled
|
|
126
57
|
: {
|
|
@@ -166,7 +97,7 @@ export class BasePermissionService<
|
|
|
166
97
|
(await this.roleServiceFactory().getBatchRoles(roles, em)).map(
|
|
167
98
|
async (role) => {
|
|
168
99
|
return (em ?? this.em).merge(
|
|
169
|
-
await this.
|
|
100
|
+
await this.mappers.RoleEntityMapper.toEntity(
|
|
170
101
|
role,
|
|
171
102
|
em ?? this.em
|
|
172
103
|
)
|
|
@@ -179,7 +110,7 @@ export class BasePermissionService<
|
|
|
179
110
|
// end: global helper functions
|
|
180
111
|
|
|
181
112
|
// start: createPermission helper functions
|
|
182
|
-
private async
|
|
113
|
+
private async createPermissionEntity({
|
|
183
114
|
permission,
|
|
184
115
|
addToRoles
|
|
185
116
|
}: {
|
|
@@ -197,18 +128,20 @@ export class BasePermissionService<
|
|
|
197
128
|
return { permission, roles };
|
|
198
129
|
}
|
|
199
130
|
|
|
200
|
-
private async
|
|
201
|
-
permissionDto:
|
|
202
|
-
em?: EntityManager
|
|
131
|
+
private async extractCreatePermissionEntityToEntityData(
|
|
132
|
+
permissionDto: CreatePermissionDto,
|
|
133
|
+
em?: EntityManager,
|
|
134
|
+
...args: unknown[]
|
|
203
135
|
): Promise<{
|
|
204
136
|
permission: MapperEntities['PermissionMapper'];
|
|
205
137
|
addToRoles: MapperEntities['RoleEntityMapper'][];
|
|
206
138
|
}> {
|
|
207
139
|
return {
|
|
208
140
|
permission: (em ?? this.em).merge(
|
|
209
|
-
await this.
|
|
141
|
+
await this.mappers.CreatePermissionMapper.toEntity(
|
|
210
142
|
permissionDto,
|
|
211
|
-
em ?? this.em
|
|
143
|
+
em ?? this.em,
|
|
144
|
+
...args
|
|
212
145
|
)
|
|
213
146
|
),
|
|
214
147
|
addToRoles: permissionDto.addToRolesIds
|
|
@@ -219,17 +152,22 @@ export class BasePermissionService<
|
|
|
219
152
|
// end: createPermission helper functions
|
|
220
153
|
|
|
221
154
|
async createPermission(
|
|
222
|
-
|
|
223
|
-
em?: EntityManager
|
|
224
|
-
|
|
155
|
+
createPermissionEntity: CreatePermissionDto,
|
|
156
|
+
em?: EntityManager,
|
|
157
|
+
...args: unknown[]
|
|
158
|
+
): Promise<MapperDomains['PermissionMapper']> {
|
|
225
159
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
226
160
|
this.openTelemetryCollector.info(
|
|
227
161
|
'Creating permission',
|
|
228
|
-
|
|
162
|
+
createPermissionEntity
|
|
229
163
|
);
|
|
230
164
|
}
|
|
231
|
-
const { permission, roles } = await this.
|
|
232
|
-
await this.
|
|
165
|
+
const { permission, roles } = await this.createPermissionEntity(
|
|
166
|
+
await this.extractCreatePermissionEntityToEntityData(
|
|
167
|
+
createPermissionEntity,
|
|
168
|
+
em,
|
|
169
|
+
...args
|
|
170
|
+
)
|
|
233
171
|
);
|
|
234
172
|
|
|
235
173
|
if (em) {
|
|
@@ -238,13 +176,13 @@ export class BasePermissionService<
|
|
|
238
176
|
await this.em.persistAndFlush([permission, ...roles]);
|
|
239
177
|
}
|
|
240
178
|
|
|
241
|
-
return this.
|
|
179
|
+
return this.mappers.PermissionMapper.toDto(permission);
|
|
242
180
|
}
|
|
243
181
|
|
|
244
182
|
async createBatchPermissions(
|
|
245
|
-
permissionDtos:
|
|
183
|
+
permissionDtos: CreatePermissionDto[],
|
|
246
184
|
em?: EntityManager
|
|
247
|
-
): Promise<
|
|
185
|
+
): Promise<MapperDomains['PermissionMapper'][]> {
|
|
248
186
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
249
187
|
this.openTelemetryCollector.info(
|
|
250
188
|
'Creating batch permissions',
|
|
@@ -253,13 +191,27 @@ export class BasePermissionService<
|
|
|
253
191
|
}
|
|
254
192
|
const rolesCache: Record<string, MapperEntities['RoleEntityMapper']> = {};
|
|
255
193
|
const permissions: MapperEntities['PermissionMapper'][] = [];
|
|
256
|
-
permissionDtos.map(async (
|
|
257
|
-
const { permission, roles } = await this.
|
|
258
|
-
await this.
|
|
259
|
-
|
|
194
|
+
permissionDtos.map(async (createPermissionEntity) => {
|
|
195
|
+
const { permission, roles } = await this.createPermissionEntity(
|
|
196
|
+
await this.extractCreatePermissionEntityToEntityData(
|
|
197
|
+
createPermissionEntity,
|
|
260
198
|
em
|
|
261
199
|
)
|
|
262
200
|
);
|
|
201
|
+
await Promise.all(
|
|
202
|
+
roles.map(async (role) => {
|
|
203
|
+
if (role.permissions.isInitialized()) {
|
|
204
|
+
return role.permissions.init();
|
|
205
|
+
}
|
|
206
|
+
})
|
|
207
|
+
);
|
|
208
|
+
await Promise.all(
|
|
209
|
+
roles.map(async (role) => {
|
|
210
|
+
if (role.permissions.isInitialized()) {
|
|
211
|
+
return role.permissions.init();
|
|
212
|
+
}
|
|
213
|
+
})
|
|
214
|
+
);
|
|
263
215
|
roles.forEach((role) => {
|
|
264
216
|
if (
|
|
265
217
|
rolesCache[role.id] &&
|
|
@@ -286,7 +238,7 @@ export class BasePermissionService<
|
|
|
286
238
|
|
|
287
239
|
return Promise.all(
|
|
288
240
|
permissions.map(async (permission) =>
|
|
289
|
-
this.
|
|
241
|
+
this.mappers.PermissionMapper.toDto(permission)
|
|
290
242
|
)
|
|
291
243
|
);
|
|
292
244
|
}
|
|
@@ -294,12 +246,12 @@ export class BasePermissionService<
|
|
|
294
246
|
async getPermission(
|
|
295
247
|
idDto: IdDto,
|
|
296
248
|
em?: EntityManager
|
|
297
|
-
): Promise<
|
|
249
|
+
): Promise<MapperDomains['PermissionMapper']> {
|
|
298
250
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
299
251
|
this.openTelemetryCollector.info('Getting permission', idDto);
|
|
300
252
|
}
|
|
301
253
|
const permission = await (em ?? this.em).findOneOrFail('Permission', idDto);
|
|
302
|
-
return this.
|
|
254
|
+
return this.mappers.PermissionMapper.toDto(
|
|
303
255
|
permission as MapperEntities['PermissionMapper']
|
|
304
256
|
);
|
|
305
257
|
}
|
|
@@ -307,13 +259,13 @@ export class BasePermissionService<
|
|
|
307
259
|
async getBatchPermissions(
|
|
308
260
|
idsDto: IdsDto,
|
|
309
261
|
em?: EntityManager
|
|
310
|
-
): Promise<
|
|
262
|
+
): Promise<MapperDomains['PermissionMapper'][]> {
|
|
311
263
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
312
264
|
this.openTelemetryCollector.info('Getting batch permissions', idsDto);
|
|
313
265
|
}
|
|
314
266
|
return Promise.all(
|
|
315
267
|
(await (em ?? this.em).find('Permission', idsDto)).map((permission) =>
|
|
316
|
-
this.
|
|
268
|
+
this.mappers.PermissionMapper.toDto(
|
|
317
269
|
permission as MapperEntities['PermissionMapper']
|
|
318
270
|
)
|
|
319
271
|
)
|
|
@@ -322,17 +274,18 @@ export class BasePermissionService<
|
|
|
322
274
|
|
|
323
275
|
// start: updatePermission helper functions
|
|
324
276
|
private updatePermissionDto = async (
|
|
325
|
-
permissionDto:
|
|
326
|
-
em?: EntityManager
|
|
277
|
+
permissionDto: UpdatePermissionDto,
|
|
278
|
+
em?: EntityManager,
|
|
279
|
+
...args: unknown[]
|
|
327
280
|
): Promise<{
|
|
328
281
|
permission: MapperEntities['PermissionMapper'];
|
|
329
282
|
roles: MapperEntities['RoleEntityMapper'][];
|
|
330
283
|
}> => {
|
|
331
|
-
const permission =
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
284
|
+
const permission = await this.mappers.UpdatePermissionMapper.toEntity(
|
|
285
|
+
permissionDto,
|
|
286
|
+
em ?? this.em,
|
|
287
|
+
...args
|
|
288
|
+
);
|
|
336
289
|
const addToRoles = permissionDto.addToRolesIds
|
|
337
290
|
? await this.getBatchRoles({ ids: permissionDto.addToRolesIds }, em)
|
|
338
291
|
: [];
|
|
@@ -357,9 +310,9 @@ export class BasePermissionService<
|
|
|
357
310
|
// end: updatePermission helper functions
|
|
358
311
|
|
|
359
312
|
async updatePermission(
|
|
360
|
-
permissionDto:
|
|
313
|
+
permissionDto: UpdatePermissionDto,
|
|
361
314
|
em?: EntityManager
|
|
362
|
-
): Promise<
|
|
315
|
+
): Promise<MapperDomains['PermissionMapper']> {
|
|
363
316
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
364
317
|
this.openTelemetryCollector.info('Updating permission', permissionDto);
|
|
365
318
|
}
|
|
@@ -372,13 +325,13 @@ export class BasePermissionService<
|
|
|
372
325
|
await this.em.persistAndFlush(entities);
|
|
373
326
|
}
|
|
374
327
|
|
|
375
|
-
return this.
|
|
328
|
+
return this.mappers.PermissionMapper.toDto(permission);
|
|
376
329
|
}
|
|
377
330
|
|
|
378
331
|
async updateBatchPermissions(
|
|
379
|
-
permissionDtos:
|
|
332
|
+
permissionDtos: UpdatePermissionDto[],
|
|
380
333
|
em?: EntityManager
|
|
381
|
-
): Promise<
|
|
334
|
+
): Promise<MapperDomains['PermissionMapper'][]> {
|
|
382
335
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
383
336
|
this.openTelemetryCollector.info(
|
|
384
337
|
'Updating batch permissions',
|
|
@@ -418,7 +371,7 @@ export class BasePermissionService<
|
|
|
418
371
|
|
|
419
372
|
return Promise.all(
|
|
420
373
|
permissions.map((permission) =>
|
|
421
|
-
this.
|
|
374
|
+
this.mappers.PermissionMapper.toDto(permission)
|
|
422
375
|
)
|
|
423
376
|
);
|
|
424
377
|
}
|