-
Notifications
You must be signed in to change notification settings - Fork 1
/
LessonDto.ts
370 lines (307 loc) · 11.4 KB
/
LessonDto.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
import AttachmentDto from './Lesson/AttachmentDto';
import UidNameStructure from './UidNameStructure';
import ValueDescriptor from './ValueDescriptor';
import SubjectDescriptor from './SubjectDescriptor';
import { IsArray, IsBoolean, IsDate, IsInstance, IsNumber, IsOptional, IsString, validateSync, ValidationError } from 'class-validator';
export interface LessonFields {
BejelentettSzamonkeresUid?: string;
Csatolmanyok?: Array<AttachmentDto>;
OsztalyCsoport: UidNameStructure;
Oraszam?: number;
TeremNeve?: string;
FeladatGroupUid?: string;
DigitalisEszkozTipus?: string;
DigitalisPlatformTipus?: string;
VegIdopont: Date;
HaziFeladatUid?: string;
IsTanuloHaziFeladatEnabled: boolean;
IsDigitalisOra: boolean;
NyelviFeladatGroupUid?: string;
OraEvesSorszama?: number;
Nev?: string;
TanuloJelenlet?: ValueDescriptor;
KezdetIdopont: Date;
Allapot: ValueDescriptor;
Tantargy: SubjectDescriptor;
HelyettesTanarNeve?: string;
DigitalisTamogatoEszkozTipusList?: string[];
TanarNeve?: string;
Tema?: string;
Tipus: ValueDescriptor;
Uid: string;
Datum: Date;
Letrehozas: Date;
UtolsoModositas: Date;
}
export default class LessonDto implements Partial<LessonFields> {
@IsOptional()
@IsString()
private readonly announcedTestUid?: string;
@IsOptional()
@IsArray()
@IsInstance(AttachmentDto, { each: true })
private readonly attachments?: Array<AttachmentDto>;
@IsInstance(UidNameStructure)
private readonly classGroup?: UidNameStructure;
@IsOptional()
@IsNumber()
private readonly classScheduleNumber?: number;
@IsOptional()
@IsString()
private readonly classroom?: string;
@IsOptional()
@IsString()
private readonly classworkGroupId?: string;
@IsOptional()
@IsString()
private readonly digitalInstrumentType?: string;
@IsOptional()
@IsString()
private readonly digitalPlatformType?: string;
@IsDate()
private readonly endTimeAsString?: Date;
@IsOptional()
@IsString()
private readonly homeWorkUid?: string;
@IsBoolean()
private readonly homeworkEditedByStudentEnabled?: boolean;
@IsBoolean()
private readonly isDigitalLesson?: boolean;
@IsOptional()
@IsString()
private readonly languageTaskGroupId?: string;
@IsOptional()
@IsNumber()
private readonly lessonNumber?: number;
@IsOptional()
@IsString()
private readonly name?: string;
@IsOptional()
@IsInstance(ValueDescriptor)
private readonly presence?: ValueDescriptor;
@IsDate()
private readonly startTimeAsString?: Date;
@IsInstance(ValueDescriptor)
private readonly state?: ValueDescriptor;
@IsInstance(SubjectDescriptor)
private readonly subject?: SubjectDescriptor;
@IsOptional()
@IsString()
private readonly supplyTeacher?: string;
@IsOptional()
@IsArray()
@IsString({ each: true })
private readonly supportedDigitalInstrumentTypes?: string[];
@IsOptional()
@IsString()
private readonly teacher?: string;
@IsOptional()
@IsString()
private readonly topic?: string;
@IsInstance(ValueDescriptor)
private readonly type?: ValueDescriptor;
@IsString()
private readonly uid?: string;
@IsDate()
private readonly date?: Date;
@IsDate()
private readonly creation?: Date;
@IsDate()
private readonly lastModification?: Date;
constructor(input: any) {
if (typeof input === 'object' && input !== null) {
this.announcedTestUid = typeof input['BejelentettSzamonkeresUid'] === 'string' ? input['BejelentettSzamonkeresUid'].trim() : undefined;
this.attachments = typeof input['Csatolmanyok'] === 'object' ? input['Csatolmanyok'].map((e: any) => new AttachmentDto(e)) :
undefined;
this.classGroup = typeof input['OsztalyCsoport'] === 'object' ? new UidNameStructure(input['OsztalyCsoport']) : undefined;
this.classScheduleNumber = typeof input['Oraszam'] === 'number' ? input['Oraszam'] : undefined;
this.classroom = typeof input['TeremNeve'] === 'string' ? input['TeremNeve'].trim() : undefined;
this.classworkGroupId = typeof input['FeladatGroupUid'] === 'string' ? input['FeladatGroupUid'].trim() : undefined;
this.digitalInstrumentType = typeof input['DigitalisEszkozTipus'] === 'string' ? input['DigitalisEszkozTipus'].trim() : undefined;
this.digitalPlatformType = typeof input['DigitalisPlatformTipus'] === 'string' ? input['DigitalisPlatformTipus'].trim() : undefined;
this.endTimeAsString = typeof input['VegIdopont'] === 'string' ? new Date(input['VegIdopont']) : undefined;
this.homeWorkUid = typeof input['HaziFeladatUid'] === 'string' ? input['HaziFeladatUid'].trim() : undefined;
this.homeworkEditedByStudentEnabled = typeof input['IsTanuloHaziFeladatEnabled'] === 'boolean' ? input['IsTanuloHaziFeladatEnabled'] :
undefined;
this.isDigitalLesson = typeof input['IsDigitalisOra'] === 'boolean' ? input['IsDigitalisOra'] : undefined;
this.languageTaskGroupId = typeof input['NyelviFeladatGroupUid'] === 'string' ? input['NyelviFeladatGroupUid'] : undefined;
this.lessonNumber = typeof input['OraEvesSorszama'] === 'number' ? input['OraEvesSorszama'] : undefined;
this.name = typeof input['Nev'] === 'string' ? input['Nev'] : undefined;
this.presence = typeof input['TanuloJelenlet'] === 'object' ? new ValueDescriptor(input['TanuloJelenlet']) : undefined;
this.startTimeAsString = typeof input['KezdetIdopont'] === 'string' ? new Date(input['KezdetIdopont']) : undefined;
this.state = typeof input['Allapot'] === 'object' ? new ValueDescriptor(input['Allapot']) : undefined;
this.subject = typeof input['Tantargy'] === 'object' ? new SubjectDescriptor(input['Tantargy']) : undefined;
this.supplyTeacher = typeof input['HelyettesTanarNeve'] === 'string' ? input['HelyettesTanarNeve'] : undefined;
this.supportedDigitalInstrumentTypes = Array.isArray(input['DigitalisTamogatoEszkozTipusList']) ?
input['DigitalisTamogatoEszkozTipusList'].map((item: any) => item) : undefined;
this.teacher = typeof input['TanarNeve'] === 'string' ? input['TanarNeve'] : undefined;
this.topic = typeof input['Tema'] === 'string' ? input['Tema'] : undefined;
this.type = typeof input['Tipus'] === 'object' ? new ValueDescriptor(input['Tipus']) : undefined;
this.uid = typeof input['Uid'] === 'string' ? input['Uid'] : undefined;
this.date = typeof input['Datum'] === 'string' ? new Date(input['Datum']) : undefined;
this.creation = typeof input['Letrehozas'] === 'string' ? new Date(input['Letrehozas']) : undefined;
this.lastModification = typeof input['UtolsoModositas'] === 'string' ? new Date(input['UtolsoModositas']) : undefined;
}
const errors = validateSync(this, { skipMissingProperties: true });
if (errors.length > 0) {
throw this.validationErrorResponse(errors);
}
}
public get BejelentettSzamonkeresUid(): string | undefined {
return this.announcedTestUid;
}
public get Csatolmanyok(): Array<AttachmentDto> | undefined {
return this.attachments;
}
public get OsztalyCsoport(): UidNameStructure | undefined {
return this.classGroup;
}
public get Oraszam(): number | undefined {
return this.classScheduleNumber;
}
public get TeremNeve(): string | undefined {
return this.classroom;
}
public get FeladatGroupUid(): string | undefined {
return this.classworkGroupId;
}
public get DigitalisEszkozTipus(): string | undefined {
return this.digitalInstrumentType;
}
public get DigitalisPlatformTipus(): string | undefined {
return this.digitalPlatformType;
}
public get VegIdopont(): Date | undefined {
return this.endTimeAsString;
}
public get HaziFeladatUid(): string | undefined {
return this.homeWorkUid;
}
public get IsTanuloHaziFeladatEnabled(): boolean | undefined {
return this.homeworkEditedByStudentEnabled;
}
public get IsDigitalisOra(): boolean | undefined {
return this.isDigitalLesson;
}
public get NyelviFeladatGroupUid(): string | undefined {
return this.languageTaskGroupId;
}
public get OraEvesSorszama(): number | undefined {
return this.lessonNumber;
}
public get Nev(): string | undefined {
return this.name;
}
public get TanuloJelenlet(): ValueDescriptor | undefined {
return this.presence;
}
public get KezdetIdopont(): Date | undefined {
return this.startTimeAsString;
}
public get Allapot(): ValueDescriptor | undefined {
return this.state;
}
public get Tantargy(): SubjectDescriptor | undefined {
return this.subject;
}
public get HelyettesTanarNeve(): string | undefined {
return this.supplyTeacher;
}
public get DigitalisTamogatoEszkozTipusList(): Array<string> | undefined {
return this.supportedDigitalInstrumentTypes;
}
public get TanarNeve(): string | undefined {
return this.teacher;
}
public get Tema(): string | undefined {
return this.topic;
}
public get Tipus(): ValueDescriptor | undefined {
return this.type;
}
public get Uid(): string | undefined {
return this.uid;
}
public get Datum(): Date | undefined {
return this.date;
}
public get Letrehozas(): Date | undefined {
return this.creation;
}
public get UtolsoModositas(): Date | undefined {
return this.lastModification;
}
public get json(): LessonFields {
return {
Allapot: this.state?.json,
BejelentettSzamonkeresUid: this.announcedTestUid,
Csatolmanyok: this.attachments,
Datum: this.date,
DigitalisEszkozTipus: this.digitalInstrumentType,
DigitalisPlatformTipus: this.digitalPlatformType,
DigitalisTamogatoEszkozTipusList: this.supportedDigitalInstrumentTypes,
FeladatGroupUid: this.classworkGroupId,
HaziFeladatUid: this.homeWorkUid,
HelyettesTanarNeve: this.supplyTeacher,
IsDigitalisOra: this.isDigitalLesson,
IsTanuloHaziFeladatEnabled: this.homeworkEditedByStudentEnabled,
KezdetIdopont: this.startTimeAsString,
Letrehozas: this.creation,
Nev: this.name,
NyelviFeladatGroupUid: this.languageTaskGroupId,
OraEvesSorszama: this.lessonNumber,
Oraszam: this.classScheduleNumber,
OsztalyCsoport: this.classGroup?.json,
TanarNeve: this.teacher,
Tantargy: this.subject?.json,
TanuloJelenlet: this.presence?.json,
Tema: this.topic,
TeremNeve: this.classroom,
Tipus: this.type?.json,
Uid: this.uid,
UtolsoModositas: this.lastModification,
VegIdopont: this.endTimeAsString,
} as LessonFields;
}
private validationErrorResponse(errors: Array<ValidationError>): object {
const validFields: Partial<LessonFields> = {
BejelentettSzamonkeresUid: this.announcedTestUid,
Csatolmanyok: this.attachments,
OsztalyCsoport: this.classGroup,
Oraszam: this.classScheduleNumber,
TeremNeve: this.classroom,
FeladatGroupUid: this.classworkGroupId,
DigitalisEszkozTipus: this.digitalInstrumentType,
DigitalisPlatformTipus: this.digitalPlatformType,
VegIdopont: this.endTimeAsString,
HaziFeladatUid: this.homeWorkUid,
IsTanuloHaziFeladatEnabled: this.homeworkEditedByStudentEnabled,
IsDigitalisOra: this.isDigitalLesson,
NyelviFeladatGroupUid: this.languageTaskGroupId,
OraEvesSorszama: this.lessonNumber,
Nev: this.name,
TanuloJelenlet: this.presence,
KezdetIdopont: this.startTimeAsString,
Allapot: this.state,
Tantargy: this.subject,
HelyettesTanarNeve: this.supplyTeacher,
DigitalisTamogatoEszkozTipusList: this.supportedDigitalInstrumentTypes,
TanarNeve: this.teacher,
Tema: this.topic,
Tipus: this.type,
Uid: this.uid,
Datum: this.date,
Letrehozas: this.creation,
UtolsoModositas: this.lastModification,
};
const errorMessages: Array<string> = [];
for (const error of errors) {
validFields[error.property as keyof LessonFields] = undefined;
errorMessages.push(...Object.values(error.constraints || {}));
}
return {
valid: validFields,
errors: errorMessages,
};
}
}