@forklaunch/implementation-iam-base 0.1.10 → 0.1.12
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/package.json +5 -5
- package/lib/__test__/schemaEquality.test.d.ts +0 -2
- package/lib/__test__/schemaEquality.test.d.ts.map +0 -1
- package/lib/__test__/schemaEquality.test.js +0 -283
- package/lib/eject/domain/schemas/index.ts +0 -4
- package/lib/eject/domain/schemas/organization.schema.ts +0 -53
- package/lib/eject/domain/schemas/permission.schema.ts +0 -36
- package/lib/eject/domain/schemas/role.schema.ts +0 -37
- package/lib/eject/domain/schemas/user.schema.ts +0 -53
- package/lib/eject/services/index.ts +0 -4
- package/lib/eject/services/organization.service.ts +0 -143
- package/lib/eject/services/permission.service.ts +0 -345
- package/lib/eject/services/role.service.ts +0 -179
- package/lib/eject/services/user.service.ts +0 -224
- package/lib/jest.config.d.ts +0 -4
- package/lib/jest.config.d.ts.map +0 -1
- package/lib/jest.config.js +0 -19
- package/lib/schemas/index.d.ts +0 -5
- package/lib/schemas/index.d.ts.map +0 -1
- package/lib/schemas/index.js +0 -4
- package/lib/schemas/organization.schema.d.ts +0 -411
- package/lib/schemas/organization.schema.d.ts.map +0 -1
- package/lib/schemas/organization.schema.js +0 -7
- package/lib/schemas/permission.schema.d.ts +0 -104
- package/lib/schemas/permission.schema.d.ts.map +0 -1
- package/lib/schemas/permission.schema.js +0 -7
- package/lib/schemas/role.schema.d.ts +0 -163
- package/lib/schemas/role.schema.d.ts.map +0 -1
- package/lib/schemas/role.schema.js +0 -7
- package/lib/schemas/typebox/organization.schema.d.ts +0 -414
- package/lib/schemas/typebox/organization.schema.d.ts.map +0 -1
- package/lib/schemas/typebox/organization.schema.js +0 -44
- package/lib/schemas/typebox/permission.schema.d.ts +0 -131
- package/lib/schemas/typebox/permission.schema.d.ts.map +0 -1
- package/lib/schemas/typebox/permission.schema.js +0 -32
- package/lib/schemas/typebox/role.schema.d.ts +0 -199
- package/lib/schemas/typebox/role.schema.d.ts.map +0 -1
- package/lib/schemas/typebox/role.schema.js +0 -33
- package/lib/schemas/typebox/user.schema.d.ts +0 -339
- package/lib/schemas/typebox/user.schema.d.ts.map +0 -1
- package/lib/schemas/typebox/user.schema.js +0 -49
- package/lib/schemas/user.schema.d.ts +0 -290
- package/lib/schemas/user.schema.d.ts.map +0 -1
- package/lib/schemas/user.schema.js +0 -7
- package/lib/schemas/zod/organization.schema.d.ts +0 -374
- package/lib/schemas/zod/organization.schema.d.ts.map +0 -1
- package/lib/schemas/zod/organization.schema.js +0 -44
- package/lib/schemas/zod/permission.schema.d.ts +0 -63
- package/lib/schemas/zod/permission.schema.d.ts.map +0 -1
- package/lib/schemas/zod/permission.schema.js +0 -32
- package/lib/schemas/zod/role.schema.d.ts +0 -113
- package/lib/schemas/zod/role.schema.d.ts.map +0 -1
- package/lib/schemas/zod/role.schema.js +0 -33
- package/lib/schemas/zod/user.schema.d.ts +0 -225
- package/lib/schemas/zod/user.schema.d.ts.map +0 -1
- package/lib/schemas/zod/user.schema.js +0 -49
- package/lib/services/index.d.ts +0 -5
- package/lib/services/index.d.ts.map +0 -1
- package/lib/services/index.js +0 -4
- package/lib/services/organization.service.d.ts +0 -118
- package/lib/services/organization.service.d.ts.map +0 -1
- package/lib/services/organization.service.js +0 -50
- package/lib/services/permission.service.d.ts +0 -138
- package/lib/services/permission.service.d.ts.map +0 -1
- package/lib/services/permission.service.js +0 -203
- package/lib/services/role.service.d.ts +0 -118
- package/lib/services/role.service.d.ts.map +0 -1
- package/lib/services/role.service.js +0 -73
- package/lib/services/user.service.d.ts +0 -138
- package/lib/services/user.service.d.ts.map +0 -1
- package/lib/services/user.service.js +0 -126
- package/lib/tsconfig.tsbuildinfo +0 -1
- package/lib/vitest.config.d.ts +0 -3
- package/lib/vitest.config.d.ts.map +0 -1
- package/lib/vitest.config.js +0 -7
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { transformIntoInternalDtoMapper } from '@forklaunch/core/mappers';
|
|
2
|
-
export class BaseRoleService {
|
|
3
|
-
em;
|
|
4
|
-
openTelemetryCollector;
|
|
5
|
-
schemaValidator;
|
|
6
|
-
mapperss;
|
|
7
|
-
#mapperss;
|
|
8
|
-
constructor(em, openTelemetryCollector, schemaValidator, mapperss) {
|
|
9
|
-
this.em = em;
|
|
10
|
-
this.openTelemetryCollector = openTelemetryCollector;
|
|
11
|
-
this.schemaValidator = schemaValidator;
|
|
12
|
-
this.mapperss = mapperss;
|
|
13
|
-
this.#mapperss = transformIntoInternalDtoMapper(mapperss, schemaValidator);
|
|
14
|
-
}
|
|
15
|
-
async createRole(roleDto, em) {
|
|
16
|
-
// TODO: Think about removing static method here, since we need specific args
|
|
17
|
-
const role =
|
|
18
|
-
this.#mapperss.CreateRoleDtoMapper.deserializeDtoToEntity(roleDto);
|
|
19
|
-
await (em ?? this.em).transactional((em) => em.persist(role));
|
|
20
|
-
return this.#mapperss.RoleDtoMapper.serializeEntityToDto(role);
|
|
21
|
-
}
|
|
22
|
-
async createBatchRoles(roleDtos, em) {
|
|
23
|
-
const roles = await Promise.all(
|
|
24
|
-
roleDtos.map(async (roleDto) =>
|
|
25
|
-
this.#mapperss.CreateRoleDtoMapper.deserializeDtoToEntity(roleDto)
|
|
26
|
-
)
|
|
27
|
-
);
|
|
28
|
-
await (em ?? this.em).transactional((em) => em.persist(roles));
|
|
29
|
-
return roles.map((role) =>
|
|
30
|
-
this.#mapperss.RoleDtoMapper.serializeEntityToDto(role)
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
async getRole(idDto, em) {
|
|
34
|
-
const role = await (em ?? this.em).findOneOrFail('Role', idDto, {
|
|
35
|
-
populate: ['id', '*']
|
|
36
|
-
});
|
|
37
|
-
return this.#mapperss.RoleDtoMapper.serializeEntityToDto(role);
|
|
38
|
-
}
|
|
39
|
-
async getBatchRoles(idsDto, em) {
|
|
40
|
-
return (
|
|
41
|
-
await (em ?? this.em).find('Role', idsDto, {
|
|
42
|
-
populate: ['id', '*']
|
|
43
|
-
})
|
|
44
|
-
).map((role) => this.#mapperss.RoleDtoMapper.serializeEntityToDto(role));
|
|
45
|
-
}
|
|
46
|
-
async updateRole(roleDto, em) {
|
|
47
|
-
let role =
|
|
48
|
-
this.#mapperss.UpdateRoleDtoMapper.deserializeDtoToEntity(roleDto);
|
|
49
|
-
await (em ?? this.em).transactional(async (em) => {
|
|
50
|
-
role = await em.upsert('Role', role);
|
|
51
|
-
});
|
|
52
|
-
return this.#mapperss.RoleDtoMapper.serializeEntityToDto(role);
|
|
53
|
-
}
|
|
54
|
-
async updateBatchRoles(roleDtos, em) {
|
|
55
|
-
let roles = await Promise.all(
|
|
56
|
-
roleDtos.map(async (roleDto) =>
|
|
57
|
-
this.#mapperss.UpdateRoleDtoMapper.deserializeDtoToEntity(roleDto)
|
|
58
|
-
)
|
|
59
|
-
);
|
|
60
|
-
await (em ?? this.em).transactional(async (em) => {
|
|
61
|
-
roles = await em.upsertMany('Role', roles);
|
|
62
|
-
});
|
|
63
|
-
return roles.map((role) =>
|
|
64
|
-
this.#mapperss.RoleDtoMapper.serializeEntityToDto(role)
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
async deleteRole(idDto, em) {
|
|
68
|
-
await (em ?? this.em).nativeDelete('Role', idDto);
|
|
69
|
-
}
|
|
70
|
-
async deleteBatchRoles(idsDto, em) {
|
|
71
|
-
await (em ?? this.em).nativeDelete('Role', { id: { $in: idsDto.ids } });
|
|
72
|
-
}
|
|
73
|
-
}
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
OrganizationService,
|
|
3
|
-
RoleService,
|
|
4
|
-
UserService
|
|
5
|
-
} from '@forklaunch/interfaces-iam/interfaces';
|
|
6
|
-
import { IdDto, IdsDto } from '@forklaunch/common';
|
|
7
|
-
import {
|
|
8
|
-
RequestDtoMapperConstructor,
|
|
9
|
-
ResponseDtoMapperConstructor
|
|
10
|
-
} from '@forklaunch/core/mappers';
|
|
11
|
-
import {
|
|
12
|
-
MetricsDefinition,
|
|
13
|
-
OpenTelemetryCollector
|
|
14
|
-
} from '@forklaunch/core/http';
|
|
15
|
-
import { MapNestedDtoArraysToCollections } from '@forklaunch/core/services';
|
|
16
|
-
import {
|
|
17
|
-
CreateUserDto,
|
|
18
|
-
UpdateUserDto,
|
|
19
|
-
UserDto
|
|
20
|
-
} from '@forklaunch/interfaces-iam/types';
|
|
21
|
-
import { AnySchemaValidator } from '@forklaunch/validator';
|
|
22
|
-
import { EntityManager } from '@mikro-orm/core';
|
|
23
|
-
export declare class BaseUserService<
|
|
24
|
-
SchemaValidator extends AnySchemaValidator,
|
|
25
|
-
OrganizationStatus,
|
|
26
|
-
Metrics extends MetricsDefinition = MetricsDefinition,
|
|
27
|
-
Dto extends {
|
|
28
|
-
UserDtoMapper: UserDto;
|
|
29
|
-
CreateUserDtoMapper: CreateUserDto;
|
|
30
|
-
UpdateUserDtoMapper: UpdateUserDto;
|
|
31
|
-
} = {
|
|
32
|
-
UserDtoMapper: UserDto;
|
|
33
|
-
CreateUserDtoMapper: CreateUserDto;
|
|
34
|
-
UpdateUserDtoMapper: UpdateUserDto;
|
|
35
|
-
},
|
|
36
|
-
Entities extends {
|
|
37
|
-
UserDtoMapper: MapNestedDtoArraysToCollections<UserDto, 'roles'>;
|
|
38
|
-
CreateUserDtoMapper: MapNestedDtoArraysToCollections<UserDto, 'roles'>;
|
|
39
|
-
UpdateUserDtoMapper: MapNestedDtoArraysToCollections<UserDto, 'roles'>;
|
|
40
|
-
} = {
|
|
41
|
-
UserDtoMapper: MapNestedDtoArraysToCollections<UserDto, 'roles'>;
|
|
42
|
-
CreateUserDtoMapper: MapNestedDtoArraysToCollections<UserDto, 'roles'>;
|
|
43
|
-
UpdateUserDtoMapper: MapNestedDtoArraysToCollections<UserDto, 'roles'>;
|
|
44
|
-
}
|
|
45
|
-
> implements UserService
|
|
46
|
-
{
|
|
47
|
-
#private;
|
|
48
|
-
em: EntityManager;
|
|
49
|
-
protected passwordEncryptionPublicKeyPath: string;
|
|
50
|
-
protected roleServiceFactory: () => RoleService;
|
|
51
|
-
protected organizationServiceFactory: () => OrganizationService<OrganizationStatus>;
|
|
52
|
-
protected openTelemetryCollector: OpenTelemetryCollector<Metrics>;
|
|
53
|
-
protected schemaValidator: SchemaValidator;
|
|
54
|
-
protected mapperss: {
|
|
55
|
-
UserDtoMapper: ResponseDtoMapperConstructor<
|
|
56
|
-
SchemaValidator,
|
|
57
|
-
Dto['UserDtoMapper'],
|
|
58
|
-
Entities['UserDtoMapper']
|
|
59
|
-
>;
|
|
60
|
-
CreateUserDtoMapper: RequestDtoMapperConstructor<
|
|
61
|
-
SchemaValidator,
|
|
62
|
-
Dto['CreateUserDtoMapper'],
|
|
63
|
-
Entities['CreateUserDtoMapper'],
|
|
64
|
-
(
|
|
65
|
-
dto: never,
|
|
66
|
-
passwordEncryptionPublicKeyPath: string
|
|
67
|
-
) => Entities['UpdateUserDtoMapper']
|
|
68
|
-
>;
|
|
69
|
-
UpdateUserDtoMapper: RequestDtoMapperConstructor<
|
|
70
|
-
SchemaValidator,
|
|
71
|
-
Dto['UpdateUserDtoMapper'],
|
|
72
|
-
Entities['UpdateUserDtoMapper'],
|
|
73
|
-
(
|
|
74
|
-
dto: never,
|
|
75
|
-
passwordEncryptionPublicKeyPath: string
|
|
76
|
-
) => Entities['UpdateUserDtoMapper']
|
|
77
|
-
>;
|
|
78
|
-
};
|
|
79
|
-
constructor(
|
|
80
|
-
em: EntityManager,
|
|
81
|
-
passwordEncryptionPublicKeyPath: string,
|
|
82
|
-
roleServiceFactory: () => RoleService,
|
|
83
|
-
organizationServiceFactory: () => OrganizationService<OrganizationStatus>,
|
|
84
|
-
openTelemetryCollector: OpenTelemetryCollector<Metrics>,
|
|
85
|
-
schemaValidator: SchemaValidator,
|
|
86
|
-
mapperss: {
|
|
87
|
-
UserDtoMapper: ResponseDtoMapperConstructor<
|
|
88
|
-
SchemaValidator,
|
|
89
|
-
Dto['UserDtoMapper'],
|
|
90
|
-
Entities['UserDtoMapper']
|
|
91
|
-
>;
|
|
92
|
-
CreateUserDtoMapper: RequestDtoMapperConstructor<
|
|
93
|
-
SchemaValidator,
|
|
94
|
-
Dto['CreateUserDtoMapper'],
|
|
95
|
-
Entities['CreateUserDtoMapper'],
|
|
96
|
-
(
|
|
97
|
-
dto: never,
|
|
98
|
-
passwordEncryptionPublicKeyPath: string
|
|
99
|
-
) => Entities['UpdateUserDtoMapper']
|
|
100
|
-
>;
|
|
101
|
-
UpdateUserDtoMapper: RequestDtoMapperConstructor<
|
|
102
|
-
SchemaValidator,
|
|
103
|
-
Dto['UpdateUserDtoMapper'],
|
|
104
|
-
Entities['UpdateUserDtoMapper'],
|
|
105
|
-
(
|
|
106
|
-
dto: never,
|
|
107
|
-
passwordEncryptionPublicKeyPath: string
|
|
108
|
-
) => Entities['UpdateUserDtoMapper']
|
|
109
|
-
>;
|
|
110
|
-
}
|
|
111
|
-
);
|
|
112
|
-
createUser(
|
|
113
|
-
userDto: Dto['CreateUserDtoMapper'],
|
|
114
|
-
em?: EntityManager
|
|
115
|
-
): Promise<Dto['UserDtoMapper']>;
|
|
116
|
-
createBatchUsers(
|
|
117
|
-
userDtos: Dto['CreateUserDtoMapper'][],
|
|
118
|
-
em?: EntityManager
|
|
119
|
-
): Promise<Dto['UserDtoMapper'][]>;
|
|
120
|
-
getUser(idDto: IdDto, em?: EntityManager): Promise<Dto['UserDtoMapper']>;
|
|
121
|
-
getBatchUsers(
|
|
122
|
-
idsDto: IdsDto,
|
|
123
|
-
em?: EntityManager
|
|
124
|
-
): Promise<Dto['UserDtoMapper'][]>;
|
|
125
|
-
updateUser(
|
|
126
|
-
userDto: Dto['UpdateUserDtoMapper'],
|
|
127
|
-
em?: EntityManager
|
|
128
|
-
): Promise<Dto['UserDtoMapper']>;
|
|
129
|
-
updateBatchUsers(
|
|
130
|
-
userDtos: UpdateUserDto[],
|
|
131
|
-
em?: EntityManager
|
|
132
|
-
): Promise<Dto['UserDtoMapper'][]>;
|
|
133
|
-
deleteUser(idDto: IdDto, em?: EntityManager): Promise<void>;
|
|
134
|
-
deleteBatchUsers(idsDto: IdsDto, em?: EntityManager): Promise<void>;
|
|
135
|
-
verifyHasRole(idDto: IdDto, roleId: string): Promise<void>;
|
|
136
|
-
verifyHasPermission(idDto: IdDto, permissionId: string): Promise<void>;
|
|
137
|
-
}
|
|
138
|
-
//# sourceMappingURL=user.service.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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,2BAA2B,EAC3B,4BAA4B,EAE7B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACvB,MAAM,uBAAuB,CAAC;AAC/B,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,EAAE,OAAO,CAAC;IACvB,mBAAmB,EAAE,aAAa,CAAC;IACnC,mBAAmB,EAAE,aAAa,CAAC;CACpC,GAAG;IACF,aAAa,EAAE,OAAO,CAAC;IACvB,mBAAmB,EAAE,aAAa,CAAC;IACnC,mBAAmB,EAAE,aAAa,CAAC;CACpC,EACD,QAAQ,SAAS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E,CAAC,EAAE,aAAa,GACjB,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,EAAE,CAAC;IAY5B,UAAU,CACd,OAAO,EAAE,GAAG,CAAC,qBAAqB,CAAC,EACnC,EAAE,CAAC,EAAE,aAAa,GACjB,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAW1B,gBAAgB,CACpB,QAAQ,EAAE,aAAa,EAAE,EACzB,EAAE,CAAC,EAAE,aAAa,GACjB,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,EAAE,CAAC;IAiB5B,UAAU,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAK3D,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAKnE,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAW1D,mBAAmB,CAAC,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAa7E"}
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { transformIntoInternalDtoMapper } from '@forklaunch/core/mappers';
|
|
2
|
-
export class BaseUserService {
|
|
3
|
-
em;
|
|
4
|
-
passwordEncryptionPublicKeyPath;
|
|
5
|
-
roleServiceFactory;
|
|
6
|
-
organizationServiceFactory;
|
|
7
|
-
openTelemetryCollector;
|
|
8
|
-
schemaValidator;
|
|
9
|
-
mapperss;
|
|
10
|
-
#mapperss;
|
|
11
|
-
constructor(
|
|
12
|
-
em,
|
|
13
|
-
passwordEncryptionPublicKeyPath,
|
|
14
|
-
roleServiceFactory,
|
|
15
|
-
organizationServiceFactory,
|
|
16
|
-
openTelemetryCollector,
|
|
17
|
-
schemaValidator,
|
|
18
|
-
mapperss
|
|
19
|
-
) {
|
|
20
|
-
this.em = em;
|
|
21
|
-
this.passwordEncryptionPublicKeyPath = passwordEncryptionPublicKeyPath;
|
|
22
|
-
this.roleServiceFactory = roleServiceFactory;
|
|
23
|
-
this.organizationServiceFactory = organizationServiceFactory;
|
|
24
|
-
this.openTelemetryCollector = openTelemetryCollector;
|
|
25
|
-
this.schemaValidator = schemaValidator;
|
|
26
|
-
this.mapperss = mapperss;
|
|
27
|
-
this.#mapperss = transformIntoInternalDtoMapper(mapperss, schemaValidator);
|
|
28
|
-
}
|
|
29
|
-
async createUser(userDto, em) {
|
|
30
|
-
const user =
|
|
31
|
-
await this.#mapperss.CreateUserDtoMapper.deserializeDtoToEntity(
|
|
32
|
-
userDto,
|
|
33
|
-
this.passwordEncryptionPublicKeyPath
|
|
34
|
-
);
|
|
35
|
-
((await em) ?? this.em).transactional(async (em) => {
|
|
36
|
-
await em.persist(user);
|
|
37
|
-
});
|
|
38
|
-
return this.#mapperss.UserDtoMapper.serializeEntityToDto(user);
|
|
39
|
-
}
|
|
40
|
-
async createBatchUsers(userDtos, em) {
|
|
41
|
-
const users = await Promise.all(
|
|
42
|
-
userDtos.map(async (createUserDto) =>
|
|
43
|
-
this.#mapperss.CreateUserDtoMapper.deserializeDtoToEntity(
|
|
44
|
-
createUserDto,
|
|
45
|
-
this.passwordEncryptionPublicKeyPath
|
|
46
|
-
)
|
|
47
|
-
)
|
|
48
|
-
);
|
|
49
|
-
await (em ?? this.em).transactional(async (em) => {
|
|
50
|
-
await em.persist(users);
|
|
51
|
-
});
|
|
52
|
-
return users.map((user) =>
|
|
53
|
-
this.#mapperss.UserDtoMapper.serializeEntityToDto(user)
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
async getUser(idDto, em) {
|
|
57
|
-
const user = await (em ?? this.em).findOneOrFail('User', idDto, {
|
|
58
|
-
populate: ['id', '*']
|
|
59
|
-
});
|
|
60
|
-
return this.#mapperss.UserDtoMapper.serializeEntityToDto(user);
|
|
61
|
-
}
|
|
62
|
-
async getBatchUsers(idsDto, em) {
|
|
63
|
-
return (
|
|
64
|
-
await (em ?? this.em).find('User', idsDto, {
|
|
65
|
-
populate: ['id', '*']
|
|
66
|
-
})
|
|
67
|
-
).map((user) => this.#mapperss.UserDtoMapper.serializeEntityToDto(user));
|
|
68
|
-
}
|
|
69
|
-
async updateUser(userDto, em) {
|
|
70
|
-
let user = this.#mapperss.UpdateUserDtoMapper.deserializeDtoToEntity(
|
|
71
|
-
userDto,
|
|
72
|
-
this.passwordEncryptionPublicKeyPath
|
|
73
|
-
);
|
|
74
|
-
await (em ?? this.em).transactional(async (localEm) => {
|
|
75
|
-
user = await localEm.upsert(user);
|
|
76
|
-
});
|
|
77
|
-
return this.#mapperss.UserDtoMapper.serializeEntityToDto(user);
|
|
78
|
-
}
|
|
79
|
-
async updateBatchUsers(userDtos, em) {
|
|
80
|
-
let users = await Promise.all(
|
|
81
|
-
userDtos.map(async (updateUserDto) =>
|
|
82
|
-
this.#mapperss.UpdateUserDtoMapper.deserializeDtoToEntity(
|
|
83
|
-
updateUserDto,
|
|
84
|
-
this.passwordEncryptionPublicKeyPath
|
|
85
|
-
)
|
|
86
|
-
)
|
|
87
|
-
);
|
|
88
|
-
await (em ?? this.em).transactional(async (localEm) => {
|
|
89
|
-
users = await localEm.upsertMany(users);
|
|
90
|
-
});
|
|
91
|
-
return users.map((user) =>
|
|
92
|
-
this.#mapperss.UserDtoMapper.serializeEntityToDto(user)
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
async deleteUser(idDto, em) {
|
|
96
|
-
const entityManager = em || this.em;
|
|
97
|
-
await entityManager.nativeDelete('User', idDto);
|
|
98
|
-
}
|
|
99
|
-
async deleteBatchUsers(idsDto, em) {
|
|
100
|
-
const entityManager = em || this.em;
|
|
101
|
-
await entityManager.nativeDelete('User', idsDto);
|
|
102
|
-
}
|
|
103
|
-
async verifyHasRole(idDto, roleId) {
|
|
104
|
-
const user = await this.getUser(idDto);
|
|
105
|
-
if (
|
|
106
|
-
user.roles.filter((role) => {
|
|
107
|
-
return roleId == role.id;
|
|
108
|
-
}).length === 0
|
|
109
|
-
) {
|
|
110
|
-
throw new Error(`User ${idDto.id} does not have role ${roleId}`);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
async verifyHasPermission(idDto, permissionId) {
|
|
114
|
-
const user = await this.getUser(idDto);
|
|
115
|
-
if (
|
|
116
|
-
user.roles
|
|
117
|
-
.map((role) => role.permissions.map((permission) => permission.id))
|
|
118
|
-
.flat()
|
|
119
|
-
.filter((id) => id == permissionId).length === 0
|
|
120
|
-
) {
|
|
121
|
-
throw new Error(
|
|
122
|
-
`User ${idDto.id} does not have permission ${permissionId}`
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|