@forklaunch/implementation-iam-base 0.1.17 → 0.2.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/eject/services/organization.service.ts +13 -13
- package/lib/eject/services/permission.service.ts +35 -28
- package/lib/eject/services/role.service.ts +29 -29
- package/lib/eject/services/user.service.ts +37 -32
- package/lib/services/organization.service.d.ts +6 -6
- package/lib/services/organization.service.d.ts.map +1 -1
- package/lib/services/organization.service.js +10 -10
- package/lib/services/permission.service.d.ts +6 -6
- package/lib/services/permission.service.d.ts.map +1 -1
- package/lib/services/permission.service.js +32 -25
- package/lib/services/role.service.d.ts +2 -2
- package/lib/services/role.service.d.ts.map +1 -1
- package/lib/services/role.service.js +27 -22
- package/lib/services/user.service.d.ts +10 -10
- package/lib/services/user.service.d.ts.map +1 -1
- package/lib/services/user.service.js +30 -25
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -6
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { IdDto, InstanceTypeRecord } from '@forklaunch/common';
|
|
2
|
+
import {
|
|
3
|
+
MetricsDefinition,
|
|
4
|
+
OpenTelemetryCollector
|
|
5
|
+
} from '@forklaunch/core/http';
|
|
2
6
|
import {
|
|
3
7
|
InternalDtoMapper,
|
|
4
8
|
RequestDtoMapperConstructor,
|
|
5
9
|
ResponseDtoMapperConstructor,
|
|
6
10
|
transformIntoInternalDtoMapper
|
|
7
11
|
} from '@forklaunch/core/mappers';
|
|
8
|
-
import {
|
|
9
|
-
MetricsDefinition,
|
|
10
|
-
OpenTelemetryCollector
|
|
11
|
-
} from '@forklaunch/core/http';
|
|
12
12
|
import { MapNestedDtoArraysToCollections } from '@forklaunch/core/services';
|
|
13
13
|
import { OrganizationService } from '@forklaunch/interfaces-iam/interfaces';
|
|
14
14
|
import {
|
|
@@ -61,8 +61,8 @@ export class BaseOrganizationService<
|
|
|
61
61
|
}
|
|
62
62
|
> implements OrganizationService<OrganizationStatus>
|
|
63
63
|
{
|
|
64
|
-
#
|
|
65
|
-
InstanceTypeRecord<typeof this.
|
|
64
|
+
#mappers: InternalDtoMapper<
|
|
65
|
+
InstanceTypeRecord<typeof this.mappers>,
|
|
66
66
|
Entities,
|
|
67
67
|
Dto
|
|
68
68
|
>;
|
|
@@ -71,7 +71,7 @@ export class BaseOrganizationService<
|
|
|
71
71
|
public em: EntityManager,
|
|
72
72
|
protected openTelemetryCollector: OpenTelemetryCollector<Metrics>,
|
|
73
73
|
protected schemaValidator: SchemaValidator,
|
|
74
|
-
protected
|
|
74
|
+
protected mappers: {
|
|
75
75
|
OrganizationDtoMapper: ResponseDtoMapperConstructor<
|
|
76
76
|
SchemaValidator,
|
|
77
77
|
Dto['OrganizationDtoMapper'],
|
|
@@ -89,7 +89,7 @@ export class BaseOrganizationService<
|
|
|
89
89
|
>;
|
|
90
90
|
}
|
|
91
91
|
) {
|
|
92
|
-
this.#
|
|
92
|
+
this.#mappers = transformIntoInternalDtoMapper(mappers, schemaValidator);
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
async createOrganization(
|
|
@@ -98,14 +98,14 @@ export class BaseOrganizationService<
|
|
|
98
98
|
): Promise<Dto['OrganizationDtoMapper']> {
|
|
99
99
|
this.openTelemetryCollector.log('info', 'Creating organization');
|
|
100
100
|
const organization =
|
|
101
|
-
this.#
|
|
101
|
+
await this.#mappers.CreateOrganizationDtoMapper.deserializeDtoToEntity(
|
|
102
102
|
organizationDto
|
|
103
103
|
);
|
|
104
104
|
await (em ?? this.em).transactional(async (innerEm) => {
|
|
105
105
|
await innerEm.persist(organization);
|
|
106
106
|
});
|
|
107
107
|
|
|
108
|
-
return this.#
|
|
108
|
+
return this.#mappers.OrganizationDtoMapper.serializeEntityToDto(
|
|
109
109
|
organization
|
|
110
110
|
);
|
|
111
111
|
}
|
|
@@ -118,7 +118,7 @@ export class BaseOrganizationService<
|
|
|
118
118
|
'Organization',
|
|
119
119
|
idDto
|
|
120
120
|
);
|
|
121
|
-
return this.#
|
|
121
|
+
return this.#mappers.OrganizationDtoMapper.serializeEntityToDto(
|
|
122
122
|
organization as Entities['OrganizationDtoMapper']
|
|
123
123
|
);
|
|
124
124
|
}
|
|
@@ -128,11 +128,11 @@ export class BaseOrganizationService<
|
|
|
128
128
|
em?: EntityManager
|
|
129
129
|
): Promise<Dto['OrganizationDtoMapper']> {
|
|
130
130
|
const updatedOrganization =
|
|
131
|
-
this.#
|
|
131
|
+
await this.#mappers.UpdateOrganizationDtoMapper.deserializeDtoToEntity(
|
|
132
132
|
organizationDto
|
|
133
133
|
);
|
|
134
134
|
await (em ?? this.em).upsert(updatedOrganization);
|
|
135
|
-
return this.#
|
|
135
|
+
return this.#mappers.OrganizationDtoMapper.serializeEntityToDto(
|
|
136
136
|
updatedOrganization
|
|
137
137
|
);
|
|
138
138
|
}
|
|
@@ -4,16 +4,16 @@ import {
|
|
|
4
4
|
} from '@forklaunch/interfaces-iam/interfaces';
|
|
5
5
|
|
|
6
6
|
import { IdDto, IdsDto, InstanceTypeRecord } from '@forklaunch/common';
|
|
7
|
+
import {
|
|
8
|
+
MetricsDefinition,
|
|
9
|
+
OpenTelemetryCollector
|
|
10
|
+
} from '@forklaunch/core/http';
|
|
7
11
|
import {
|
|
8
12
|
InternalDtoMapper,
|
|
9
13
|
RequestDtoMapperConstructor,
|
|
10
14
|
ResponseDtoMapperConstructor,
|
|
11
15
|
transformIntoInternalDtoMapper
|
|
12
16
|
} from '@forklaunch/core/mappers';
|
|
13
|
-
import {
|
|
14
|
-
MetricsDefinition,
|
|
15
|
-
OpenTelemetryCollector
|
|
16
|
-
} from '@forklaunch/core/http';
|
|
17
17
|
import { MapNestedDtoArraysToCollections } from '@forklaunch/core/services';
|
|
18
18
|
import {
|
|
19
19
|
CreatePermissionDto,
|
|
@@ -51,8 +51,8 @@ export class BasePermissionService<
|
|
|
51
51
|
}
|
|
52
52
|
> implements PermissionService
|
|
53
53
|
{
|
|
54
|
-
#
|
|
55
|
-
InstanceTypeRecord<typeof this.
|
|
54
|
+
#mappers: InternalDtoMapper<
|
|
55
|
+
InstanceTypeRecord<typeof this.mappers>,
|
|
56
56
|
Entities,
|
|
57
57
|
Dto
|
|
58
58
|
>;
|
|
@@ -62,7 +62,7 @@ export class BasePermissionService<
|
|
|
62
62
|
protected roleServiceFactory: () => RoleService,
|
|
63
63
|
protected openTelemetryCollector: OpenTelemetryCollector<Metrics>,
|
|
64
64
|
protected schemaValidator: SchemaValidator,
|
|
65
|
-
protected
|
|
65
|
+
protected mappers: {
|
|
66
66
|
PermissionDtoMapper: ResponseDtoMapperConstructor<
|
|
67
67
|
SchemaValidator,
|
|
68
68
|
Dto['PermissionDtoMapper'],
|
|
@@ -85,7 +85,7 @@ export class BasePermissionService<
|
|
|
85
85
|
>;
|
|
86
86
|
}
|
|
87
87
|
) {
|
|
88
|
-
this.#
|
|
88
|
+
this.#mappers = transformIntoInternalDtoMapper(mappers, schemaValidator);
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
// start: global helper functions
|
|
@@ -93,7 +93,7 @@ export class BasePermissionService<
|
|
|
93
93
|
roles: Entities['RoleDtoMapper'][],
|
|
94
94
|
permissions: Entities['PermissionDtoMapper'][]
|
|
95
95
|
): Promise<Entities['RoleDtoMapper'][]> {
|
|
96
|
-
return
|
|
96
|
+
return Promise.all(
|
|
97
97
|
roles.map(async (role) => {
|
|
98
98
|
permissions.forEach((permission) => role.permissions.add(permission));
|
|
99
99
|
return role;
|
|
@@ -105,7 +105,7 @@ export class BasePermissionService<
|
|
|
105
105
|
roles: Entities['RoleDtoMapper'][],
|
|
106
106
|
permissions: Entities['PermissionDtoMapper'][]
|
|
107
107
|
): Promise<Entities['RoleDtoMapper'][]> {
|
|
108
|
-
return
|
|
108
|
+
return Promise.all(
|
|
109
109
|
roles.map(async (role) => {
|
|
110
110
|
permissions.forEach((permission) =>
|
|
111
111
|
role.permissions.remove(permission)
|
|
@@ -120,12 +120,14 @@ export class BasePermissionService<
|
|
|
120
120
|
em?: EntityManager
|
|
121
121
|
): Promise<Entities['RoleDtoMapper'][]> {
|
|
122
122
|
return roleIds
|
|
123
|
-
?
|
|
124
|
-
(
|
|
125
|
-
|
|
126
|
-
this
|
|
127
|
-
|
|
128
|
-
|
|
123
|
+
? await Promise.all(
|
|
124
|
+
(await this.roleServiceFactory().getBatchRoles(roleIds, em)).map(
|
|
125
|
+
async (role) => {
|
|
126
|
+
return (em ?? this.em).merge(
|
|
127
|
+
await this.#mappers.RoleDtoMapper.deserializeDtoToEntity(role)
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
)
|
|
129
131
|
)
|
|
130
132
|
: [];
|
|
131
133
|
}
|
|
@@ -159,7 +161,7 @@ export class BasePermissionService<
|
|
|
159
161
|
}> {
|
|
160
162
|
return {
|
|
161
163
|
permission: (em ?? this.em).merge(
|
|
162
|
-
this.#
|
|
164
|
+
await this.#mappers.CreatePermissionDtoMapper.deserializeDtoToEntity(
|
|
163
165
|
permissionDto
|
|
164
166
|
)
|
|
165
167
|
),
|
|
@@ -180,7 +182,7 @@ export class BasePermissionService<
|
|
|
180
182
|
await (em ?? this.em).transactional(async (innerEm) => {
|
|
181
183
|
await innerEm.persist([permission, ...roles]);
|
|
182
184
|
});
|
|
183
|
-
return this.#
|
|
185
|
+
return this.#mappers.PermissionDtoMapper.serializeEntityToDto(permission);
|
|
184
186
|
}
|
|
185
187
|
|
|
186
188
|
async createBatchPermissions(
|
|
@@ -219,8 +221,10 @@ export class BasePermissionService<
|
|
|
219
221
|
]);
|
|
220
222
|
});
|
|
221
223
|
|
|
222
|
-
return
|
|
223
|
-
|
|
224
|
+
return Promise.all(
|
|
225
|
+
permissions.map(async (permission) =>
|
|
226
|
+
this.#mappers.PermissionDtoMapper.serializeEntityToDto(permission)
|
|
227
|
+
)
|
|
224
228
|
);
|
|
225
229
|
}
|
|
226
230
|
|
|
@@ -229,7 +233,7 @@ export class BasePermissionService<
|
|
|
229
233
|
em?: EntityManager
|
|
230
234
|
): Promise<Dto['PermissionDtoMapper']> {
|
|
231
235
|
const permission = await (em ?? this.em).findOneOrFail('Permission', idDto);
|
|
232
|
-
return this.#
|
|
236
|
+
return this.#mappers.PermissionDtoMapper.serializeEntityToDto(
|
|
233
237
|
permission as Entities['PermissionDtoMapper']
|
|
234
238
|
);
|
|
235
239
|
}
|
|
@@ -238,11 +242,12 @@ export class BasePermissionService<
|
|
|
238
242
|
idsDto: IdsDto,
|
|
239
243
|
em?: EntityManager
|
|
240
244
|
): Promise<Dto['PermissionDtoMapper'][]> {
|
|
241
|
-
return
|
|
242
|
-
(permission) =>
|
|
243
|
-
this.#
|
|
245
|
+
return Promise.all(
|
|
246
|
+
(await (em ?? this.em).find('Permission', idsDto)).map((permission) =>
|
|
247
|
+
this.#mappers.PermissionDtoMapper.serializeEntityToDto(
|
|
244
248
|
permission as Entities['PermissionDtoMapper']
|
|
245
249
|
)
|
|
250
|
+
)
|
|
246
251
|
);
|
|
247
252
|
}
|
|
248
253
|
|
|
@@ -255,7 +260,7 @@ export class BasePermissionService<
|
|
|
255
260
|
roles: Entities['RoleDtoMapper'][];
|
|
256
261
|
}> => {
|
|
257
262
|
const permission =
|
|
258
|
-
this.#
|
|
263
|
+
await this.#mappers.UpdatePermissionDtoMapper.deserializeDtoToEntity(
|
|
259
264
|
permissionDto
|
|
260
265
|
);
|
|
261
266
|
const addToRoles = permissionDto.addToRolesIds
|
|
@@ -290,7 +295,7 @@ export class BasePermissionService<
|
|
|
290
295
|
if (!em) {
|
|
291
296
|
this.em.flush();
|
|
292
297
|
}
|
|
293
|
-
return this.#
|
|
298
|
+
return this.#mappers.PermissionDtoMapper.serializeEntityToDto(permission);
|
|
294
299
|
}
|
|
295
300
|
|
|
296
301
|
async updateBatchPermissions(
|
|
@@ -325,8 +330,10 @@ export class BasePermissionService<
|
|
|
325
330
|
]);
|
|
326
331
|
});
|
|
327
332
|
|
|
328
|
-
return
|
|
329
|
-
|
|
333
|
+
return Promise.all(
|
|
334
|
+
permissions.map((permission) =>
|
|
335
|
+
this.#mappers.PermissionDtoMapper.serializeEntityToDto(permission)
|
|
336
|
+
)
|
|
330
337
|
);
|
|
331
338
|
}
|
|
332
339
|
|
|
@@ -55,8 +55,8 @@ export class BaseRoleService<
|
|
|
55
55
|
}
|
|
56
56
|
> implements RoleService
|
|
57
57
|
{
|
|
58
|
-
#
|
|
59
|
-
InstanceTypeRecord<typeof this.
|
|
58
|
+
#mappers: InternalDtoMapper<
|
|
59
|
+
InstanceTypeRecord<typeof this.mappers>,
|
|
60
60
|
Entities,
|
|
61
61
|
Dto
|
|
62
62
|
>;
|
|
@@ -65,7 +65,7 @@ export class BaseRoleService<
|
|
|
65
65
|
public em: EntityManager,
|
|
66
66
|
protected openTelemetryCollector: OpenTelemetryCollector<Metrics>,
|
|
67
67
|
protected schemaValidator: SchemaValidator,
|
|
68
|
-
protected
|
|
68
|
+
protected mappers: {
|
|
69
69
|
RoleDtoMapper: ResponseDtoMapperConstructor<
|
|
70
70
|
SchemaValidator,
|
|
71
71
|
Dto['RoleDtoMapper'],
|
|
@@ -83,20 +83,17 @@ export class BaseRoleService<
|
|
|
83
83
|
>;
|
|
84
84
|
}
|
|
85
85
|
) {
|
|
86
|
-
this.#
|
|
86
|
+
this.#mappers = transformIntoInternalDtoMapper(mappers, schemaValidator);
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
async createRole(
|
|
90
90
|
roleDto: Dto['CreateRoleDtoMapper'],
|
|
91
91
|
em?: EntityManager
|
|
92
92
|
): Promise<Dto['RoleDtoMapper']> {
|
|
93
|
-
// TODO: Think about removing static method here, since we need specific args
|
|
94
93
|
const role =
|
|
95
|
-
this.#
|
|
94
|
+
await this.#mappers.CreateRoleDtoMapper.deserializeDtoToEntity(roleDto);
|
|
96
95
|
await (em ?? this.em).transactional((em) => em.persist(role));
|
|
97
|
-
return this.#
|
|
98
|
-
role as Entities['RoleDtoMapper']
|
|
99
|
-
);
|
|
96
|
+
return this.#mappers.RoleDtoMapper.serializeEntityToDto(role);
|
|
100
97
|
}
|
|
101
98
|
|
|
102
99
|
async createBatchRoles(
|
|
@@ -105,13 +102,13 @@ export class BaseRoleService<
|
|
|
105
102
|
): Promise<Dto['RoleDtoMapper'][]> {
|
|
106
103
|
const roles = await Promise.all(
|
|
107
104
|
roleDtos.map(async (roleDto) =>
|
|
108
|
-
this.#
|
|
105
|
+
this.#mappers.CreateRoleDtoMapper.deserializeDtoToEntity(roleDto)
|
|
109
106
|
)
|
|
110
107
|
);
|
|
111
108
|
await (em ?? this.em).transactional((em) => em.persist(roles));
|
|
112
|
-
return
|
|
113
|
-
|
|
114
|
-
role
|
|
109
|
+
return Promise.all(
|
|
110
|
+
roles.map((role) =>
|
|
111
|
+
this.#mappers.RoleDtoMapper.serializeEntityToDto(role)
|
|
115
112
|
)
|
|
116
113
|
);
|
|
117
114
|
}
|
|
@@ -120,19 +117,21 @@ export class BaseRoleService<
|
|
|
120
117
|
const role = await (em ?? this.em).findOneOrFail('Role', idDto, {
|
|
121
118
|
populate: ['id', '*']
|
|
122
119
|
});
|
|
123
|
-
return this.#
|
|
120
|
+
return this.#mappers.RoleDtoMapper.serializeEntityToDto(
|
|
124
121
|
role as Entities['RoleDtoMapper']
|
|
125
122
|
);
|
|
126
123
|
}
|
|
127
124
|
|
|
128
125
|
async getBatchRoles(idsDto: IdsDto, em?: EntityManager): Promise<RoleDto[]> {
|
|
129
|
-
return (
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
126
|
+
return Promise.all(
|
|
127
|
+
(
|
|
128
|
+
await (em ?? this.em).find('Role', idsDto, {
|
|
129
|
+
populate: ['id', '*']
|
|
130
|
+
})
|
|
131
|
+
).map((role) =>
|
|
132
|
+
this.#mappers.RoleDtoMapper.serializeEntityToDto(
|
|
133
|
+
role as Entities['RoleDtoMapper']
|
|
134
|
+
)
|
|
136
135
|
)
|
|
137
136
|
);
|
|
138
137
|
}
|
|
@@ -141,13 +140,12 @@ export class BaseRoleService<
|
|
|
141
140
|
roleDto: Dto['UpdateRoleDtoMapper'],
|
|
142
141
|
em?: EntityManager
|
|
143
142
|
): Promise<Dto['RoleDtoMapper']> {
|
|
144
|
-
let role =
|
|
145
|
-
roleDto
|
|
146
|
-
) as Entities['RoleDtoMapper'];
|
|
143
|
+
let role =
|
|
144
|
+
await this.#mappers.UpdateRoleDtoMapper.deserializeDtoToEntity(roleDto);
|
|
147
145
|
await (em ?? this.em).transactional(async (em) => {
|
|
148
146
|
role = (await em.upsert('Role', role)) as Entities['RoleDtoMapper'];
|
|
149
147
|
});
|
|
150
|
-
return this.#
|
|
148
|
+
return this.#mappers.RoleDtoMapper.serializeEntityToDto(role);
|
|
151
149
|
}
|
|
152
150
|
|
|
153
151
|
async updateBatchRoles(
|
|
@@ -156,15 +154,17 @@ export class BaseRoleService<
|
|
|
156
154
|
): Promise<Dto['RoleDtoMapper'][]> {
|
|
157
155
|
let roles = await Promise.all(
|
|
158
156
|
roleDtos.map(async (roleDto) =>
|
|
159
|
-
this.#
|
|
157
|
+
this.#mappers.UpdateRoleDtoMapper.deserializeDtoToEntity(roleDto)
|
|
160
158
|
)
|
|
161
159
|
);
|
|
162
160
|
await (em ?? this.em).transactional(async (em) => {
|
|
163
161
|
roles = await em.upsertMany('Role', roles);
|
|
164
162
|
});
|
|
165
|
-
return
|
|
166
|
-
|
|
167
|
-
|
|
163
|
+
return Promise.all(
|
|
164
|
+
roles.map((role) =>
|
|
165
|
+
this.#mappers.RoleDtoMapper.serializeEntityToDto(
|
|
166
|
+
role as Entities['RoleDtoMapper']
|
|
167
|
+
)
|
|
168
168
|
)
|
|
169
169
|
);
|
|
170
170
|
}
|
|
@@ -5,16 +5,16 @@ import {
|
|
|
5
5
|
} from '@forklaunch/interfaces-iam/interfaces';
|
|
6
6
|
|
|
7
7
|
import { IdDto, IdsDto, InstanceTypeRecord } from '@forklaunch/common';
|
|
8
|
+
import {
|
|
9
|
+
MetricsDefinition,
|
|
10
|
+
OpenTelemetryCollector
|
|
11
|
+
} from '@forklaunch/core/http';
|
|
8
12
|
import {
|
|
9
13
|
InternalDtoMapper,
|
|
10
14
|
RequestDtoMapperConstructor,
|
|
11
15
|
ResponseDtoMapperConstructor,
|
|
12
16
|
transformIntoInternalDtoMapper
|
|
13
17
|
} from '@forklaunch/core/mappers';
|
|
14
|
-
import {
|
|
15
|
-
MetricsDefinition,
|
|
16
|
-
OpenTelemetryCollector
|
|
17
|
-
} from '@forklaunch/core/http';
|
|
18
18
|
import { MapNestedDtoArraysToCollections } from '@forklaunch/core/services';
|
|
19
19
|
import {
|
|
20
20
|
CreateUserDto,
|
|
@@ -48,8 +48,8 @@ export class BaseUserService<
|
|
|
48
48
|
}
|
|
49
49
|
> implements UserService
|
|
50
50
|
{
|
|
51
|
-
#
|
|
52
|
-
InstanceTypeRecord<typeof this.
|
|
51
|
+
#mappers: InternalDtoMapper<
|
|
52
|
+
InstanceTypeRecord<typeof this.mappers>,
|
|
53
53
|
Entities,
|
|
54
54
|
Dto
|
|
55
55
|
>;
|
|
@@ -61,7 +61,7 @@ export class BaseUserService<
|
|
|
61
61
|
protected organizationServiceFactory: () => OrganizationService<OrganizationStatus>,
|
|
62
62
|
protected openTelemetryCollector: OpenTelemetryCollector<Metrics>,
|
|
63
63
|
protected schemaValidator: SchemaValidator,
|
|
64
|
-
protected
|
|
64
|
+
protected mappers: {
|
|
65
65
|
UserDtoMapper: ResponseDtoMapperConstructor<
|
|
66
66
|
SchemaValidator,
|
|
67
67
|
Dto['UserDtoMapper'],
|
|
@@ -74,7 +74,7 @@ export class BaseUserService<
|
|
|
74
74
|
(
|
|
75
75
|
dto: never,
|
|
76
76
|
passwordEncryptionPublicKeyPath: string
|
|
77
|
-
) => Entities['UpdateUserDtoMapper']
|
|
77
|
+
) => Promise<Entities['UpdateUserDtoMapper']>
|
|
78
78
|
>;
|
|
79
79
|
UpdateUserDtoMapper: RequestDtoMapperConstructor<
|
|
80
80
|
SchemaValidator,
|
|
@@ -83,26 +83,25 @@ export class BaseUserService<
|
|
|
83
83
|
(
|
|
84
84
|
dto: never,
|
|
85
85
|
passwordEncryptionPublicKeyPath: string
|
|
86
|
-
) => Entities['UpdateUserDtoMapper']
|
|
86
|
+
) => Promise<Entities['UpdateUserDtoMapper']>
|
|
87
87
|
>;
|
|
88
88
|
}
|
|
89
89
|
) {
|
|
90
|
-
this.#
|
|
90
|
+
this.#mappers = transformIntoInternalDtoMapper(mappers, schemaValidator);
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
async createUser(
|
|
94
94
|
userDto: Dto['CreateUserDtoMapper'],
|
|
95
95
|
em?: EntityManager
|
|
96
96
|
): Promise<Dto['UserDtoMapper']> {
|
|
97
|
-
const user =
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
);
|
|
97
|
+
const user = await this.#mappers.CreateUserDtoMapper.deserializeDtoToEntity(
|
|
98
|
+
userDto,
|
|
99
|
+
this.passwordEncryptionPublicKeyPath
|
|
100
|
+
);
|
|
102
101
|
((await em) ?? this.em).transactional(async (em) => {
|
|
103
102
|
await em.persist(user);
|
|
104
103
|
});
|
|
105
|
-
return this.#
|
|
104
|
+
return this.#mappers.UserDtoMapper.serializeEntityToDto(user);
|
|
106
105
|
}
|
|
107
106
|
|
|
108
107
|
async createBatchUsers(
|
|
@@ -111,7 +110,7 @@ export class BaseUserService<
|
|
|
111
110
|
): Promise<Dto['UserDtoMapper'][]> {
|
|
112
111
|
const users = await Promise.all(
|
|
113
112
|
userDtos.map(async (createUserDto) =>
|
|
114
|
-
this.#
|
|
113
|
+
this.#mappers.CreateUserDtoMapper.deserializeDtoToEntity(
|
|
115
114
|
createUserDto,
|
|
116
115
|
this.passwordEncryptionPublicKeyPath
|
|
117
116
|
)
|
|
@@ -121,8 +120,10 @@ export class BaseUserService<
|
|
|
121
120
|
await em.persist(users);
|
|
122
121
|
});
|
|
123
122
|
|
|
124
|
-
return
|
|
125
|
-
|
|
123
|
+
return Promise.all(
|
|
124
|
+
users.map((user) =>
|
|
125
|
+
this.#mappers.UserDtoMapper.serializeEntityToDto(user)
|
|
126
|
+
)
|
|
126
127
|
);
|
|
127
128
|
}
|
|
128
129
|
|
|
@@ -133,7 +134,7 @@ export class BaseUserService<
|
|
|
133
134
|
const user = await (em ?? this.em).findOneOrFail('User', idDto, {
|
|
134
135
|
populate: ['id', '*']
|
|
135
136
|
});
|
|
136
|
-
return this.#
|
|
137
|
+
return this.#mappers.UserDtoMapper.serializeEntityToDto(
|
|
137
138
|
user as Entities['UserDtoMapper']
|
|
138
139
|
);
|
|
139
140
|
}
|
|
@@ -142,13 +143,15 @@ export class BaseUserService<
|
|
|
142
143
|
idsDto: IdsDto,
|
|
143
144
|
em?: EntityManager
|
|
144
145
|
): Promise<Dto['UserDtoMapper'][]> {
|
|
145
|
-
return (
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
146
|
+
return Promise.all(
|
|
147
|
+
(
|
|
148
|
+
await (em ?? this.em).find('User', idsDto, {
|
|
149
|
+
populate: ['id', '*']
|
|
150
|
+
})
|
|
151
|
+
).map((user) =>
|
|
152
|
+
this.#mappers.UserDtoMapper.serializeEntityToDto(
|
|
153
|
+
user as Entities['UserDtoMapper']
|
|
154
|
+
)
|
|
152
155
|
)
|
|
153
156
|
);
|
|
154
157
|
}
|
|
@@ -157,14 +160,14 @@ export class BaseUserService<
|
|
|
157
160
|
userDto: Dto['UpdateUserDtoMapper'],
|
|
158
161
|
em?: EntityManager
|
|
159
162
|
): Promise<Dto['UserDtoMapper']> {
|
|
160
|
-
let user = this.#
|
|
163
|
+
let user = await this.#mappers.UpdateUserDtoMapper.deserializeDtoToEntity(
|
|
161
164
|
userDto,
|
|
162
165
|
this.passwordEncryptionPublicKeyPath
|
|
163
166
|
);
|
|
164
167
|
await (em ?? this.em).transactional(async (localEm) => {
|
|
165
168
|
user = await localEm.upsert(user);
|
|
166
169
|
});
|
|
167
|
-
return this.#
|
|
170
|
+
return this.#mappers.UserDtoMapper.serializeEntityToDto(user);
|
|
168
171
|
}
|
|
169
172
|
|
|
170
173
|
async updateBatchUsers(
|
|
@@ -173,7 +176,7 @@ export class BaseUserService<
|
|
|
173
176
|
): Promise<Dto['UserDtoMapper'][]> {
|
|
174
177
|
let users = await Promise.all(
|
|
175
178
|
userDtos.map(async (updateUserDto) =>
|
|
176
|
-
this.#
|
|
179
|
+
this.#mappers.UpdateUserDtoMapper.deserializeDtoToEntity(
|
|
177
180
|
updateUserDto,
|
|
178
181
|
this.passwordEncryptionPublicKeyPath
|
|
179
182
|
)
|
|
@@ -182,8 +185,10 @@ export class BaseUserService<
|
|
|
182
185
|
await (em ?? this.em).transactional(async (localEm) => {
|
|
183
186
|
users = await localEm.upsertMany(users);
|
|
184
187
|
});
|
|
185
|
-
return
|
|
186
|
-
|
|
188
|
+
return Promise.all(
|
|
189
|
+
users.map((user) =>
|
|
190
|
+
this.#mappers.UserDtoMapper.serializeEntityToDto(user)
|
|
191
|
+
)
|
|
187
192
|
);
|
|
188
193
|
}
|
|
189
194
|
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { IdDto } from '@forklaunch/common';
|
|
2
|
-
import {
|
|
3
|
-
RequestDtoMapperConstructor,
|
|
4
|
-
ResponseDtoMapperConstructor
|
|
5
|
-
} from '@forklaunch/core/mappers';
|
|
6
2
|
import {
|
|
7
3
|
MetricsDefinition,
|
|
8
4
|
OpenTelemetryCollector
|
|
9
5
|
} from '@forklaunch/core/http';
|
|
6
|
+
import {
|
|
7
|
+
RequestDtoMapperConstructor,
|
|
8
|
+
ResponseDtoMapperConstructor
|
|
9
|
+
} from '@forklaunch/core/mappers';
|
|
10
10
|
import { MapNestedDtoArraysToCollections } from '@forklaunch/core/services';
|
|
11
11
|
import { OrganizationService } from '@forklaunch/interfaces-iam/interfaces';
|
|
12
12
|
import {
|
|
@@ -62,7 +62,7 @@ export declare class BaseOrganizationService<
|
|
|
62
62
|
em: EntityManager;
|
|
63
63
|
protected openTelemetryCollector: OpenTelemetryCollector<Metrics>;
|
|
64
64
|
protected schemaValidator: SchemaValidator;
|
|
65
|
-
protected
|
|
65
|
+
protected mappers: {
|
|
66
66
|
OrganizationDtoMapper: ResponseDtoMapperConstructor<
|
|
67
67
|
SchemaValidator,
|
|
68
68
|
Dto['OrganizationDtoMapper'],
|
|
@@ -83,7 +83,7 @@ export declare class BaseOrganizationService<
|
|
|
83
83
|
em: EntityManager,
|
|
84
84
|
openTelemetryCollector: OpenTelemetryCollector<Metrics>,
|
|
85
85
|
schemaValidator: SchemaValidator,
|
|
86
|
-
|
|
86
|
+
mappers: {
|
|
87
87
|
OrganizationDtoMapper: ResponseDtoMapperConstructor<
|
|
88
88
|
SchemaValidator,
|
|
89
89
|
Dto['OrganizationDtoMapper'],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"organization.service.d.ts","sourceRoot":"","sources":["../../services/organization.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAsB,MAAM,oBAAoB,CAAC;AAC/D,OAAO,
|
|
1
|
+
{"version":3,"file":"organization.service.d.ts","sourceRoot":"","sources":["../../services/organization.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAsB,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACvB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAEL,2BAA2B,EAC3B,4BAA4B,EAE7B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,+BAA+B,EAAE,MAAM,2BAA2B,CAAC;AAC5E,OAAO,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAC;AAC5E,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,qBAAqB,EACtB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,M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1E"}
|
|
@@ -3,25 +3,25 @@ export class BaseOrganizationService {
|
|
|
3
3
|
em;
|
|
4
4
|
openTelemetryCollector;
|
|
5
5
|
schemaValidator;
|
|
6
|
-
|
|
7
|
-
#
|
|
8
|
-
constructor(em, openTelemetryCollector, schemaValidator,
|
|
6
|
+
mappers;
|
|
7
|
+
#mappers;
|
|
8
|
+
constructor(em, openTelemetryCollector, schemaValidator, mappers) {
|
|
9
9
|
this.em = em;
|
|
10
10
|
this.openTelemetryCollector = openTelemetryCollector;
|
|
11
11
|
this.schemaValidator = schemaValidator;
|
|
12
|
-
this.
|
|
13
|
-
this.#
|
|
12
|
+
this.mappers = mappers;
|
|
13
|
+
this.#mappers = transformIntoInternalDtoMapper(mappers, schemaValidator);
|
|
14
14
|
}
|
|
15
15
|
async createOrganization(organizationDto, em) {
|
|
16
16
|
this.openTelemetryCollector.log('info', 'Creating organization');
|
|
17
17
|
const organization =
|
|
18
|
-
this.#
|
|
18
|
+
await this.#mappers.CreateOrganizationDtoMapper.deserializeDtoToEntity(
|
|
19
19
|
organizationDto
|
|
20
20
|
);
|
|
21
21
|
await (em ?? this.em).transactional(async (innerEm) => {
|
|
22
22
|
await innerEm.persist(organization);
|
|
23
23
|
});
|
|
24
|
-
return this.#
|
|
24
|
+
return this.#mappers.OrganizationDtoMapper.serializeEntityToDto(
|
|
25
25
|
organization
|
|
26
26
|
);
|
|
27
27
|
}
|
|
@@ -30,17 +30,17 @@ export class BaseOrganizationService {
|
|
|
30
30
|
'Organization',
|
|
31
31
|
idDto
|
|
32
32
|
);
|
|
33
|
-
return this.#
|
|
33
|
+
return this.#mappers.OrganizationDtoMapper.serializeEntityToDto(
|
|
34
34
|
organization
|
|
35
35
|
);
|
|
36
36
|
}
|
|
37
37
|
async updateOrganization(organizationDto, em) {
|
|
38
38
|
const updatedOrganization =
|
|
39
|
-
this.#
|
|
39
|
+
await this.#mappers.UpdateOrganizationDtoMapper.deserializeDtoToEntity(
|
|
40
40
|
organizationDto
|
|
41
41
|
);
|
|
42
42
|
await (em ?? this.em).upsert(updatedOrganization);
|
|
43
|
-
return this.#
|
|
43
|
+
return this.#mappers.OrganizationDtoMapper.serializeEntityToDto(
|
|
44
44
|
updatedOrganization
|
|
45
45
|
);
|
|
46
46
|
}
|