dl-commons 0.0.1-testing.3 → 0.0.1-testing.4
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/interfaces/person.interface.d.ts +2 -0
- package/dist/models/schemas/embedded/person.schema.d.ts +2 -0
- package/dist/models/schemas/embedded/person.schema.js +5 -0
- package/dist/models/schemas/embedded/person.schema.js.map +1 -1
- package/dist/services/dictionaries.service.d.ts +1 -0
- package/dist/services/dictionaries.service.js +27 -2
- package/dist/services/dictionaries.service.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/index.ts +2 -0
- package/src/models/interfaces/person.interface.ts +2 -0
- package/src/models/schemas/embedded/person.schema.ts +5 -0
- package/src/services/dictionaries.service.ts +44 -2
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dl-commons",
|
|
3
3
|
"type": "commonjs",
|
|
4
|
-
"version": "0.0.1-testing.
|
|
4
|
+
"version": "0.0.1-testing.4",
|
|
5
5
|
"description": "distance learning commons",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"build": "tsc",
|
|
11
11
|
"pack": "npm run build && npm pack --pack-destination ./packs"
|
|
12
12
|
},
|
|
13
|
-
"author": "",
|
|
13
|
+
"author": "Giorgi Maisuradze",
|
|
14
14
|
"license": "ISC",
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@nestjs/axios": "^3.1.0",
|
package/src/index.ts
CHANGED
|
@@ -49,12 +49,14 @@ import { transformers } from './transformers/common.transformer';
|
|
|
49
49
|
import { IUser } from './models/interfaces/user.interface';
|
|
50
50
|
import { SessionUser, SessionUserDocument, SessionUserSchema } from './models/schemas/embedded/session-user.schema';
|
|
51
51
|
import { Session, SessionDocument, SessionSchema } from './models/schemas/session.schema';
|
|
52
|
+
import { DictionariesService } from './services/dictionaries.service';
|
|
52
53
|
|
|
53
54
|
export {
|
|
54
55
|
/**
|
|
55
56
|
* Services
|
|
56
57
|
*/
|
|
57
58
|
SessionsService,
|
|
59
|
+
DictionariesService,
|
|
58
60
|
|
|
59
61
|
/**
|
|
60
62
|
* Rest Wrapper
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { IDictionary } from './dictionary.interface';
|
|
1
2
|
import { IResidence } from './residence.interface';
|
|
2
3
|
|
|
3
4
|
export interface IPerson {
|
|
4
5
|
pid?: string | null | undefined;
|
|
5
6
|
firstName: string;
|
|
6
7
|
lastName: string;
|
|
8
|
+
gender?: IDictionary | null | undefined;
|
|
7
9
|
birthDate?: Date | null | undefined;
|
|
8
10
|
residence?: IResidence | null | undefined;
|
|
9
11
|
}
|
|
@@ -3,6 +3,8 @@ import { IPerson } from '../../interfaces/person.interface';
|
|
|
3
3
|
import { HydratedDocument } from 'mongoose';
|
|
4
4
|
import { IResidence } from '../../interfaces/residence.interface';
|
|
5
5
|
import { Residence, ResidenceSchema } from './residence.schema';
|
|
6
|
+
import { DictionaryEmbeddedSchema } from './dictionary-embedded.schema';
|
|
7
|
+
import { IDictionary } from '../../interfaces/dictionary.interface';
|
|
6
8
|
|
|
7
9
|
@Schema({ _id: false })
|
|
8
10
|
export class Person implements IPerson {
|
|
@@ -18,6 +20,9 @@ export class Person implements IPerson {
|
|
|
18
20
|
@Prop({ type: Date, required: false, default: null })
|
|
19
21
|
birthDate: Date;
|
|
20
22
|
|
|
23
|
+
@Prop({ type: DictionaryEmbeddedSchema, required: false })
|
|
24
|
+
gender: IDictionary;
|
|
25
|
+
|
|
21
26
|
@Prop({ type: ResidenceSchema, required: true, default: () => new Residence() })
|
|
22
27
|
residence: IResidence;
|
|
23
28
|
}
|
|
@@ -4,6 +4,7 @@ import { ConfigService } from '@nestjs/config';
|
|
|
4
4
|
import { RESTResponseBody, RESTError } from '../models/dtos/wrappers/rest-wrapper.class';
|
|
5
5
|
import { firstValueFrom } from 'rxjs';
|
|
6
6
|
import { IDictionary } from '../models/interfaces/dictionary.interface';
|
|
7
|
+
import { Types } from 'mongoose';
|
|
7
8
|
|
|
8
9
|
@Injectable()
|
|
9
10
|
export class DictionariesService {
|
|
@@ -30,7 +31,13 @@ export class DictionariesService {
|
|
|
30
31
|
if (!response.data || !response.data.result) {
|
|
31
32
|
throw new RESTError('dictionaries_api_error', 'empty response');
|
|
32
33
|
}
|
|
33
|
-
|
|
34
|
+
|
|
35
|
+
const result: IDictionary = {
|
|
36
|
+
...response.data.result.data,
|
|
37
|
+
_id: new Types.ObjectId(response.data.result.data._id),
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
return result;
|
|
34
41
|
} catch (e) {
|
|
35
42
|
throw RESTError.createFromCatch(e, { keyword: 'unknown', debug: e });
|
|
36
43
|
}
|
|
@@ -48,7 +55,42 @@ export class DictionariesService {
|
|
|
48
55
|
if (!response.data || !response.data.result) {
|
|
49
56
|
throw new RESTError('dictionaries_api_error', 'empty response');
|
|
50
57
|
}
|
|
51
|
-
|
|
58
|
+
|
|
59
|
+
const result: IDictionary = {
|
|
60
|
+
...response.data.result.data,
|
|
61
|
+
_id: new Types.ObjectId(response.data.result.data._id),
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
return result;
|
|
65
|
+
} catch (e) {
|
|
66
|
+
throw RESTError.createFromCatch(e, { keyword: 'unknown', debug: e });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
public async validateIds(ids: string[]) {
|
|
71
|
+
try {
|
|
72
|
+
const endpoint = `${this._baseUrl}/v1/dictionaries/validate/by-ids`;
|
|
73
|
+
const requestBody = { data: { ids } };
|
|
74
|
+
const response$ = this._httpService.post<RESTResponseBody<IDictionary[]>>(endpoint, requestBody);
|
|
75
|
+
const response = await firstValueFrom(response$);
|
|
76
|
+
|
|
77
|
+
if (response.data.errors) {
|
|
78
|
+
throw new RESTError('dictionaries_api_error', response.data.errors);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (!response.data || !response.data.result) {
|
|
82
|
+
throw new RESTError('dictionaries_api_error', 'empty response');
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const result: IDictionary[] = [];
|
|
86
|
+
for (let item of response.data.result.data) {
|
|
87
|
+
result.push({
|
|
88
|
+
...item,
|
|
89
|
+
_id: new Types.ObjectId(item._id),
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return result;
|
|
52
94
|
} catch (e) {
|
|
53
95
|
throw RESTError.createFromCatch(e, { keyword: 'unknown', debug: e });
|
|
54
96
|
}
|