@forklaunch/implementation-iam-base 0.1.17 → 0.2.1
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 +75 -21
- package/lib/eject/services/permission.service.ts +169 -89
- package/lib/eject/services/role.service.ts +126 -42
- package/lib/eject/services/user.service.ts +128 -58
- package/lib/services/organization.service.d.ts +11 -6
- package/lib/services/organization.service.d.ts.map +1 -1
- package/lib/services/organization.service.js +56 -18
- package/lib/services/permission.service.d.ts +29 -18
- package/lib/services/permission.service.d.ts.map +1 -1
- package/lib/services/permission.service.js +125 -64
- package/lib/services/role.service.d.ts +10 -5
- package/lib/services/role.service.d.ts.map +1 -1
- package/lib/services/role.service.js +102 -36
- package/lib/services/user.service.d.ts +23 -27
- package/lib/services/user.service.d.ts.map +1 -1
- package/lib/services/user.service.js +102 -43
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -6
|
@@ -1,73 +1,139 @@
|
|
|
1
|
+
import { evaluateTelemetryOptions } from '@forklaunch/core/http';
|
|
1
2
|
import { transformIntoInternalDtoMapper } from '@forklaunch/core/mappers';
|
|
2
3
|
export class BaseRoleService {
|
|
3
4
|
em;
|
|
4
5
|
openTelemetryCollector;
|
|
5
6
|
schemaValidator;
|
|
6
|
-
|
|
7
|
-
#
|
|
8
|
-
|
|
7
|
+
mappers;
|
|
8
|
+
#mappers;
|
|
9
|
+
evaluatedTelemetryOptions;
|
|
10
|
+
constructor(em, openTelemetryCollector, schemaValidator, mappers, options) {
|
|
9
11
|
this.em = em;
|
|
10
12
|
this.openTelemetryCollector = openTelemetryCollector;
|
|
11
13
|
this.schemaValidator = schemaValidator;
|
|
12
|
-
this.
|
|
13
|
-
this.#
|
|
14
|
+
this.mappers = mappers;
|
|
15
|
+
this.#mappers = transformIntoInternalDtoMapper(mappers, schemaValidator);
|
|
16
|
+
this.evaluatedTelemetryOptions = options?.telemetry
|
|
17
|
+
? evaluateTelemetryOptions(options.telemetry).enabled
|
|
18
|
+
: {
|
|
19
|
+
logging: false,
|
|
20
|
+
metrics: false,
|
|
21
|
+
tracing: false
|
|
22
|
+
};
|
|
14
23
|
}
|
|
15
24
|
async createRole(roleDto, em) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
25
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
26
|
+
this.openTelemetryCollector.info('Creating role', roleDto);
|
|
27
|
+
}
|
|
28
|
+
const role = await this.#mappers.CreateRoleDtoMapper.deserializeDtoToEntity(
|
|
29
|
+
roleDto,
|
|
30
|
+
em ?? this.em
|
|
31
|
+
);
|
|
32
|
+
if (em) {
|
|
33
|
+
await em.persist(role);
|
|
34
|
+
} else {
|
|
35
|
+
await this.em.persistAndFlush(role);
|
|
36
|
+
}
|
|
37
|
+
return this.#mappers.RoleDtoMapper.serializeEntityToDto(role);
|
|
21
38
|
}
|
|
22
39
|
async createBatchRoles(roleDtos, em) {
|
|
40
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
41
|
+
this.openTelemetryCollector.info('Creating batch roles', roleDtos);
|
|
42
|
+
}
|
|
23
43
|
const roles = await Promise.all(
|
|
24
44
|
roleDtos.map(async (roleDto) =>
|
|
25
|
-
this.#
|
|
45
|
+
this.#mappers.CreateRoleDtoMapper.deserializeDtoToEntity(
|
|
46
|
+
roleDto,
|
|
47
|
+
em ?? this.em
|
|
48
|
+
)
|
|
26
49
|
)
|
|
27
50
|
);
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
51
|
+
if (em) {
|
|
52
|
+
await em.persist(roles);
|
|
53
|
+
} else {
|
|
54
|
+
await this.em.persistAndFlush(roles);
|
|
55
|
+
}
|
|
56
|
+
return Promise.all(
|
|
57
|
+
roles.map((role) =>
|
|
58
|
+
this.#mappers.RoleDtoMapper.serializeEntityToDto(role)
|
|
59
|
+
)
|
|
31
60
|
);
|
|
32
61
|
}
|
|
33
|
-
async getRole(
|
|
34
|
-
|
|
62
|
+
async getRole({ id }, em) {
|
|
63
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
64
|
+
this.openTelemetryCollector.info('Getting role', { id });
|
|
65
|
+
}
|
|
66
|
+
const role = await (em ?? this.em).findOneOrFail('Role', id, {
|
|
35
67
|
populate: ['id', '*']
|
|
36
68
|
});
|
|
37
|
-
return this.#
|
|
69
|
+
return this.#mappers.RoleDtoMapper.serializeEntityToDto(role);
|
|
38
70
|
}
|
|
39
|
-
async getBatchRoles(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
71
|
+
async getBatchRoles({ ids }, em) {
|
|
72
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
73
|
+
this.openTelemetryCollector.info('Getting batch roles', { ids });
|
|
74
|
+
}
|
|
75
|
+
return Promise.all(
|
|
76
|
+
(
|
|
77
|
+
await (em ?? this.em).find(
|
|
78
|
+
'Role',
|
|
79
|
+
{
|
|
80
|
+
id: { $in: ids }
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
populate: ['id', '*']
|
|
84
|
+
}
|
|
85
|
+
)
|
|
86
|
+
).map((role) => this.#mappers.RoleDtoMapper.serializeEntityToDto(role))
|
|
87
|
+
);
|
|
45
88
|
}
|
|
46
89
|
async updateRole(roleDto, em) {
|
|
47
|
-
|
|
48
|
-
this
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
90
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
91
|
+
this.openTelemetryCollector.info('Updating role', roleDto);
|
|
92
|
+
}
|
|
93
|
+
const role = await this.#mappers.UpdateRoleDtoMapper.deserializeDtoToEntity(
|
|
94
|
+
roleDto,
|
|
95
|
+
em ?? this.em
|
|
96
|
+
);
|
|
97
|
+
if (em) {
|
|
98
|
+
await em.persist(role);
|
|
99
|
+
} else {
|
|
100
|
+
await this.em.persistAndFlush(role);
|
|
101
|
+
}
|
|
102
|
+
return this.#mappers.RoleDtoMapper.serializeEntityToDto(role);
|
|
53
103
|
}
|
|
54
104
|
async updateBatchRoles(roleDtos, em) {
|
|
55
|
-
|
|
105
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
106
|
+
this.openTelemetryCollector.info('Updating batch roles', roleDtos);
|
|
107
|
+
}
|
|
108
|
+
const roles = await Promise.all(
|
|
56
109
|
roleDtos.map(async (roleDto) =>
|
|
57
|
-
this.#
|
|
110
|
+
this.#mappers.UpdateRoleDtoMapper.deserializeDtoToEntity(
|
|
111
|
+
roleDto,
|
|
112
|
+
em ?? this.em
|
|
113
|
+
)
|
|
58
114
|
)
|
|
59
115
|
);
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
116
|
+
if (em) {
|
|
117
|
+
await em.persist(roles);
|
|
118
|
+
} else {
|
|
119
|
+
await this.em.persistAndFlush(roles);
|
|
120
|
+
}
|
|
121
|
+
return Promise.all(
|
|
122
|
+
roles.map((role) =>
|
|
123
|
+
this.#mappers.RoleDtoMapper.serializeEntityToDto(role)
|
|
124
|
+
)
|
|
65
125
|
);
|
|
66
126
|
}
|
|
67
127
|
async deleteRole(idDto, em) {
|
|
128
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
129
|
+
this.openTelemetryCollector.info('Deleting role', idDto);
|
|
130
|
+
}
|
|
68
131
|
await (em ?? this.em).nativeDelete('Role', idDto);
|
|
69
132
|
}
|
|
70
133
|
async deleteBatchRoles(idsDto, em) {
|
|
134
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
135
|
+
this.openTelemetryCollector.info('Deleting batch roles', idsDto);
|
|
136
|
+
}
|
|
71
137
|
await (em ?? this.em).nativeDelete('Role', { id: { $in: idsDto.ids } });
|
|
72
138
|
}
|
|
73
139
|
}
|
|
@@ -4,14 +4,15 @@ import {
|
|
|
4
4
|
UserService
|
|
5
5
|
} from '@forklaunch/interfaces-iam/interfaces';
|
|
6
6
|
import { IdDto, IdsDto } from '@forklaunch/common';
|
|
7
|
+
import {
|
|
8
|
+
MetricsDefinition,
|
|
9
|
+
OpenTelemetryCollector,
|
|
10
|
+
TelemetryOptions
|
|
11
|
+
} from '@forklaunch/core/http';
|
|
7
12
|
import {
|
|
8
13
|
RequestDtoMapperConstructor,
|
|
9
14
|
ResponseDtoMapperConstructor
|
|
10
15
|
} from '@forklaunch/core/mappers';
|
|
11
|
-
import {
|
|
12
|
-
MetricsDefinition,
|
|
13
|
-
OpenTelemetryCollector
|
|
14
|
-
} from '@forklaunch/core/http';
|
|
15
16
|
import { MapNestedDtoArraysToCollections } from '@forklaunch/core/services';
|
|
16
17
|
import {
|
|
17
18
|
CreateUserDto,
|
|
@@ -51,7 +52,7 @@ export declare class BaseUserService<
|
|
|
51
52
|
protected organizationServiceFactory: () => OrganizationService<OrganizationStatus>;
|
|
52
53
|
protected openTelemetryCollector: OpenTelemetryCollector<Metrics>;
|
|
53
54
|
protected schemaValidator: SchemaValidator;
|
|
54
|
-
protected
|
|
55
|
+
protected mappers: {
|
|
55
56
|
UserDtoMapper: ResponseDtoMapperConstructor<
|
|
56
57
|
SchemaValidator,
|
|
57
58
|
Dto['UserDtoMapper'],
|
|
@@ -60,22 +61,20 @@ export declare class BaseUserService<
|
|
|
60
61
|
CreateUserDtoMapper: RequestDtoMapperConstructor<
|
|
61
62
|
SchemaValidator,
|
|
62
63
|
Dto['CreateUserDtoMapper'],
|
|
63
|
-
Entities['CreateUserDtoMapper']
|
|
64
|
-
(
|
|
65
|
-
dto: never,
|
|
66
|
-
passwordEncryptionPublicKeyPath: string
|
|
67
|
-
) => Entities['UpdateUserDtoMapper']
|
|
64
|
+
Entities['CreateUserDtoMapper']
|
|
68
65
|
>;
|
|
69
66
|
UpdateUserDtoMapper: RequestDtoMapperConstructor<
|
|
70
67
|
SchemaValidator,
|
|
71
68
|
Dto['UpdateUserDtoMapper'],
|
|
72
|
-
Entities['UpdateUserDtoMapper']
|
|
73
|
-
(
|
|
74
|
-
dto: never,
|
|
75
|
-
passwordEncryptionPublicKeyPath: string
|
|
76
|
-
) => Entities['UpdateUserDtoMapper']
|
|
69
|
+
Entities['UpdateUserDtoMapper']
|
|
77
70
|
>;
|
|
78
71
|
};
|
|
72
|
+
readonly options?:
|
|
73
|
+
| {
|
|
74
|
+
telemetry?: TelemetryOptions;
|
|
75
|
+
}
|
|
76
|
+
| undefined;
|
|
77
|
+
private evaluatedTelemetryOptions;
|
|
79
78
|
constructor(
|
|
80
79
|
em: EntityManager,
|
|
81
80
|
passwordEncryptionPublicKeyPath: string,
|
|
@@ -83,7 +82,7 @@ export declare class BaseUserService<
|
|
|
83
82
|
organizationServiceFactory: () => OrganizationService<OrganizationStatus>,
|
|
84
83
|
openTelemetryCollector: OpenTelemetryCollector<Metrics>,
|
|
85
84
|
schemaValidator: SchemaValidator,
|
|
86
|
-
|
|
85
|
+
mappers: {
|
|
87
86
|
UserDtoMapper: ResponseDtoMapperConstructor<
|
|
88
87
|
SchemaValidator,
|
|
89
88
|
Dto['UserDtoMapper'],
|
|
@@ -92,22 +91,19 @@ export declare class BaseUserService<
|
|
|
92
91
|
CreateUserDtoMapper: RequestDtoMapperConstructor<
|
|
93
92
|
SchemaValidator,
|
|
94
93
|
Dto['CreateUserDtoMapper'],
|
|
95
|
-
Entities['CreateUserDtoMapper']
|
|
96
|
-
(
|
|
97
|
-
dto: never,
|
|
98
|
-
passwordEncryptionPublicKeyPath: string
|
|
99
|
-
) => Entities['UpdateUserDtoMapper']
|
|
94
|
+
Entities['CreateUserDtoMapper']
|
|
100
95
|
>;
|
|
101
96
|
UpdateUserDtoMapper: RequestDtoMapperConstructor<
|
|
102
97
|
SchemaValidator,
|
|
103
98
|
Dto['UpdateUserDtoMapper'],
|
|
104
|
-
Entities['UpdateUserDtoMapper']
|
|
105
|
-
(
|
|
106
|
-
dto: never,
|
|
107
|
-
passwordEncryptionPublicKeyPath: string
|
|
108
|
-
) => Entities['UpdateUserDtoMapper']
|
|
99
|
+
Entities['UpdateUserDtoMapper']
|
|
109
100
|
>;
|
|
110
|
-
}
|
|
101
|
+
},
|
|
102
|
+
options?:
|
|
103
|
+
| {
|
|
104
|
+
telemetry?: TelemetryOptions;
|
|
105
|
+
}
|
|
106
|
+
| undefined
|
|
111
107
|
);
|
|
112
108
|
createUser(
|
|
113
109
|
userDto: Dto['CreateUserDtoMapper'],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user.service.d.ts","sourceRoot":"","sources":["../../services/user.service.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,WAAW,EACX,WAAW,EACZ,MAAM,uCAAuC,CAAC;AAE/C,OAAO,EAAE,KAAK,EAAE,MAAM,EAAsB,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAEL,
|
|
1
|
+
{"version":3,"file":"user.service.d.ts","sourceRoot":"","sources":["../../services/user.service.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,WAAW,EACX,WAAW,EACZ,MAAM,uCAAuC,CAAC;AAE/C,OAAO,EAAE,KAAK,EAAE,MAAM,EAAsB,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAEL,iBAAiB,EACjB,sBAAsB,EACtB,gBAAgB,EACjB,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,EACL,aAAa,EACb,aAAa,EACb,OAAO,EACR,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,qBAAa,eAAe,CAC1B,eAAe,SAAS,kBAAkB,EAC1C,kBAAkB,EAClB,OAAO,SAAS,iBAAiB,GAAG,iBAAiB,EACrD,GAAG,SAAS;IACV,aAAa,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;IAc1B,aAAa,CACjB,MAAM,EAAE,MAAM,EACd,EAAE,CAAC,EAAE,aAAa,GACjB,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,EAAE,CAAC;IAkB5B,UAAU,CACd,OAAO,EAAE,GAAG,CAAC,qBAAqB,CAAC,EACnC,EAAE,CAAC,EAAE,aAAa,GACjB,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAmB1B,gBAAgB,CACpB,QAAQ,EAAE,aAAa,EAAE,EACzB,EAAE,CAAC,EAAE,aAAa,GACjB,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,EAAE,CAAC;IA2B5B,UAAU,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAO3D,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAOnE,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAiB1D,mBAAmB,CAAC,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAmB7E"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { evaluateTelemetryOptions } from '@forklaunch/core/http';
|
|
1
2
|
import { transformIntoInternalDtoMapper } from '@forklaunch/core/mappers';
|
|
2
3
|
export class BaseUserService {
|
|
3
4
|
em;
|
|
@@ -6,8 +7,10 @@ export class BaseUserService {
|
|
|
6
7
|
organizationServiceFactory;
|
|
7
8
|
openTelemetryCollector;
|
|
8
9
|
schemaValidator;
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
mappers;
|
|
11
|
+
options;
|
|
12
|
+
#mappers;
|
|
13
|
+
evaluatedTelemetryOptions;
|
|
11
14
|
constructor(
|
|
12
15
|
em,
|
|
13
16
|
passwordEncryptionPublicKeyPath,
|
|
@@ -15,7 +18,8 @@ export class BaseUserService {
|
|
|
15
18
|
organizationServiceFactory,
|
|
16
19
|
openTelemetryCollector,
|
|
17
20
|
schemaValidator,
|
|
18
|
-
|
|
21
|
+
mappers,
|
|
22
|
+
options
|
|
19
23
|
) {
|
|
20
24
|
this.em = em;
|
|
21
25
|
this.passwordEncryptionPublicKeyPath = passwordEncryptionPublicKeyPath;
|
|
@@ -23,84 +27,133 @@ export class BaseUserService {
|
|
|
23
27
|
this.organizationServiceFactory = organizationServiceFactory;
|
|
24
28
|
this.openTelemetryCollector = openTelemetryCollector;
|
|
25
29
|
this.schemaValidator = schemaValidator;
|
|
26
|
-
this.
|
|
27
|
-
this
|
|
30
|
+
this.mappers = mappers;
|
|
31
|
+
this.options = options;
|
|
32
|
+
this.#mappers = transformIntoInternalDtoMapper(mappers, schemaValidator);
|
|
33
|
+
this.evaluatedTelemetryOptions = options?.telemetry
|
|
34
|
+
? evaluateTelemetryOptions(options.telemetry).enabled
|
|
35
|
+
: {
|
|
36
|
+
logging: false,
|
|
37
|
+
metrics: false,
|
|
38
|
+
tracing: false
|
|
39
|
+
};
|
|
28
40
|
}
|
|
29
41
|
async createUser(userDto, em) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
42
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
43
|
+
this.openTelemetryCollector.info('Creating user', userDto);
|
|
44
|
+
}
|
|
45
|
+
const user = await this.#mappers.CreateUserDtoMapper.deserializeDtoToEntity(
|
|
46
|
+
userDto,
|
|
47
|
+
em ?? this.em
|
|
48
|
+
);
|
|
49
|
+
if (em) {
|
|
36
50
|
await em.persist(user);
|
|
37
|
-
}
|
|
38
|
-
|
|
51
|
+
} else {
|
|
52
|
+
await this.em.persistAndFlush(user);
|
|
53
|
+
}
|
|
54
|
+
return this.#mappers.UserDtoMapper.serializeEntityToDto(user);
|
|
39
55
|
}
|
|
40
56
|
async createBatchUsers(userDtos, em) {
|
|
57
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
58
|
+
this.openTelemetryCollector.info('Creating batch users', userDtos);
|
|
59
|
+
}
|
|
41
60
|
const users = await Promise.all(
|
|
42
61
|
userDtos.map(async (createUserDto) =>
|
|
43
|
-
this.#
|
|
62
|
+
this.#mappers.CreateUserDtoMapper.deserializeDtoToEntity(
|
|
44
63
|
createUserDto,
|
|
45
|
-
this.
|
|
64
|
+
em ?? this.em
|
|
46
65
|
)
|
|
47
66
|
)
|
|
48
67
|
);
|
|
49
|
-
|
|
68
|
+
if (em) {
|
|
50
69
|
await em.persist(users);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
70
|
+
} else {
|
|
71
|
+
await this.em.persistAndFlush(users);
|
|
72
|
+
}
|
|
73
|
+
return Promise.all(
|
|
74
|
+
users.map((user) =>
|
|
75
|
+
this.#mappers.UserDtoMapper.serializeEntityToDto(user)
|
|
76
|
+
)
|
|
54
77
|
);
|
|
55
78
|
}
|
|
56
79
|
async getUser(idDto, em) {
|
|
80
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
81
|
+
this.openTelemetryCollector.info('Getting user', idDto);
|
|
82
|
+
}
|
|
57
83
|
const user = await (em ?? this.em).findOneOrFail('User', idDto, {
|
|
58
84
|
populate: ['id', '*']
|
|
59
85
|
});
|
|
60
|
-
return this.#
|
|
86
|
+
return this.#mappers.UserDtoMapper.serializeEntityToDto(user);
|
|
61
87
|
}
|
|
62
88
|
async getBatchUsers(idsDto, em) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
89
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
90
|
+
this.openTelemetryCollector.info('Getting batch users', idsDto);
|
|
91
|
+
}
|
|
92
|
+
return Promise.all(
|
|
93
|
+
(
|
|
94
|
+
await (em ?? this.em).find('User', idsDto, {
|
|
95
|
+
populate: ['id', '*']
|
|
96
|
+
})
|
|
97
|
+
).map((user) => this.#mappers.UserDtoMapper.serializeEntityToDto(user))
|
|
98
|
+
);
|
|
68
99
|
}
|
|
69
100
|
async updateUser(userDto, em) {
|
|
70
|
-
|
|
101
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
102
|
+
this.openTelemetryCollector.info('Updating user', userDto);
|
|
103
|
+
}
|
|
104
|
+
const user = await this.#mappers.UpdateUserDtoMapper.deserializeDtoToEntity(
|
|
71
105
|
userDto,
|
|
72
|
-
this.
|
|
106
|
+
em ?? this.em
|
|
73
107
|
);
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
|
|
108
|
+
if (em) {
|
|
109
|
+
await em.persist(user);
|
|
110
|
+
} else {
|
|
111
|
+
await this.em.persistAndFlush(user);
|
|
112
|
+
}
|
|
113
|
+
return this.#mappers.UserDtoMapper.serializeEntityToDto(user);
|
|
78
114
|
}
|
|
79
115
|
async updateBatchUsers(userDtos, em) {
|
|
80
|
-
|
|
116
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
117
|
+
this.openTelemetryCollector.info('Updating batch users', userDtos);
|
|
118
|
+
}
|
|
119
|
+
const users = await Promise.all(
|
|
81
120
|
userDtos.map(async (updateUserDto) =>
|
|
82
|
-
this.#
|
|
121
|
+
this.#mappers.UpdateUserDtoMapper.deserializeDtoToEntity(
|
|
83
122
|
updateUserDto,
|
|
84
|
-
this.
|
|
123
|
+
em ?? this.em
|
|
85
124
|
)
|
|
86
125
|
)
|
|
87
126
|
);
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
127
|
+
if (em) {
|
|
128
|
+
await em.persist(users);
|
|
129
|
+
} else {
|
|
130
|
+
await this.em.persistAndFlush(users);
|
|
131
|
+
}
|
|
132
|
+
return Promise.all(
|
|
133
|
+
users.map((user) =>
|
|
134
|
+
this.#mappers.UserDtoMapper.serializeEntityToDto(user)
|
|
135
|
+
)
|
|
93
136
|
);
|
|
94
137
|
}
|
|
95
138
|
async deleteUser(idDto, em) {
|
|
96
|
-
|
|
97
|
-
|
|
139
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
140
|
+
this.openTelemetryCollector.info('Deleting user', idDto);
|
|
141
|
+
}
|
|
142
|
+
await (em ?? this.em).nativeDelete('User', idDto);
|
|
98
143
|
}
|
|
99
144
|
async deleteBatchUsers(idsDto, em) {
|
|
100
|
-
|
|
101
|
-
|
|
145
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
146
|
+
this.openTelemetryCollector.info('Deleting batch users', idsDto);
|
|
147
|
+
}
|
|
148
|
+
await (em ?? this.em).nativeDelete('User', idsDto);
|
|
102
149
|
}
|
|
103
150
|
async verifyHasRole(idDto, roleId) {
|
|
151
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
152
|
+
this.openTelemetryCollector.info('Verifying user has role', {
|
|
153
|
+
idDto,
|
|
154
|
+
roleId
|
|
155
|
+
});
|
|
156
|
+
}
|
|
104
157
|
const user = await this.getUser(idDto);
|
|
105
158
|
if (
|
|
106
159
|
user.roles.filter((role) => {
|
|
@@ -111,6 +164,12 @@ export class BaseUserService {
|
|
|
111
164
|
}
|
|
112
165
|
}
|
|
113
166
|
async verifyHasPermission(idDto, permissionId) {
|
|
167
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
168
|
+
this.openTelemetryCollector.info('Verifying user has permission', {
|
|
169
|
+
idDto,
|
|
170
|
+
permissionId
|
|
171
|
+
});
|
|
172
|
+
}
|
|
114
173
|
const user = await this.getUser(idDto);
|
|
115
174
|
if (
|
|
116
175
|
user.roles
|