dl-commons 0.0.2-testing.32 → 0.0.2-testing.34

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.
Files changed (34) hide show
  1. package/dist/index.d.ts +6 -4
  2. package/dist/index.js +12 -8
  3. package/dist/index.js.map +1 -1
  4. package/dist/models/consts/env-vars.const.d.ts +2 -0
  5. package/dist/models/consts/env-vars.const.js +3 -1
  6. package/dist/models/consts/env-vars.const.js.map +1 -1
  7. package/dist/models/enums/attachment-type.enum.d.ts +4 -0
  8. package/dist/models/enums/attachment-type.enum.js +9 -0
  9. package/dist/models/enums/attachment-type.enum.js.map +1 -0
  10. package/dist/models/interfaces/attachment.interface.d.ts +8 -0
  11. package/dist/models/interfaces/attachment.interface.js +3 -0
  12. package/dist/models/interfaces/attachment.interface.js.map +1 -0
  13. package/dist/models/interfaces/group-request.interface.d.ts +7 -0
  14. package/dist/models/interfaces/group-request.interface.js +3 -0
  15. package/dist/models/interfaces/group-request.interface.js.map +1 -0
  16. package/dist/models/schemas/embedded/attachment.schema.d.ts +20 -0
  17. package/dist/models/schemas/embedded/attachment.schema.js +36 -0
  18. package/dist/models/schemas/embedded/attachment.schema.js.map +1 -0
  19. package/dist/services/groups.service.d.ts +13 -0
  20. package/dist/services/groups.service.js +65 -0
  21. package/dist/services/groups.service.js.map +1 -0
  22. package/dist/services/students.service.d.ts +11 -0
  23. package/dist/services/students.service.js +48 -0
  24. package/dist/services/students.service.js.map +1 -0
  25. package/dist/tsconfig.tsbuildinfo +1 -1
  26. package/package.json +1 -1
  27. package/src/index.ts +12 -8
  28. package/src/models/consts/env-vars.const.ts +3 -1
  29. package/src/models/enums/{attachement-type.enum.ts → attachment-type.enum.ts} +1 -1
  30. package/src/models/interfaces/{attachement.interface.ts → attachment.interface.ts} +3 -3
  31. package/src/models/interfaces/group-request.interface.ts +8 -0
  32. package/src/models/schemas/embedded/{attachement.schema.ts → attachment.schema.ts} +7 -7
  33. package/src/services/groups.service.ts +63 -0
  34. package/src/services/students.service.ts +42 -0
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.32",
4
+ "version": "0.0.2-testing.34",
5
5
  "description": "distance learning commons",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -103,9 +103,9 @@ import {
103
103
  import { IUserMeta } from './models/interfaces/user-meta.interface';
104
104
  import { ICropArea } from './models/interfaces/crop-area.interface';
105
105
  import { CropArea, CropAreaDocument, CropAreaSchema } from './models/schemas/embedded/crop-area.schema';
106
- import { AttachementType } from './models/enums/attachement-type.enum';
107
- import { IAttachement } from './models/interfaces/attachement.interface';
108
- import { Attachement, AttachementDocument, AttachementSchema } from './models/schemas/embedded/attachement.schema';
106
+ import { AttachmentType } from './models/enums/attachment-type.enum';
107
+ import { IAttachment } from './models/interfaces/attachment.interface';
108
+ import { Attachment, AttachmentDocument, AttachmentSchema } from './models/schemas/embedded/attachment.schema';
109
109
  import { Picture, PictureSchema, PictureDocument } from './models/schemas/embedded/picture.schema';
110
110
  import { IPicture } from './models/interfaces/picture.interface';
111
111
  import { IAuthor } from './models/interfaces/author.interface';
@@ -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
@@ -184,7 +188,7 @@ export {
184
188
  GroupState,
185
189
  S3FileState,
186
190
  FileLogInitType,
187
- AttachementType,
191
+ AttachmentType,
188
192
  VirtualAddressType,
189
193
  LocationType,
190
194
 
@@ -227,7 +231,7 @@ export {
227
231
  IFileLog,
228
232
  IUserMeta,
229
233
  ICropArea,
230
- IAttachement,
234
+ IAttachment,
231
235
  IPicture,
232
236
  IAuthor,
233
237
  IFileEmbedded,
@@ -309,9 +313,9 @@ export {
309
313
  CropArea,
310
314
  CropAreaSchema,
311
315
  CropAreaDocument,
312
- Attachement,
313
- AttachementSchema,
314
- AttachementDocument,
316
+ Attachment,
317
+ AttachmentSchema,
318
+ AttachmentDocument,
315
319
  Picture,
316
320
  PictureSchema,
317
321
  PictureDocument,
@@ -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';
@@ -1,4 +1,4 @@
1
- export enum AttachementType {
1
+ export enum AttachmentType {
2
2
  File = 'file',
3
3
  Link = 'link',
4
4
  }
@@ -1,9 +1,9 @@
1
- import { AttachementType } from '../enums/attachement-type.enum';
1
+ import { AttachmentType } from '../enums/attachment-type.enum';
2
2
  import { IIdentifable } from './identifable.interface';
3
3
  import { IFileEmbedded } from './s3.interface';
4
4
 
5
- export interface IAttachement extends IIdentifable {
6
- type: AttachementType;
5
+ export interface IAttachment extends IIdentifable {
6
+ type: AttachmentType;
7
7
  file?: IFileEmbedded | null | undefined;
8
8
  link?: string | null | undefined;
9
9
  }
@@ -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
+ }
@@ -1,15 +1,15 @@
1
1
  import { Schema, Prop, SchemaFactory } from '@nestjs/mongoose';
2
2
  import { HydratedDocument } from 'mongoose';
3
- import { IAttachement } from '../../interfaces/attachement.interface';
3
+ import { IAttachment } from '../../interfaces/attachment.interface';
4
4
  import { Identifable } from '../identifable.schema';
5
- import { AttachementType } from '../../enums/attachement-type.enum';
5
+ import { AttachmentType } from '../../enums/attachment-type.enum';
6
6
  import { IFileEmbedded } from '../../interfaces/s3.interface';
7
7
  import { FileEmbeddedSchema } from './s3.schema';
8
8
 
9
9
  @Schema({ _id: false })
10
- export class Attachement extends Identifable implements IAttachement {
11
- @Prop({ required: true, enum: AttachementType, type: String })
12
- type: AttachementType;
10
+ export class Attachment extends Identifable implements IAttachment {
11
+ @Prop({ required: true, enum: AttachmentType, type: String })
12
+ type: AttachmentType;
13
13
 
14
14
  @Prop({ type: FileEmbeddedSchema, required: false, default: null })
15
15
  file: IFileEmbedded;
@@ -18,5 +18,5 @@ export class Attachement extends Identifable implements IAttachement {
18
18
  link: string;
19
19
  }
20
20
 
21
- export const AttachementSchema = SchemaFactory.createForClass(Attachement);
22
- export type AttachementDocument = HydratedDocument<Attachement>;
21
+ export const AttachmentSchema = SchemaFactory.createForClass(Attachment);
22
+ export type AttachmentDocument = HydratedDocument<Attachment>;
@@ -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<RESTResult<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;
38
+ } catch (e) {
39
+ throw RESTError.createFromCatch(e, { keyword: 'unknown', debug: e });
40
+ }
41
+ }
42
+
43
+ public async readGroupRequest(id: string): Promise<RESTResult<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;
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<RESTResult<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;
37
+ } catch (e) {
38
+ throw RESTError.createFromCatch(e, { keyword: 'unknown', debug: e });
39
+ }
40
+ }
41
+ //#endregion
42
+ }