dl-commons 0.0.2-testing.21 → 0.0.2-testing.23
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/dist/guards/permission.guard.js +1 -1
- package/dist/guards/permission.guard.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/dist/models/enums/user-type.enum.d.ts +7 -0
- package/dist/models/enums/user-type.enum.js +12 -0
- package/dist/models/enums/user-type.enum.js.map +1 -0
- package/dist/services/iam.service.d.ts +6 -4
- package/dist/services/iam.service.js +21 -42
- package/dist/services/iam.service.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/guards/permission.guard.ts +1 -1
- package/src/index.ts +4 -0
- package/src/models/enums/user-type.enum.ts +7 -0
- package/src/services/iam.service.ts +29 -55
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@ export class PermissionGuardArgs {
|
|
|
7
7
|
verificationLevels?: string[] | null | undefined;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
export const AllowPermissions = Reflector.createDecorator<PermissionGuardArgs>();
|
|
10
|
+
export const AllowPermissions = Reflector.createDecorator<PermissionGuardArgs>({ key: 'AllowPermissions' });
|
|
11
11
|
|
|
12
12
|
@Injectable()
|
|
13
13
|
export class PermissionGuard implements CanActivate {
|
package/src/index.ts
CHANGED
|
@@ -113,6 +113,8 @@ import { Author, AuthorDocument, AuthorSchema } from './models/schemas/embedded/
|
|
|
113
113
|
import { CropAreaDTO } from './models/dtos/commons/crop-area.dto';
|
|
114
114
|
import { StorageService } from './services/storage.service';
|
|
115
115
|
import { IDParams } from './models/dtos/commons/id.param';
|
|
116
|
+
import { UserType } from './models/enums/user-type.enum';
|
|
117
|
+
import { IAMService } from './services/iam.service';
|
|
116
118
|
|
|
117
119
|
export {
|
|
118
120
|
/**
|
|
@@ -122,6 +124,7 @@ export {
|
|
|
122
124
|
DictionariesService,
|
|
123
125
|
SMTPService,
|
|
124
126
|
StorageService,
|
|
127
|
+
IAMService,
|
|
125
128
|
|
|
126
129
|
/**
|
|
127
130
|
* Rest Wrapper
|
|
@@ -162,6 +165,7 @@ export {
|
|
|
162
165
|
RecordState,
|
|
163
166
|
ContactType,
|
|
164
167
|
UserVerificationLevel,
|
|
168
|
+
UserType,
|
|
165
169
|
WeekDay,
|
|
166
170
|
GroupState,
|
|
167
171
|
S3FileState,
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { HttpService } from '@nestjs/axios';
|
|
2
2
|
import { Injectable } from '@nestjs/common';
|
|
3
3
|
import { ConfigService } from '@nestjs/config';
|
|
4
|
-
import { RESTResponseBody, RESTError } from '../models/dtos/wrappers/rest-wrapper.class';
|
|
4
|
+
import { RESTResponseBody, RESTError, RESTResult } from '../models/dtos/wrappers/rest-wrapper.class';
|
|
5
5
|
import { firstValueFrom } from 'rxjs';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
6
|
+
import { UserVerificationLevel } from '../models/enums/user-verifiation-level.enum';
|
|
7
|
+
import { UserType } from '../models/enums/user-type.enum';
|
|
8
|
+
import { IUser } from '../models/interfaces/user.interface';
|
|
8
9
|
|
|
9
10
|
@Injectable()
|
|
10
11
|
export class IAMService {
|
|
@@ -19,87 +20,60 @@ export class IAMService {
|
|
|
19
20
|
//#endregion
|
|
20
21
|
|
|
21
22
|
//#region Public API
|
|
22
|
-
public async
|
|
23
|
+
public async list(firstName: string, lastName: string, types: UserType[], verificationLevels: UserVerificationLevel[]): Promise<RESTResult<IUser[]>> {
|
|
23
24
|
try {
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (response.data.errors) {
|
|
29
|
-
throw new RESTError('dictionaries_api_error', response.data.errors);
|
|
25
|
+
const queryParams = new URLSearchParams();
|
|
26
|
+
if (firstName) {
|
|
27
|
+
queryParams.append('firstName', firstName);
|
|
30
28
|
}
|
|
31
29
|
|
|
32
|
-
if (
|
|
33
|
-
|
|
30
|
+
if (lastName) {
|
|
31
|
+
queryParams.append('lastName', lastName);
|
|
34
32
|
}
|
|
35
33
|
|
|
36
|
-
if (
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
_id: new Types.ObjectId(response.data.result.data._id),
|
|
40
|
-
};
|
|
34
|
+
if (types && types.length) {
|
|
35
|
+
types.forEach((type) => queryParams.append('types', type));
|
|
36
|
+
}
|
|
41
37
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return null;
|
|
38
|
+
if (verificationLevels && verificationLevels.length) {
|
|
39
|
+
verificationLevels.forEach((level) => queryParams.append('verificationLevels', level));
|
|
45
40
|
}
|
|
46
|
-
} catch (e) {
|
|
47
|
-
throw RESTError.createFromCatch(e, { keyword: 'unknown', debug: e });
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
41
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const endpoint = `${this._baseUrl}/v1/
|
|
54
|
-
const response$ = this._httpService.get<RESTResponseBody<
|
|
42
|
+
const qs = queryParams.toString();
|
|
43
|
+
|
|
44
|
+
const endpoint = `${this._baseUrl}/v1/users?${qs}`;
|
|
45
|
+
const response$ = this._httpService.get<RESTResponseBody<IUser[]>>(endpoint);
|
|
55
46
|
const response = await firstValueFrom(response$);
|
|
56
47
|
|
|
57
48
|
if (response.data.errors) {
|
|
58
|
-
throw new RESTError('
|
|
49
|
+
throw new RESTError('iam_api_error', response.data.errors);
|
|
59
50
|
}
|
|
51
|
+
|
|
60
52
|
if (!response.data || !response.data.result) {
|
|
61
|
-
throw new RESTError('
|
|
53
|
+
throw new RESTError('iam_api_error', 'empty response');
|
|
62
54
|
}
|
|
63
55
|
|
|
64
|
-
|
|
65
|
-
const result: IDictionary = {
|
|
66
|
-
...response.data.result.data,
|
|
67
|
-
_id: new Types.ObjectId(response.data.result.data._id),
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
return result;
|
|
71
|
-
} else {
|
|
72
|
-
return null;
|
|
73
|
-
}
|
|
56
|
+
return response.data.result;
|
|
74
57
|
} catch (e) {
|
|
75
58
|
throw RESTError.createFromCatch(e, { keyword: 'unknown', debug: e });
|
|
76
59
|
}
|
|
77
60
|
}
|
|
78
61
|
|
|
79
|
-
public async
|
|
62
|
+
public async read(id: string) : Promise<RESTResult<IUser>> {
|
|
80
63
|
try {
|
|
81
|
-
const endpoint = `${this._baseUrl}/v1/
|
|
82
|
-
const
|
|
83
|
-
const response$ = this._httpService.post<RESTResponseBody<IDictionary[]>>(endpoint, requestBody);
|
|
64
|
+
const endpoint = `${this._baseUrl}/v1/users/${id}`;
|
|
65
|
+
const response$ = this._httpService.get<RESTResponseBody<IUser>>(endpoint);
|
|
84
66
|
const response = await firstValueFrom(response$);
|
|
85
67
|
|
|
86
68
|
if (response.data.errors) {
|
|
87
|
-
throw new RESTError('
|
|
69
|
+
throw new RESTError('iam_api_error', response.data.errors);
|
|
88
70
|
}
|
|
89
71
|
|
|
90
72
|
if (!response.data || !response.data.result) {
|
|
91
|
-
throw new RESTError('
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const result: IDictionary[] = [];
|
|
95
|
-
for (let item of response.data.result.data) {
|
|
96
|
-
result.push({
|
|
97
|
-
...item,
|
|
98
|
-
_id: new Types.ObjectId(item._id),
|
|
99
|
-
});
|
|
73
|
+
throw new RESTError('iam_api_error', 'empty response');
|
|
100
74
|
}
|
|
101
75
|
|
|
102
|
-
return result;
|
|
76
|
+
return response.data.result;
|
|
103
77
|
} catch (e) {
|
|
104
78
|
throw RESTError.createFromCatch(e, { keyword: 'unknown', debug: e });
|
|
105
79
|
}
|