dl-commons 0.0.2-testing.20 → 0.0.2-testing.22
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/index.d.ts +4 -1
- package/dist/index.js +8 -2
- package/dist/index.js.map +1 -1
- package/dist/models/dtos/commons/id.param.d.ts +3 -0
- package/dist/models/dtos/commons/id.param.js +22 -0
- package/dist/models/dtos/commons/id.param.js.map +1 -0
- 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/models/interfaces/s3.interface.d.ts +0 -1
- package/dist/models/schemas/embedded/s3.schema.d.ts +0 -1
- package/dist/models/schemas/embedded/s3.schema.js +0 -4
- package/dist/models/schemas/embedded/s3.schema.js.map +1 -1
- package/dist/services/iam.service.d.ts +14 -0
- package/dist/services/iam.service.js +78 -0
- package/dist/services/iam.service.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/index.ts +6 -0
- package/src/models/dtos/commons/id.param.ts +7 -0
- package/src/models/enums/user-type.enum.ts +7 -0
- package/src/models/interfaces/s3.interface.ts +0 -1
- package/src/models/schemas/embedded/s3.schema.ts +0 -3
- package/src/services/iam.service.ts +82 -0
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -112,6 +112,9 @@ import { IAuthor } from './models/interfaces/author.interface';
|
|
|
112
112
|
import { Author, AuthorDocument, AuthorSchema } from './models/schemas/embedded/author.schema';
|
|
113
113
|
import { CropAreaDTO } from './models/dtos/commons/crop-area.dto';
|
|
114
114
|
import { StorageService } from './services/storage.service';
|
|
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';
|
|
115
118
|
|
|
116
119
|
export {
|
|
117
120
|
/**
|
|
@@ -121,6 +124,7 @@ export {
|
|
|
121
124
|
DictionariesService,
|
|
122
125
|
SMTPService,
|
|
123
126
|
StorageService,
|
|
127
|
+
IAMService,
|
|
124
128
|
|
|
125
129
|
/**
|
|
126
130
|
* Rest Wrapper
|
|
@@ -161,6 +165,7 @@ export {
|
|
|
161
165
|
RecordState,
|
|
162
166
|
ContactType,
|
|
163
167
|
UserVerificationLevel,
|
|
168
|
+
UserType,
|
|
164
169
|
WeekDay,
|
|
165
170
|
GroupState,
|
|
166
171
|
S3FileState,
|
|
@@ -172,6 +177,7 @@ export {
|
|
|
172
177
|
*/
|
|
173
178
|
I18nDTO,
|
|
174
179
|
CropAreaDTO,
|
|
180
|
+
IDParams,
|
|
175
181
|
|
|
176
182
|
/**
|
|
177
183
|
* Interfaces
|
|
@@ -107,9 +107,6 @@ export class FileEmbedded implements IFileEmbedded {
|
|
|
107
107
|
@Prop({ type: S3, required: true, default: null })
|
|
108
108
|
s3: S3;
|
|
109
109
|
|
|
110
|
-
@Prop({ type: String, enum: S3FileState, required: true })
|
|
111
|
-
state: S3FileState;
|
|
112
|
-
|
|
113
110
|
@Prop({ type: Date, required: true })
|
|
114
111
|
createdAt: Date;
|
|
115
112
|
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { HttpService } from '@nestjs/axios';
|
|
2
|
+
import { Injectable } from '@nestjs/common';
|
|
3
|
+
import { ConfigService } from '@nestjs/config';
|
|
4
|
+
import { RESTResponseBody, RESTError, RESTResult } from '../models/dtos/wrappers/rest-wrapper.class';
|
|
5
|
+
import { firstValueFrom } from 'rxjs';
|
|
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';
|
|
9
|
+
|
|
10
|
+
@Injectable()
|
|
11
|
+
export class IAMService {
|
|
12
|
+
//#region Private Members
|
|
13
|
+
private _baseUrl: string;
|
|
14
|
+
//#endregion
|
|
15
|
+
|
|
16
|
+
//#region Constructor
|
|
17
|
+
constructor(private readonly _httpService: HttpService, private readonly _configService: ConfigService) {
|
|
18
|
+
this._baseUrl = this._configService.getOrThrow('DL_IAM__REST__BASE_URL');
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
|
|
22
|
+
//#region Public API
|
|
23
|
+
public async list(firstName: string, lastName: string, types: UserType[], verificationLevels: UserVerificationLevel[]): Promise<RESTResult<IUser[]>> {
|
|
24
|
+
try {
|
|
25
|
+
const queryParams = new URLSearchParams();
|
|
26
|
+
if (firstName) {
|
|
27
|
+
queryParams.append('firstName', firstName);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (lastName) {
|
|
31
|
+
queryParams.append('lastName', lastName);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (types && types.length) {
|
|
35
|
+
types.forEach((type) => queryParams.append('types', type));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (verificationLevels && verificationLevels.length) {
|
|
39
|
+
verificationLevels.forEach((level) => queryParams.append('verificationLevels', level));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const qs = queryParams.toString();
|
|
43
|
+
|
|
44
|
+
const endpoint = `${this._baseUrl}/v1/users?${qs}`;
|
|
45
|
+
const response$ = this._httpService.get<RESTResponseBody<IUser[]>>(endpoint);
|
|
46
|
+
const response = await firstValueFrom(response$);
|
|
47
|
+
|
|
48
|
+
if (response.data.errors) {
|
|
49
|
+
throw new RESTError('iam_api_error', response.data.errors);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (!response.data || !response.data.result) {
|
|
53
|
+
throw new RESTError('iam_api_error', 'empty response');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return response.data.result;
|
|
57
|
+
} catch (e) {
|
|
58
|
+
throw RESTError.createFromCatch(e, { keyword: 'unknown', debug: e });
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
public async read(id: string) : Promise<RESTResult<IUser>> {
|
|
63
|
+
try {
|
|
64
|
+
const endpoint = `${this._baseUrl}/v1/users/${id}`;
|
|
65
|
+
const response$ = this._httpService.get<RESTResponseBody<IUser>>(endpoint);
|
|
66
|
+
const response = await firstValueFrom(response$);
|
|
67
|
+
|
|
68
|
+
if (response.data.errors) {
|
|
69
|
+
throw new RESTError('iam_api_error', response.data.errors);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (!response.data || !response.data.result) {
|
|
73
|
+
throw new RESTError('iam_api_error', 'empty response');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return response.data.result;
|
|
77
|
+
} catch (e) {
|
|
78
|
+
throw RESTError.createFromCatch(e, { keyword: 'unknown', debug: e });
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
//#endregion
|
|
82
|
+
}
|