-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTimetableWeekDto.ts
92 lines (75 loc) · 2.45 KB
/
TimetableWeekDto.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
import { IsDate, IsNumber, IsString, validateSync, ValidationError } from 'class-validator';
export interface TimetableWeekFields {
VegNapDatuma: Date;
Id: string;
HetSorszama: number;
KezdoNapDatuma: Date;
Hetirend?: string;
}
export default class TimetableWeekDto implements Partial<TimetableWeekFields> {
@IsDate()
private readonly endDate?: Date;
@IsString()
private readonly id?: string;
@IsNumber()
private readonly numberOfWeek?: number;
@IsDate()
private readonly startDate?: Date;
@IsString()
private readonly weekSchedule?: string;
constructor(input: any) {
if (typeof input === 'object' && input !== null) {
this.endDate = typeof input['VegNapDatuma'] === 'string' ? new Date(input['VegNapDatuma']) : input['VegNapDatuma'];
this.id = typeof input['Id'] === 'string' ? input['Id'].trim() : undefined;
this.numberOfWeek = typeof input['HetSorszama'] === 'number' ? input['HetSorszama'] : undefined;
this.startDate = typeof input['KezdoNapDatuma'] === 'string' ? new Date(input['KezdoNapDatuma']) : input['KezdoNapDatuma'];
this.weekSchedule = typeof input['Hetirend'] === 'string' ? input['Hetirend'].trim() : undefined;
}
const errors = validateSync(this, { skipMissingProperties: true });
if (errors.length > 0) {
throw this.validationErrorResponse(errors);
}
}
public get VegNapDatuma(): Date | undefined {
return this.endDate;
}
public get Id(): string | undefined {
return this.id;
}
public get HetSorszama(): number | undefined {
return this.numberOfWeek;
}
public get KezdoNapDatuma(): Date | undefined {
return this.startDate;
}
public get Hetirend(): string | undefined {
return this.weekSchedule;
}
public get json(): TimetableWeekFields {
return {
HetSorszama: this.numberOfWeek,
Hetirend: this.weekSchedule,
Id: this.id,
KezdoNapDatuma: this.startDate,
VegNapDatuma: this.endDate,
} as TimetableWeekFields;
}
private validationErrorResponse(errors: Array<ValidationError>): object {
const validFields: Partial<TimetableWeekFields> = {
VegNapDatuma: this.endDate,
Id: this.id,
HetSorszama: this.numberOfWeek,
KezdoNapDatuma: this.startDate,
Hetirend: this.weekSchedule,
};
const errorMessages: Array<string> = [];
for (const error of errors) {
validFields[error.property as keyof TimetableWeekFields] = undefined;
errorMessages.push(...Object.values(error.constraints || {}));
}
return {
valid: validFields,
errors: errorMessages,
};
}
}