-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSchoolGuardDto.ts
103 lines (84 loc) · 2.82 KB
/
SchoolGuardDto.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
import { IsEmail, IsString, validateSync, ValidationError } from 'class-validator';
export interface SchoolGuardFields {
EmailCim: string;
Nev: string;
Telefonszam: string;
FeladatEllatasiHelyId: string;
FeladatEllatasiHelyNev: string;
Uid: string;
}
export default class SchoolGuardDto implements Partial<SchoolGuardFields> {
@IsEmail()
private readonly emailAddress?: string;
@IsString()
private readonly name?: string;
@IsString()
private readonly phoneNumber?: string;
@IsString()
private readonly placeOfWorkId?: string;
@IsString()
private readonly placeOfWorkName?: string;
@IsString()
private readonly uid?: string;
constructor(input: any) {
if (typeof input === 'object' && input !== null) {
this.emailAddress = typeof input['EmailCim'] === 'string' ? input['EmailCim'].trim() : undefined;
this.name = typeof input['Nev'] === 'string' ? input['Nev'].trim() : undefined;
this.phoneNumber = typeof input['Telefonszam'] === 'string' ? input['Telefonszam'].trim() : undefined;
this.placeOfWorkId = typeof input['FeladatEllatasiHelyId'] === 'string' ? input['FeladatEllatasiHelyId'].trim() : undefined;
this.placeOfWorkName = typeof input['FeladatEllatasiHelyNev'] === 'string' ? input['FeladatEllatasiHelyNev'].trim() : undefined;
this.uid = typeof input['Uid'] === 'string' ? input['Uid'].trim() : undefined;
}
const errors = validateSync(this, { skipMissingProperties: true });
if (errors.length > 0) {
throw this.validationErrorResponse(errors);
}
}
public get EmailCim(): string | undefined {
return this.emailAddress;
}
public get Nev(): string | undefined {
return this.name;
}
public get Telefonszam(): string | undefined {
return this.phoneNumber;
}
public get FeladatEllatasiHelyId(): string | undefined {
return this.placeOfWorkId;
}
public get FeladatEllatasiHelyNev(): string | undefined {
return this.placeOfWorkName;
}
public get Uid(): string | undefined {
return this.uid;
}
public get json(): SchoolGuardFields {
return {
EmailCim: this.emailAddress,
FeladatEllatasiHelyId: this.placeOfWorkId,
FeladatEllatasiHelyNev: this.placeOfWorkName,
Nev: this.name,
Telefonszam: this.phoneNumber,
Uid: this.uid,
} as SchoolGuardFields;
}
private validationErrorResponse(errors: Array<ValidationError>): object {
const validFields: Partial<SchoolGuardFields> = {
EmailCim: this.emailAddress,
Nev: this.name,
Telefonszam: this.phoneNumber,
FeladatEllatasiHelyId: this.placeOfWorkId,
FeladatEllatasiHelyNev: this.placeOfWorkName,
Uid: this.uid,
};
const errorMessages: Array<string> = [];
for (const error of errors) {
validFields[error.property as keyof SchoolGuardFields] = undefined;
errorMessages.push(...Object.values(error.constraints || {}));
}
return {
valid: validFields,
errors: errorMessages,
};
}
}