-
Notifications
You must be signed in to change notification settings - Fork 0
/
Guardian4TDto.ts
144 lines (119 loc) · 4.07 KB
/
Guardian4TDto.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
import { IsDate, IsOptional, IsString, validateSync, ValidationError } from 'class-validator';
export interface Guardian4TFields {
SzuletesiDatum?: Date;
Utonev?: string;
SzuletesiUtonev?: string;
AnyjaUtonev?: string;
AnyjaVezeteknev?: string;
Elotag: string;
SzuletesiHely?: string;
Vezeteknev?: string;
SzuletesiVezeteknev?: string;
}
export default class Guardian4TDto implements Partial<Guardian4TFields> {
@IsOptional()
@IsDate()
private readonly dateOfBirthAsString?: Date;
@IsOptional()
@IsString()
private readonly firstname?: string;
@IsOptional()
@IsString()
private readonly firstnameOfBirth?: string;
@IsOptional()
@IsString()
private readonly mothersFirstname?: string;
@IsOptional()
@IsString()
private readonly mothersSurname?: string;
@IsString()
private readonly namePrefix?: string;
@IsOptional()
@IsString()
private readonly placeOfBirth?: string;
@IsOptional()
@IsString()
private readonly surname?: string;
@IsOptional()
@IsString()
private readonly surnameOfBirth?: string;
constructor(input: any) {
if (typeof input === 'object' && input !== null) {
this.dateOfBirthAsString = typeof input['SzuletesiDatum'] === 'string' ? new Date(input['SzuletesiDatum']) : undefined;
this.firstname = typeof input['Utonev'] === 'string' ? input['Utonev'].trim() : undefined;
this.firstnameOfBirth = typeof input['SzuletesiUtonev'] === 'string' ? input['SzuletesiUtonev'].trim() : undefined;
this.mothersFirstname = typeof input['AnyjaUtonev'] === 'string' ? input['AnyjaUtonev'].trim() : undefined;
this.mothersSurname = typeof input['AnyjaVezeteknev'] === 'string' ? input['AnyjaVezeteknev'].trim() : undefined;
this.namePrefix = typeof input['Elotag'] === 'string' ? input['Elotag'].trim() : '';
this.placeOfBirth = typeof input['SzuletesiHely'] === 'string' ? input['SzuletesiHely'].trim() : undefined;
this.surname = typeof input['Vezeteknev'] === 'string' ? input['Vezeteknev'].trim() : undefined;
this.surnameOfBirth = typeof input['SzuletesiVezeteknev'] === 'string' ? input['SzuletesiVezeteknev'].trim() : undefined;
}
const errors = validateSync(this, { skipMissingProperties: true });
if (errors.length > 0) {
throw this.validationErrorResponse(errors);
}
}
public get SzuletesiDatum(): Date | undefined {
return this.dateOfBirthAsString;
}
public get Utonev(): string | undefined {
return this.firstname;
}
public get SzuletesiUtonev(): string | undefined {
return this.firstnameOfBirth;
}
public get AnyjaUtonev(): string | undefined {
return this.mothersFirstname;
}
public get AnyjaVezeteknev(): string | undefined {
return this.surname;
}
public get Elotag(): string | undefined {
return this.namePrefix;
}
public get SzuletesiHely(): string | undefined {
return this.placeOfBirth;
}
public get Vezeteknev(): string | undefined {
return this.surname;
}
public get SzuletesiVezeteknev(): string | undefined {
return this.surnameOfBirth;
}
public get json(): Guardian4TFields {
return {
AnyjaUtonev: this.mothersFirstname,
AnyjaVezeteknev: this.mothersSurname,
Elotag: this.namePrefix,
SzuletesiDatum: this.dateOfBirthAsString,
SzuletesiHely: this.placeOfBirth,
SzuletesiUtonev: this.firstnameOfBirth,
SzuletesiVezeteknev: this.surnameOfBirth,
Utonev: this.firstname,
Vezeteknev: this.surname,
} as Guardian4TFields;
}
private validationErrorResponse(errors: Array<ValidationError>): object {
const validFields: Partial<Guardian4TFields> = {
SzuletesiDatum: this.dateOfBirthAsString,
Utonev: this.firstname,
SzuletesiUtonev: this.firstnameOfBirth,
AnyjaUtonev: this.mothersFirstname,
AnyjaVezeteknev: this.mothersSurname,
Elotag: this.namePrefix,
SzuletesiHely: this.placeOfBirth,
Vezeteknev: this.surname,
SzuletesiVezeteknev: this.surnameOfBirth,
};
const errorMessages: Array<string> = [];
for (const error of errors) {
validFields[error.property as keyof Guardian4TFields] = undefined;
errorMessages.push(...Object.values(error.constraints || {}));
}
return {
valid: validFields,
errors: errorMessages,
};
}
}