dl-commons 0.0.2-testing.20 → 0.0.2-testing.21
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 +2 -1
- package/dist/index.js +4 -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/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 +12 -0
- package/dist/services/iam.service.js +99 -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 +2 -0
- package/src/models/dtos/commons/id.param.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 +108 -0
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -112,6 +112,7 @@ 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';
|
|
115
116
|
|
|
116
117
|
export {
|
|
117
118
|
/**
|
|
@@ -172,6 +173,7 @@ export {
|
|
|
172
173
|
*/
|
|
173
174
|
I18nDTO,
|
|
174
175
|
CropAreaDTO,
|
|
176
|
+
IDParams,
|
|
175
177
|
|
|
176
178
|
/**
|
|
177
179
|
* 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,108 @@
|
|
|
1
|
+
import { HttpService } from '@nestjs/axios';
|
|
2
|
+
import { Injectable } from '@nestjs/common';
|
|
3
|
+
import { ConfigService } from '@nestjs/config';
|
|
4
|
+
import { RESTResponseBody, RESTError } from '../models/dtos/wrappers/rest-wrapper.class';
|
|
5
|
+
import { firstValueFrom } from 'rxjs';
|
|
6
|
+
import { IDictionary } from '../models/interfaces/dictionary.interface';
|
|
7
|
+
import { Types } from 'mongoose';
|
|
8
|
+
|
|
9
|
+
@Injectable()
|
|
10
|
+
export class IAMService {
|
|
11
|
+
//#region Private Members
|
|
12
|
+
private _baseUrl: string;
|
|
13
|
+
//#endregion
|
|
14
|
+
|
|
15
|
+
//#region Constructor
|
|
16
|
+
constructor(private readonly _httpService: HttpService, private readonly _configService: ConfigService) {
|
|
17
|
+
this._baseUrl = this._configService.getOrThrow('DL_IAM__REST__BASE_URL');
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
|
|
21
|
+
//#region Public API
|
|
22
|
+
public async fetchById(id: string) {
|
|
23
|
+
try {
|
|
24
|
+
const endpoint = `${this._baseUrl}/v1/dictionaries/by-id/${id}`;
|
|
25
|
+
const response$ = this._httpService.get<RESTResponseBody<IDictionary>>(endpoint);
|
|
26
|
+
const response = await firstValueFrom(response$);
|
|
27
|
+
|
|
28
|
+
if (response.data.errors) {
|
|
29
|
+
throw new RESTError('dictionaries_api_error', response.data.errors);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (!response.data || !response.data.result) {
|
|
33
|
+
throw new RESTError('dictionaries_api_error', 'empty response');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (response.data.result.data) {
|
|
37
|
+
const result: IDictionary = {
|
|
38
|
+
...response.data.result.data,
|
|
39
|
+
_id: new Types.ObjectId(response.data.result.data._id),
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
return result;
|
|
43
|
+
} else {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
} catch (e) {
|
|
47
|
+
throw RESTError.createFromCatch(e, { keyword: 'unknown', debug: e });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public async fetchByKeyword(keyword: string) {
|
|
52
|
+
try {
|
|
53
|
+
const endpoint = `${this._baseUrl}/v1/dictionaries/by-keyword/${keyword}`;
|
|
54
|
+
const response$ = this._httpService.get<RESTResponseBody<IDictionary>>(endpoint);
|
|
55
|
+
const response = await firstValueFrom(response$);
|
|
56
|
+
|
|
57
|
+
if (response.data.errors) {
|
|
58
|
+
throw new RESTError('dictionaries_api_error', response.data.errors);
|
|
59
|
+
}
|
|
60
|
+
if (!response.data || !response.data.result) {
|
|
61
|
+
throw new RESTError('dictionaries_api_error', 'empty response');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (response.data.result.data) {
|
|
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
|
+
}
|
|
74
|
+
} catch (e) {
|
|
75
|
+
throw RESTError.createFromCatch(e, { keyword: 'unknown', debug: e });
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
public async validateIds(ids: string[]) {
|
|
80
|
+
try {
|
|
81
|
+
const endpoint = `${this._baseUrl}/v1/dictionaries/validate/by-ids`;
|
|
82
|
+
const requestBody = { data: { ids } };
|
|
83
|
+
const response$ = this._httpService.post<RESTResponseBody<IDictionary[]>>(endpoint, requestBody);
|
|
84
|
+
const response = await firstValueFrom(response$);
|
|
85
|
+
|
|
86
|
+
if (response.data.errors) {
|
|
87
|
+
throw new RESTError('dictionaries_api_error', response.data.errors);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (!response.data || !response.data.result) {
|
|
91
|
+
throw new RESTError('dictionaries_api_error', 'empty response');
|
|
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
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return result;
|
|
103
|
+
} catch (e) {
|
|
104
|
+
throw RESTError.createFromCatch(e, { keyword: 'unknown', debug: e });
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
//#endregion
|
|
108
|
+
}
|