-
Notifications
You must be signed in to change notification settings - Fork 1
/
EvaluationUpdateRequestDto.ts
106 lines (87 loc) · 3.14 KB
/
EvaluationUpdateRequestDto.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
import { IsDate, IsNumber, IsOptional, IsString, validateSync, ValidationError } from 'class-validator';
export interface EvaluationUpdateRequestFields {
ErtekelesDatum: Date;
ErtekelesOsztalyzatId?: number;
ErtekelesSzazalek?: number;
ErtekelesSzoveg?: string;
ErtekelesModId: number;
ErtekelesTema: string;
}
export default class EvaluationUpdateRequestDto implements Partial<EvaluationUpdateRequestFields> {
@IsDate()
private readonly date?: Date;
@IsOptional()
@IsNumber()
private readonly evaluationGradeTypeId?: number;
@IsOptional()
@IsNumber()
private readonly evaluationPercent?: number;
@IsOptional()
@IsString()
private readonly evaluationText?: string;
@IsNumber()
private readonly modeId?: number;
@IsString()
private readonly topic?: string;
constructor(input: any) {
if (typeof input === 'object' && input !== null) {
this.date = typeof input['ErtekelesDatum'] === 'string' ? new Date(input['ErtekelesDatum']) : input['ErtekelesDatum'];
this.evaluationGradeTypeId = typeof input['ErtekelesOsztalyzatId'] === 'number' ? input['ErtekelesOsztalyzatId'] : undefined;
this.evaluationPercent = typeof input['ErtekelesSzazalek'] === 'number' ? input['ErtekelesSzazalek'] : undefined;
this.evaluationText = typeof input['ErtekelesSzoveg'] === 'string' ? input['ErtekelesSzoveg'] : undefined;
this.modeId = typeof input['ErtekelesModId'] === 'number' ? input['ErtekelesModId'] : undefined;
this.topic = typeof input['ErtekelesTema'] === 'string' ? input['ErtekelesTema'] : undefined;
}
const errors = validateSync(this, { skipMissingProperties: true });
if (errors.length > 0) {
throw this.validationErrorResponse(errors);
}
}
public get ErtekelesDatum(): Date | undefined {
return this.date;
}
public get ErtekelesOsztalyzatId(): number | undefined {
return this.evaluationGradeTypeId;
}
public get ErtekelesSzazalek(): number | undefined {
return this.evaluationPercent;
}
public get ErtekelesSzoveg(): string | undefined {
return this.evaluationText;
}
public get ErtekelesModId(): number | undefined {
return this.modeId;
}
public get ErtekelesTema(): string | undefined {
return this.topic;
}
public get json(): EvaluationUpdateRequestFields {
return {
ErtekelesDatum: this.date,
ErtekelesModId: this.modeId,
ErtekelesOsztalyzatId: this.evaluationGradeTypeId,
ErtekelesSzazalek: this.evaluationPercent,
ErtekelesSzoveg: this.evaluationText,
ErtekelesTema: this.topic,
} as EvaluationUpdateRequestFields;
}
private validationErrorResponse(errors: Array<ValidationError>): object {
const validFields: Partial<EvaluationUpdateRequestFields> = {
ErtekelesDatum: this.date,
ErtekelesOsztalyzatId: this.evaluationGradeTypeId,
ErtekelesSzazalek: this.evaluationPercent,
ErtekelesSzoveg: this.evaluationText,
ErtekelesModId: this.modeId,
ErtekelesTema: this.topic,
};
const errorMessages: Array<string> = [];
for (const error of errors) {
validFields[error.property as keyof EvaluationUpdateRequestFields] = undefined;
errorMessages.push(...Object.values(error.constraints || {}));
}
return {
valid: validFields,
errors: errorMessages,
};
}
}