-
Notifications
You must be signed in to change notification settings - Fork 1
/
AnnouncedTestRequestDto.ts
81 lines (66 loc) · 2.26 KB
/
AnnouncedTestRequestDto.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
import { IsBoolean, IsNumber, IsString, validateSync, ValidationError } from 'class-validator';
export interface AnnouncedTestRequestFields {
ErtekelesMod: number;
ForceSave: boolean;
OrarendElemUid: string;
Tema: string;
}
export default class AnnouncedTestRequestDto implements Partial<AnnouncedTestRequestFields> {
@IsNumber()
private readonly evaluationModeId?: number;
@IsBoolean()
private readonly forceSave?: boolean;
@IsString()
private readonly timetableElementId?: string;
@IsString()
private readonly topic?: string;
constructor(input: any) {
if (typeof input === 'object' && input !== null) {
this.evaluationModeId = typeof input['ErtekelesMod'] === 'number' ? input['ErtekelesMod'] : undefined;
this.forceSave = typeof input['ForceSave'] === 'boolean' ? input['ForceSave'] : undefined;
this.timetableElementId = typeof input['OrarendElemUid'] === 'string' ? input['OrarendElemUid'].trim() : undefined;
this.topic = typeof input['Tema'] === 'string' ? input['Tema'].trim() : undefined;
}
const errors = validateSync(this, { skipMissingProperties: true });
if (errors.length > 0) {
throw this.validationErrorResponse(errors);
}
}
public get ErtekelesMod(): number | undefined {
return this.evaluationModeId;
}
public get ForceSave(): boolean | undefined {
return this.forceSave;
}
public get OrarendElemUid(): string | undefined {
return this.timetableElementId;
}
public get Tema(): string | undefined {
return this.topic;
}
public get json(): AnnouncedTestRequestFields {
return {
ErtekelesMod: this.evaluationModeId,
ForceSave: this.forceSave,
OrarendElemUid: this.timetableElementId,
Tema: this.topic,
} as AnnouncedTestRequestFields;
}
private validationErrorResponse(errors: Array<ValidationError>): object {
const validFields: Partial<AnnouncedTestRequestFields> = {
ErtekelesMod: this.evaluationModeId,
ForceSave: this.forceSave,
OrarendElemUid: this.timetableElementId,
Tema: this.topic,
};
const errorMessages: Array<string> = [];
for (const error of errors) {
validFields[error.property as keyof AnnouncedTestRequestFields] = undefined;
errorMessages.push(...Object.values(error.constraints || {}));
}
return {
valid: validFields,
errors: errorMessages,
};
}
}