dl-commons 0.0.2-testing.1 → 0.0.2-testing.10
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 +9 -2
- package/dist/index.js +27 -2
- package/dist/index.js.map +1 -1
- package/dist/models/enums/s3.enum.d.ts +11 -0
- package/dist/models/enums/s3.enum.js +17 -0
- package/dist/models/enums/s3.enum.js.map +1 -0
- package/dist/models/interfaces/group-session.interface.d.ts +6 -2
- package/dist/models/interfaces/s3.interface.d.ts +47 -0
- package/dist/models/interfaces/s3.interface.js +3 -0
- package/dist/models/interfaces/s3.interface.js.map +1 -0
- package/dist/models/interfaces/smtp-api-config.interface.d.ts +5 -0
- package/dist/models/interfaces/smtp-api-config.interface.js +3 -0
- package/dist/models/interfaces/smtp-api-config.interface.js.map +1 -0
- package/dist/models/interfaces/smtp.interface.d.ts +5 -0
- package/dist/models/interfaces/smtp.interface.js +3 -0
- package/dist/models/interfaces/smtp.interface.js.map +1 -0
- package/dist/models/interfaces/user-meta.interface.d.ts +4 -0
- package/dist/models/interfaces/user-meta.interface.js +3 -0
- package/dist/models/interfaces/user-meta.interface.js.map +1 -0
- package/dist/models/interfaces/user.interface.d.ts +1 -0
- package/dist/models/schemas/base.schema.d.ts +2 -2
- package/dist/models/schemas/embedded/contact.schema.d.ts +2 -2
- package/dist/models/schemas/embedded/dictionary-embedded.schema.d.ts +2 -2
- package/dist/models/schemas/embedded/group-session.schema.d.ts +4 -5
- package/dist/models/schemas/embedded/group-session.schema.js +4 -7
- package/dist/models/schemas/embedded/group-session.schema.js.map +1 -1
- package/dist/models/schemas/embedded/i18n.embedded.d.ts +2 -2
- package/dist/models/schemas/embedded/person.schema.d.ts +2 -2
- package/dist/models/schemas/embedded/record.embedded.d.ts +2 -2
- package/dist/models/schemas/embedded/residence.schema.d.ts +2 -2
- package/dist/models/schemas/embedded/s3.schema.d.ts +128 -0
- package/dist/models/schemas/embedded/s3.schema.js +188 -0
- package/dist/models/schemas/embedded/s3.schema.js.map +1 -0
- package/dist/models/schemas/embedded/session-user.schema.d.ts +2 -2
- package/dist/models/schemas/embedded/student-embedded.schema.d.ts +2 -2
- package/dist/models/schemas/embedded/teacher.schema.d.ts +2 -2
- package/dist/models/schemas/embedded/time.schema.d.ts +17 -0
- package/dist/models/schemas/embedded/time.schema.js +33 -0
- package/dist/models/schemas/embedded/time.schema.js.map +1 -0
- package/dist/models/schemas/identifable.schema.d.ts +2 -2
- package/dist/models/schemas/parent.schema.d.ts +2 -2
- package/dist/models/schemas/session.schema.d.ts +2 -2
- package/dist/services/sessions.service.d.ts +4 -1
- package/dist/services/sessions.service.js +34 -0
- package/dist/services/sessions.service.js.map +1 -1
- package/dist/services/smtp.service.d.ts +11 -0
- package/dist/services/smtp.service.js +71 -0
- package/dist/services/smtp.service.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/index.ts +85 -3
- package/src/models/enums/s3.enum.ts +12 -0
- package/src/models/interfaces/group-session.interface.ts +7 -2
- package/src/models/interfaces/s3.interface.ts +55 -0
- package/src/models/interfaces/smtp-api-config.interface.ts +5 -0
- package/src/models/interfaces/smtp.interface.ts +5 -0
- package/src/models/interfaces/user-meta.interface.ts +4 -0
- package/src/models/interfaces/user.interface.ts +1 -0
- package/src/models/schemas/embedded/group-session.schema.ts +5 -7
- package/src/models/schemas/embedded/s3.schema.ts +133 -0
- package/src/models/schemas/embedded/time.schema.ts +18 -0
- package/src/services/sessions.service.ts +38 -1
- package/src/services/smtp.service.ts +71 -0
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -5,7 +5,16 @@ import { validationExceptionFactory } from './factories/exception.factory';
|
|
|
5
5
|
import { BaseExceptionsFilter } from './filters/base-exception.filter';
|
|
6
6
|
import { AccessTokenGuard } from './guards/access-token.guard';
|
|
7
7
|
import { AllowPermissions, PermissionGuard } from './guards/permission.guard';
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
APP__PORT,
|
|
10
|
+
APP__DEBUG,
|
|
11
|
+
APP__ACCESS_TOKEN,
|
|
12
|
+
MONGO__CS,
|
|
13
|
+
REDIS__CS,
|
|
14
|
+
KAFKA__BROKERS,
|
|
15
|
+
APP__MONGO__CS,
|
|
16
|
+
DL_SESSIONS__MONGO__CS,
|
|
17
|
+
} from './models/consts/env-vars.const';
|
|
9
18
|
import { I18nDTO } from './models/dtos/commons/i18n.dto';
|
|
10
19
|
import {
|
|
11
20
|
IMongoPage,
|
|
@@ -56,10 +65,42 @@ import { IStudentEmbedded } from './models/interfaces/student-embedded.interface
|
|
|
56
65
|
import { StudentEmbedded, StudentEmbeddedDocument, StudentEmbeddedSchema } from './models/schemas/embedded/student-embedded.schema';
|
|
57
66
|
import { ITeacher } from './models/interfaces/teacher.interface';
|
|
58
67
|
import { WeekDay } from './models/enums/week-day.enum';
|
|
59
|
-
import { IGroupSession } from './models/interfaces/group-session.interface';
|
|
68
|
+
import { IGroupSession, ITime } from './models/interfaces/group-session.interface';
|
|
60
69
|
import { GroupState } from './models/enums/group-state.enum';
|
|
61
70
|
import { GroupSessionSchema, GroupSessionDocument, GroupSession } from './models/schemas/embedded/group-session.schema';
|
|
62
71
|
import { TeacherSchema, TeacherDocument, Teacher } from './models/schemas/embedded/teacher.schema';
|
|
72
|
+
import { ISMTPAPIConfig } from './models/interfaces/smtp-api-config.interface';
|
|
73
|
+
import { SMTPService } from './services/smtp.service';
|
|
74
|
+
import { Time, TimeDocument, TimeSchema } from './models/schemas/embedded/time.schema';
|
|
75
|
+
import { FileLogInitType, S3FileState } from './models/enums/s3.enum';
|
|
76
|
+
import { IS3, ILogInitiator, IS3File, IFileState, IFileRecord, IFileMeta, IFileLog } from './models/interfaces/s3.interface';
|
|
77
|
+
import {
|
|
78
|
+
S3,
|
|
79
|
+
S3Schema,
|
|
80
|
+
S3Document,
|
|
81
|
+
LogInitiatorDocument,
|
|
82
|
+
LogInitiatorSchema,
|
|
83
|
+
LogInitiator,
|
|
84
|
+
FileLog,
|
|
85
|
+
FileLogSchema,
|
|
86
|
+
FileLogDocument,
|
|
87
|
+
FileMetaDocument,
|
|
88
|
+
FileMetaSchema,
|
|
89
|
+
FileMeta,
|
|
90
|
+
FileState,
|
|
91
|
+
FileStateSchema,
|
|
92
|
+
FileStateDocument,
|
|
93
|
+
FileRecord,
|
|
94
|
+
FileRecordSchema,
|
|
95
|
+
FileRecordDocument,
|
|
96
|
+
S3File,
|
|
97
|
+
S3FileSchema,
|
|
98
|
+
S3FileDocument,
|
|
99
|
+
FileEmbedded,
|
|
100
|
+
FileEmbeddedDocument,
|
|
101
|
+
FileEmbeddedSchema,
|
|
102
|
+
} from './models/schemas/embedded/s3.schema';
|
|
103
|
+
import { IUserMeta } from './models/interfaces/user-meta.interface';
|
|
63
104
|
|
|
64
105
|
export {
|
|
65
106
|
/**
|
|
@@ -67,6 +108,7 @@ export {
|
|
|
67
108
|
*/
|
|
68
109
|
SessionsService,
|
|
69
110
|
DictionariesService,
|
|
111
|
+
SMTPService,
|
|
70
112
|
|
|
71
113
|
/**
|
|
72
114
|
* Rest Wrapper
|
|
@@ -109,6 +151,8 @@ export {
|
|
|
109
151
|
UserVerificationLevel,
|
|
110
152
|
WeekDay,
|
|
111
153
|
GroupState,
|
|
154
|
+
S3FileState,
|
|
155
|
+
FileLogInitType,
|
|
112
156
|
|
|
113
157
|
/**
|
|
114
158
|
* DTOs
|
|
@@ -136,7 +180,17 @@ export {
|
|
|
136
180
|
IStudentEmbedded,
|
|
137
181
|
ITeacher,
|
|
138
182
|
IGroupSession,
|
|
139
|
-
|
|
183
|
+
ITime,
|
|
184
|
+
ISMTPAPIConfig,
|
|
185
|
+
IS3,
|
|
186
|
+
ILogInitiator,
|
|
187
|
+
IS3File,
|
|
188
|
+
IFileState,
|
|
189
|
+
IFileRecord,
|
|
190
|
+
IFileMeta,
|
|
191
|
+
IFileLog,
|
|
192
|
+
IUserMeta,
|
|
193
|
+
|
|
140
194
|
/**
|
|
141
195
|
* Schemas & Documents
|
|
142
196
|
*/
|
|
@@ -179,6 +233,34 @@ export {
|
|
|
179
233
|
StudentEmbeddedSchema,
|
|
180
234
|
StudentEmbeddedDocument,
|
|
181
235
|
StudentEmbedded,
|
|
236
|
+
TimeSchema,
|
|
237
|
+
TimeDocument,
|
|
238
|
+
Time,
|
|
239
|
+
S3,
|
|
240
|
+
S3Schema,
|
|
241
|
+
S3Document,
|
|
242
|
+
LogInitiator,
|
|
243
|
+
LogInitiatorSchema,
|
|
244
|
+
LogInitiatorDocument,
|
|
245
|
+
FileLog,
|
|
246
|
+
FileLogSchema,
|
|
247
|
+
FileLogDocument,
|
|
248
|
+
FileMeta,
|
|
249
|
+
FileMetaSchema,
|
|
250
|
+
FileMetaDocument,
|
|
251
|
+
FileState,
|
|
252
|
+
FileStateSchema,
|
|
253
|
+
FileStateDocument,
|
|
254
|
+
FileRecord,
|
|
255
|
+
FileRecordSchema,
|
|
256
|
+
FileRecordDocument,
|
|
257
|
+
S3File,
|
|
258
|
+
S3FileSchema,
|
|
259
|
+
S3FileDocument,
|
|
260
|
+
FileEmbedded,
|
|
261
|
+
FileEmbeddedSchema,
|
|
262
|
+
FileEmbeddedDocument,
|
|
263
|
+
|
|
182
264
|
|
|
183
265
|
/**
|
|
184
266
|
* Filters
|
|
@@ -2,9 +2,14 @@ import { WeekDay } from '../enums/week-day.enum';
|
|
|
2
2
|
import { II18n } from './i18n.interface';
|
|
3
3
|
import { IIdentifable } from './identifable.interface';
|
|
4
4
|
|
|
5
|
+
export interface ITime {
|
|
6
|
+
inString: string;
|
|
7
|
+
inNumber: number;
|
|
8
|
+
zone: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
5
11
|
export interface IGroupSession extends IIdentifable {
|
|
6
12
|
description: II18n;
|
|
7
13
|
day: WeekDay;
|
|
8
|
-
time:
|
|
9
|
-
timeZone: string;
|
|
14
|
+
time: ITime;
|
|
10
15
|
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { mongo } from 'mongoose';
|
|
2
|
+
import { FileLogInitType, S3FileState } from '../enums/s3.enum';
|
|
3
|
+
|
|
4
|
+
export interface IS3 {
|
|
5
|
+
key: string;
|
|
6
|
+
bucket: string;
|
|
7
|
+
etag: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface ILogInitiator {
|
|
11
|
+
type: FileLogInitType;
|
|
12
|
+
name: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface IS3File {
|
|
16
|
+
id: mongo.ObjectId;
|
|
17
|
+
fileMeta: IFileMeta;
|
|
18
|
+
state: IFileState;
|
|
19
|
+
s3: IS3;
|
|
20
|
+
record: IFileRecord;
|
|
21
|
+
owner: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface IFileState {
|
|
25
|
+
value: S3FileState;
|
|
26
|
+
log: IFileLog[];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface IFileRecord {
|
|
30
|
+
createdAt: Date;
|
|
31
|
+
updatedAt: Date;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface IFileMeta {
|
|
35
|
+
name: string;
|
|
36
|
+
size: number;
|
|
37
|
+
mimeType: string;
|
|
38
|
+
extension: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface IFileLog {
|
|
42
|
+
createdAt: Date;
|
|
43
|
+
value: S3FileState;
|
|
44
|
+
initiator: ILogInitiator;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface IFileEmbedded {
|
|
48
|
+
id: string;
|
|
49
|
+
name: string;
|
|
50
|
+
size: number;
|
|
51
|
+
mimeType: string;
|
|
52
|
+
s3: IS3;
|
|
53
|
+
state: S3FileState;
|
|
54
|
+
createdAt: Date;
|
|
55
|
+
}
|
|
@@ -1,24 +1,22 @@
|
|
|
1
1
|
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
|
|
2
2
|
import { HydratedDocument } from 'mongoose';
|
|
3
3
|
import { Identifable } from '../identifable.schema';
|
|
4
|
-
import { IGroupSession } from '../../interfaces/group-session.interface';
|
|
4
|
+
import { IGroupSession, ITime } from '../../interfaces/group-session.interface';
|
|
5
5
|
import { WeekDay } from '../../enums/week-day.enum';
|
|
6
6
|
import { I18nSchema } from './i18n.embedded';
|
|
7
7
|
import { II18n } from '../../interfaces/i18n.interface';
|
|
8
|
+
import { Time } from './time.schema';
|
|
8
9
|
|
|
9
10
|
@Schema()
|
|
10
11
|
export class GroupSession extends Identifable implements IGroupSession {
|
|
11
12
|
@Prop({ type: I18nSchema, required: false })
|
|
12
13
|
description: II18n;
|
|
13
14
|
|
|
14
|
-
@Prop({ type:
|
|
15
|
+
@Prop({ type: Number, enum: WeekDay, required: true })
|
|
15
16
|
day: WeekDay;
|
|
16
17
|
|
|
17
|
-
@Prop({ type:
|
|
18
|
-
time:
|
|
19
|
-
|
|
20
|
-
@Prop({ type: String, required: true })
|
|
21
|
-
timeZone: string;
|
|
18
|
+
@Prop({ type: Time, required: true })
|
|
19
|
+
time: ITime;
|
|
22
20
|
}
|
|
23
21
|
|
|
24
22
|
export const GroupSessionSchema = SchemaFactory.createForClass(GroupSession);
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
|
|
2
|
+
import { HydratedDocument, mongo, SchemaTypes } from 'mongoose';
|
|
3
|
+
import { IFileEmbedded, IFileLog, IFileMeta, IFileRecord, IFileState, ILogInitiator, IS3, IS3File } from '../../interfaces/s3.interface';
|
|
4
|
+
import { FileLogInitType, S3FileState } from '../../enums/s3.enum';
|
|
5
|
+
|
|
6
|
+
@Schema({ _id: false })
|
|
7
|
+
export class S3 implements IS3 {
|
|
8
|
+
@Prop({ type: String, required: true })
|
|
9
|
+
key: string;
|
|
10
|
+
|
|
11
|
+
@Prop({ type: String, required: true })
|
|
12
|
+
bucket: string;
|
|
13
|
+
|
|
14
|
+
@Prop({ type: String, required: false })
|
|
15
|
+
etag: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@Schema({ _id: false })
|
|
19
|
+
export class LogInitiator implements ILogInitiator {
|
|
20
|
+
@Prop({ type: String, enum: FileLogInitType, required: false })
|
|
21
|
+
type: FileLogInitType;
|
|
22
|
+
|
|
23
|
+
@Prop({ type: String, required: false })
|
|
24
|
+
name: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@Schema()
|
|
28
|
+
export class FileLog implements IFileLog {
|
|
29
|
+
@Prop({ type: Date, required: true })
|
|
30
|
+
createdAt: Date;
|
|
31
|
+
|
|
32
|
+
@Prop({ type: String, enum: S3FileState, required: true })
|
|
33
|
+
value: S3FileState;
|
|
34
|
+
|
|
35
|
+
@Prop({ type: LogInitiator, required: false })
|
|
36
|
+
initiator: LogInitiator;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@Schema({ _id: false })
|
|
40
|
+
export class FileMeta implements IFileMeta {
|
|
41
|
+
@Prop({ type: String, required: false })
|
|
42
|
+
name: string;
|
|
43
|
+
|
|
44
|
+
@Prop({ type: Number, required: true })
|
|
45
|
+
size: number;
|
|
46
|
+
|
|
47
|
+
@Prop({ type: String, required: true })
|
|
48
|
+
mimeType: string;
|
|
49
|
+
|
|
50
|
+
@Prop({ type: String, required: true })
|
|
51
|
+
extension: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
@Schema({ _id: false })
|
|
55
|
+
export class FileState implements IFileState {
|
|
56
|
+
@Prop({ type: String, enum: S3FileState, required: true })
|
|
57
|
+
value: S3FileState;
|
|
58
|
+
|
|
59
|
+
@Prop({ type: [FileLog], required: true, default: [] })
|
|
60
|
+
log: FileLog[];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
@Schema({ _id: false })
|
|
64
|
+
export class FileRecord implements IFileRecord {
|
|
65
|
+
@Prop({ type: Date, required: true })
|
|
66
|
+
createdAt: Date;
|
|
67
|
+
|
|
68
|
+
@Prop({ type: Date, required: false })
|
|
69
|
+
updatedAt: Date;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
@Schema({ _id: false })
|
|
73
|
+
export class S3File implements IS3File {
|
|
74
|
+
@Prop({ type: SchemaTypes.ObjectId, required: true })
|
|
75
|
+
id: mongo.ObjectId;
|
|
76
|
+
|
|
77
|
+
@Prop({ type: FileMeta, required: true, default: null })
|
|
78
|
+
fileMeta: FileMeta;
|
|
79
|
+
|
|
80
|
+
@Prop({ type: FileState, required: true, default: null })
|
|
81
|
+
state: FileState;
|
|
82
|
+
|
|
83
|
+
@Prop({ type: S3, required: true, default: null })
|
|
84
|
+
s3: S3;
|
|
85
|
+
|
|
86
|
+
@Prop({ type: FileRecord, required: true })
|
|
87
|
+
record: FileRecord;
|
|
88
|
+
|
|
89
|
+
@Prop({ type: String, required: true })
|
|
90
|
+
owner: string;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
@Schema({ _id: false })
|
|
94
|
+
export class FileEmbedded implements IFileEmbedded {
|
|
95
|
+
@Prop({ type: String, required: true })
|
|
96
|
+
id: string;
|
|
97
|
+
|
|
98
|
+
@Prop({ type: String, required: false })
|
|
99
|
+
name: string;
|
|
100
|
+
|
|
101
|
+
@Prop({ type: Number, required: true })
|
|
102
|
+
size: number;
|
|
103
|
+
|
|
104
|
+
@Prop({ type: String, required: true })
|
|
105
|
+
mimeType: string;
|
|
106
|
+
|
|
107
|
+
@Prop({ type: S3, required: true, default: null })
|
|
108
|
+
s3: S3;
|
|
109
|
+
|
|
110
|
+
@Prop({ type: String, enum: S3FileState, required: true })
|
|
111
|
+
state: S3FileState;
|
|
112
|
+
|
|
113
|
+
@Prop({ type: Date, required: true })
|
|
114
|
+
createdAt: Date;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export const S3Schema = SchemaFactory.createForClass(S3);
|
|
118
|
+
export const LogInitiatorSchema = SchemaFactory.createForClass(LogInitiator);
|
|
119
|
+
export const FileLogSchema = SchemaFactory.createForClass(FileLog);
|
|
120
|
+
export const FileMetaSchema = SchemaFactory.createForClass(FileMeta);
|
|
121
|
+
export const FileStateSchema = SchemaFactory.createForClass(FileState);
|
|
122
|
+
export const FileRecordSchema = SchemaFactory.createForClass(FileRecord);
|
|
123
|
+
export const S3FileSchema = SchemaFactory.createForClass(S3File);
|
|
124
|
+
export const FileEmbeddedSchema = SchemaFactory.createForClass(FileEmbedded);
|
|
125
|
+
|
|
126
|
+
export type S3Document = HydratedDocument<S3>;
|
|
127
|
+
export type LogInitiatorDocument = HydratedDocument<LogInitiator>;
|
|
128
|
+
export type FileLogDocument = HydratedDocument<FileLog>;
|
|
129
|
+
export type FileMetaDocument = HydratedDocument<FileMeta>;
|
|
130
|
+
export type FileStateDocument = HydratedDocument<FileState>;
|
|
131
|
+
export type FileRecordDocument = HydratedDocument<FileRecord>;
|
|
132
|
+
export type S3FileDocument = HydratedDocument<S3File>;
|
|
133
|
+
export type FileEmbeddedDocument = HydratedDocument<FileEmbedded>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
|
|
2
|
+
import { HydratedDocument } from 'mongoose';
|
|
3
|
+
import { ITime } from '../../interfaces/group-session.interface';
|
|
4
|
+
|
|
5
|
+
@Schema({ _id: false })
|
|
6
|
+
export class Time implements ITime {
|
|
7
|
+
@Prop({ type: String, required: true })
|
|
8
|
+
inString: string;
|
|
9
|
+
|
|
10
|
+
@Prop({ type: Number, required: true })
|
|
11
|
+
inNumber: number;
|
|
12
|
+
|
|
13
|
+
@Prop({ type: String, required: true })
|
|
14
|
+
zone: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const TimeSchema = SchemaFactory.createForClass(Time);
|
|
18
|
+
export type TimeDocument = HydratedDocument<Time>;
|
|
@@ -7,6 +7,7 @@ import { firstValueFrom } from 'rxjs';
|
|
|
7
7
|
import { Model } from 'mongoose';
|
|
8
8
|
import { Session, SessionDocument } from '../models/schemas/session.schema';
|
|
9
9
|
import { InjectModel } from '@nestjs/mongoose';
|
|
10
|
+
import { Types } from 'mongoose';
|
|
10
11
|
|
|
11
12
|
@Injectable()
|
|
12
13
|
export class SessionsService {
|
|
@@ -26,7 +27,7 @@ export class SessionsService {
|
|
|
26
27
|
//#endregion
|
|
27
28
|
|
|
28
29
|
//#region Public API
|
|
29
|
-
public async create(userId: string, userAgent: string, ip: string) {
|
|
30
|
+
public async create(userId: string | Types.ObjectId, userAgent: string, ip: string) {
|
|
30
31
|
try {
|
|
31
32
|
const endpoint = `${this._baseUrl}/v1/sessions/${userId}`;
|
|
32
33
|
const headers = { 'user-agent': userAgent, 'x-ip': ip };
|
|
@@ -57,5 +58,41 @@ export class SessionsService {
|
|
|
57
58
|
|
|
58
59
|
return session;
|
|
59
60
|
}
|
|
61
|
+
|
|
62
|
+
public async fetchAllById(id: string): Promise<ISession[]> {
|
|
63
|
+
try {
|
|
64
|
+
const endpoint = `${this._baseUrl}/v1/sessions/${id}/all`;
|
|
65
|
+
const response$ = this._httpService.get<RESTResponseBody<ISession[]>>(endpoint);
|
|
66
|
+
const response = await firstValueFrom(response$);
|
|
67
|
+
|
|
68
|
+
if (response.data.errors) {
|
|
69
|
+
throw new RESTError('sessions_api_error', response.data.errors);
|
|
70
|
+
}
|
|
71
|
+
if (!response.data || !response.data.result) {
|
|
72
|
+
throw new RESTError('sessions_api_error', 'empty response');
|
|
73
|
+
}
|
|
74
|
+
return response.data.result.data;
|
|
75
|
+
} catch (e) {
|
|
76
|
+
throw RESTError.createFromCatch(e, { keyword: 'unknown', debug: e });
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public async fetchAllByUserId(id: string): Promise<ISession[]> {
|
|
81
|
+
try {
|
|
82
|
+
const endpoint = `${this._baseUrl}/v1/sessions/users/${id}/all`;
|
|
83
|
+
const response$ = this._httpService.get<RESTResponseBody<ISession[]>>(endpoint);
|
|
84
|
+
const response = await firstValueFrom(response$);
|
|
85
|
+
|
|
86
|
+
if (response.data.errors) {
|
|
87
|
+
throw new RESTError('sessions_api_error', response.data.errors);
|
|
88
|
+
}
|
|
89
|
+
if (!response.data || !response.data.result) {
|
|
90
|
+
throw new RESTError('sessions_api_error', 'empty response');
|
|
91
|
+
}
|
|
92
|
+
return response.data.result.data;
|
|
93
|
+
} catch (e) {
|
|
94
|
+
throw RESTError.createFromCatch(e, { keyword: 'unknown', debug: e });
|
|
95
|
+
}
|
|
96
|
+
}
|
|
60
97
|
//#endregion
|
|
61
98
|
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { HttpService } from '@nestjs/axios';
|
|
2
|
+
import { ConfigService } from '@nestjs/config';
|
|
3
|
+
import { catchError, firstValueFrom, map } from 'rxjs';
|
|
4
|
+
import { Injectable } from '@nestjs/common';
|
|
5
|
+
import { RESTResponseBody, RESTError } from '../models/dtos/wrappers/rest-wrapper.class';
|
|
6
|
+
import { ISMTP } from '../models/interfaces/smtp.interface';
|
|
7
|
+
|
|
8
|
+
@Injectable()
|
|
9
|
+
export class SMTPService {
|
|
10
|
+
//#region Private Members
|
|
11
|
+
private _baseUrl: string;
|
|
12
|
+
//#endregion
|
|
13
|
+
|
|
14
|
+
//#region Constructor
|
|
15
|
+
constructor(private readonly _httpService: HttpService, private readonly _configService: ConfigService) {
|
|
16
|
+
this._baseUrl = this._configService.getOrThrow('DL_SMTP__REST__BASE_URL');
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
|
|
20
|
+
//#region Public API
|
|
21
|
+
public async send(subject: string, from: string, to: string, html: string, profileId: string) {
|
|
22
|
+
const requestBody = {
|
|
23
|
+
data: {
|
|
24
|
+
from,
|
|
25
|
+
to: [to],
|
|
26
|
+
subject,
|
|
27
|
+
html,
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const response$ = this._httpService.post<RESTResponseBody<ISMTP>>(`${this._baseUrl}/v1/emails/send`, requestBody, { params: { profileId } });
|
|
32
|
+
const response = await firstValueFrom(response$);
|
|
33
|
+
|
|
34
|
+
if (response.data.errors) {
|
|
35
|
+
throw new RESTError('smtp_api_error', response.data.errors);
|
|
36
|
+
}
|
|
37
|
+
if (!response.data || !response.data.result) {
|
|
38
|
+
throw new RESTError('smtp_api_error', 'empty response');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return response.data.result.data;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public send$(subject: string, from: string, to: string, html: string, profileId: string) {
|
|
45
|
+
const requestBody = {
|
|
46
|
+
data: {
|
|
47
|
+
from,
|
|
48
|
+
to: [to],
|
|
49
|
+
subject,
|
|
50
|
+
html,
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const response$ = this._httpService.post<RESTResponseBody<ISMTP>>(`${this._baseUrl}/v1/emails/send`, requestBody, { params: { profileId } });
|
|
55
|
+
return response$.pipe(
|
|
56
|
+
map((response) => {
|
|
57
|
+
if (response.data.errors) {
|
|
58
|
+
throw new RESTError('smtp_api_error', response.data.errors);
|
|
59
|
+
}
|
|
60
|
+
if (!response.data || !response.data.result) {
|
|
61
|
+
throw new RESTError('smtp_api_error', 'empty response');
|
|
62
|
+
}
|
|
63
|
+
return response.data.result.data;
|
|
64
|
+
}),
|
|
65
|
+
catchError((e) => {
|
|
66
|
+
throw new RESTError('smtp_api_error', e);
|
|
67
|
+
}),
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
}
|