dl-commons 0.0.2-testing.33 → 0.0.2-testing.35

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dl-commons",
3
3
  "type": "commonjs",
4
- "version": "0.0.2-testing.33",
4
+ "version": "0.0.2-testing.35",
5
5
  "description": "distance learning commons",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -128,6 +128,8 @@ import { Location, LocationDocument, LocationSchema } from './models/schemas/emb
128
128
  import { ILocation } from './models/interfaces/location.interface';
129
129
  import { IArchive } from './models/interfaces/archive.interface';
130
130
  import { Archive, ArchiveDocument, ArchiveSchema } from './models/schemas/embedded/archive.schema';
131
+ import { StudentsService } from './services/students.service';
132
+ import { GroupsService } from './services/groups.service';
131
133
 
132
134
  export {
133
135
  /**
@@ -139,6 +141,8 @@ export {
139
141
  SMTPService,
140
142
  StorageService,
141
143
  IAMService,
144
+ StudentsService,
145
+ GroupsService,
142
146
 
143
147
  /**
144
148
  * Rest Wrapper
@@ -7,4 +7,6 @@ export const MONGO__CS = 'MONGO__CS';
7
7
  export const REDIS__CS = 'REDIS__CS';
8
8
  export const KAFKA__BROKERS = 'KAFKA__BROKERS';
9
9
 
10
- export const DL_SESSIONS__MONGO__CS = 'DL_SESSIONS__MONGO__CS';
10
+ export const DL_SESSIONS__MONGO__CS = 'DL_SESSIONS__MONGO__CS';
11
+ export const DL_STUDENTS__REST__BASE_URL = 'DL_STUDENTS__REST__BASE_URL';
12
+ export const DL_GROUPS__REST__BASE_URL = 'DL_GROUPS__REST__BASE_URL';
@@ -0,0 +1,8 @@
1
+ import { IBase } from './base.interface';
2
+
3
+ export interface IGroupRequestEmbedded extends IBase {
4
+ status: string;
5
+ action: string;
6
+ description: string;
7
+ reason: string;
8
+ }
@@ -0,0 +1,63 @@
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 { DL_GROUPS__REST__BASE_URL } from '../models/consts/env-vars.const';
7
+ import { IGroupEmbedded } from '../models/interfaces/group-embedded.interface';
8
+ import { IGroupRequestEmbedded } from '../models/interfaces/group-request.interface';
9
+
10
+ @Injectable()
11
+ export class GroupsService {
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_GROUPS__REST__BASE_URL);
19
+ }
20
+ //#endregion
21
+
22
+ //#region Public API
23
+ public async readGroup(id: string): Promise<IGroupEmbedded> {
24
+ try {
25
+ const endpoint = `${this._baseUrl}/v1/groups/${id}`;
26
+ const response$ = this._httpService.get<RESTResponseBody<IGroupEmbedded>>(endpoint);
27
+ const response = await firstValueFrom(response$);
28
+
29
+ if (response.data.errors) {
30
+ throw new RESTError('students_api_error', response.data.errors);
31
+ }
32
+
33
+ if (!response.data || !response.data.result) {
34
+ throw new RESTError('students_api_error', 'empty response');
35
+ }
36
+
37
+ return response.data.result.data;
38
+ } catch (e) {
39
+ throw RESTError.createFromCatch(e, { keyword: 'unknown', debug: e });
40
+ }
41
+ }
42
+
43
+ public async readGroupRequest(id: string): Promise<IGroupRequestEmbedded> {
44
+ try {
45
+ const endpoint = `${this._baseUrl}/v1/group-requests/${id}`;
46
+ const response$ = this._httpService.get<RESTResponseBody<IGroupRequestEmbedded>>(endpoint);
47
+ const response = await firstValueFrom(response$);
48
+
49
+ if (response.data.errors) {
50
+ throw new RESTError('students_api_error', response.data.errors);
51
+ }
52
+
53
+ if (!response.data || !response.data.result) {
54
+ throw new RESTError('students_api_error', 'empty response');
55
+ }
56
+
57
+ return response.data.result.data;
58
+ } catch (e) {
59
+ throw RESTError.createFromCatch(e, { keyword: 'unknown', debug: e });
60
+ }
61
+ }
62
+ //#endregion
63
+ }
@@ -0,0 +1,42 @@
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 { DL_STUDENTS__REST__BASE_URL } from '../models/consts/env-vars.const';
7
+ import { IStudentEmbedded } from '../models/interfaces/student-embedded.interface';
8
+
9
+ @Injectable()
10
+ export class StudentsService {
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_STUDENTS__REST__BASE_URL);
18
+ }
19
+ //#endregion
20
+
21
+ //#region Public API
22
+ public async read(id: string): Promise<IStudentEmbedded> {
23
+ try {
24
+ const endpoint = `${this._baseUrl}/v1/students/${id}`;
25
+ const response$ = this._httpService.get<RESTResponseBody<IStudentEmbedded>>(endpoint);
26
+ const response = await firstValueFrom(response$);
27
+
28
+ if (response.data.errors) {
29
+ throw new RESTError('students_api_error', response.data.errors);
30
+ }
31
+
32
+ if (!response.data || !response.data.result) {
33
+ throw new RESTError('students_api_error', 'empty response');
34
+ }
35
+
36
+ return response.data.result.data;
37
+ } catch (e) {
38
+ throw RESTError.createFromCatch(e, { keyword: 'unknown', debug: e });
39
+ }
40
+ }
41
+ //#endregion
42
+ }