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