-
Notifications
You must be signed in to change notification settings - Fork 1
/
EmployeeDetailsDto.ts
230 lines (191 loc) · 6.57 KB
/
EmployeeDetailsDto.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
import { IsBoolean, IsNumber, IsOptional, IsString, validateSync, ValidationError } from 'class-validator';
export interface EmployeeDetailsFields {
osztalyHelyettes?: string;
osztalyHelyettesKretaAzonosito?: number;
oktatasiAzonosito?: string;
osztaly?: string;
isAdmin?: boolean;
isOsztalyfonok?: boolean;
isTorolt?: boolean;
isOsztalyfonokHelyettes?: boolean;
isIgazgatoHelyettes?: boolean;
isIgazgato?: boolean;
isAlairo?: boolean;
isTanar?: boolean;
osztalyKretaAzonosito?: number;
kretaAzonosito?: number;
nev?: string;
titulus?: string;
}
export default class EmployeeDetailsDto implements Partial<EmployeeDetailsFields> {
@IsOptional()
@IsString()
private readonly classSubstitute?: string;
@IsOptional()
@IsNumber()
private readonly classSubstituteKretaId?: number;
@IsOptional()
@IsString()
private readonly educatedId?: string;
@IsOptional()
@IsString()
private readonly educationClass?: string;
@IsOptional()
@IsBoolean()
private readonly _isAdmin?: boolean;
@IsOptional()
@IsBoolean()
private readonly isClassMaster?: boolean;
@IsOptional()
@IsBoolean()
private readonly isDeleted?: boolean;
@IsOptional()
@IsBoolean()
private readonly isDeputyClassMaster?: boolean;
@IsOptional()
@IsBoolean()
private readonly isDeputyDirector?: boolean;
@IsOptional()
@IsBoolean()
private readonly isDirector?: boolean;
@IsOptional()
@IsBoolean()
private readonly isSignatory?: boolean;
@IsOptional()
@IsBoolean()
private readonly isTeacher?: boolean;
@IsOptional()
@IsNumber()
private readonly kretaClassId?: number;
@IsOptional()
@IsNumber()
private readonly kretaId?: number;
@IsOptional()
@IsString()
private readonly name?: string;
@IsOptional()
@IsString()
private readonly title?: string;
constructor(input: any) {
if (typeof input === 'object' && input !== null) {
this.classSubstitute = typeof input['osztalyHelyettes'] === 'string' ? input['osztalyHelyettes'].trim() : undefined;
this.classSubstituteKretaId = typeof input['osztalyHelyettesKretaAzonosito'] === 'number' ? input['osztalyHelyettesKretaAzonosito'] :
undefined;
this.educatedId = typeof input['oktatasiAzonosito'] === 'string' ? input['oktatasiAzonosito'].trim() : undefined;
this.educationClass = typeof input['osztaly'] === 'string' ? input['osztaly'].trim() : undefined;
this._isAdmin = typeof input['isAdmin'] === 'boolean' ? input['isAdmin'] : undefined;
this.isClassMaster = typeof input['isOsztalyfonok'] === 'boolean' ? input['isOsztalyfonok'] : undefined;
this.isDeleted = typeof input['isTorolt'] === 'boolean' ? input['isTorolt'] : undefined;
this.isDeputyClassMaster = typeof input['isOsztalyfonokHelyettes'] === 'boolean' ? input['isOsztalyfonokHelyettes'] : undefined;
this.isDeputyDirector = typeof input['isIgazgatoHelyettes'] === 'boolean' ? input['isIgazgatoHelyettes'] : undefined;
this.isDirector = typeof input['isIgazgato'] === 'boolean' ? input['isIgazgato'] : undefined;
this.isSignatory = typeof input['isAlairo'] === 'boolean' ? input['isAlairo'] : undefined;
this.isTeacher = typeof input['isTanar'] === 'boolean' ? input['isTanar'] : undefined;
this.kretaClassId = typeof input['osztalyKretaAzonosito'] === 'number' ? input['osztalyKretaAzonosito'] : undefined;
this.kretaId = typeof input['kretaAzonosito'] === 'number' ? input['kretaAzonosito'] : undefined;
this.name = typeof input['nev'] === 'string' ? input['nev'].trim() : undefined;
this.title = typeof input['titulus'] === 'string' ? input['titulus'].trim() : undefined;
}
const errors = validateSync(this, { skipMissingProperties: true });
if (errors.length > 0) {
throw this.validationErrorResponse(errors);
}
}
public get osztalyHelyettes(): string | undefined {
return this.classSubstitute;
}
public get osztalyHelyettesKretaAzonosito(): number | undefined {
return this.classSubstituteKretaId;
}
public get oktatasiAzonosito(): string | undefined {
return this.educatedId;
}
public get osztaly(): string | undefined {
return this.educationClass;
}
public get isAdmin(): boolean | undefined {
return this._isAdmin;
}
public get isOsztalyfonok(): boolean | undefined {
return this.isClassMaster;
}
public get isTorolt(): boolean | undefined {
return this.isDeleted;
}
public get isOsztalyfonokHelyettes(): boolean | undefined {
return this.isDeputyClassMaster;
}
public get isIgazgatoHelyettes(): boolean | undefined {
return this.isDeputyDirector;
}
public get isIgazgato(): boolean | undefined {
return this.isDirector;
}
public get isAlairo(): boolean | undefined {
return this.isSignatory;
}
public get isTanar(): boolean | undefined {
return this.isTeacher;
}
public get osztalyKretaAzonosito(): number | undefined {
return this.kretaClassId;
}
public get kretaAzonosito(): number | undefined {
return this.kretaId;
}
public get nev(): string | undefined {
return this.name;
}
public get titulus(): string | undefined {
return this.title;
}
public get json(): EmployeeDetailsFields {
return {
isAdmin: this._isAdmin,
isAlairo: this.isSignatory,
isIgazgato: this.isDirector,
isIgazgatoHelyettes: this.isDeputyDirector,
isOsztalyfonok: this.isClassMaster,
isOsztalyfonokHelyettes: this.isDeputyClassMaster,
isTanar: this.isTeacher,
isTorolt: this.isDeleted,
kretaAzonosito: this.kretaId,
nev: this.name,
oktatasiAzonosito: this.educatedId,
osztaly: this.educationClass,
osztalyHelyettes: this.classSubstitute,
osztalyHelyettesKretaAzonosito: this.classSubstituteKretaId,
osztalyKretaAzonosito: this.kretaClassId,
titulus: this.title,
} as EmployeeDetailsFields;
}
private validationErrorResponse(errors: Array<ValidationError>): object {
const validFields: Partial<EmployeeDetailsFields> = {
osztalyHelyettes: this.classSubstitute,
osztalyHelyettesKretaAzonosito: this.classSubstituteKretaId,
oktatasiAzonosito: this.educatedId,
osztaly: this.educationClass,
isAdmin: this._isAdmin,
isOsztalyfonok: this.isClassMaster,
isTorolt: this.isDeleted,
isOsztalyfonokHelyettes: this.isDeputyClassMaster,
isIgazgatoHelyettes: this.isDeputyDirector,
isIgazgato: this.isDirector,
isAlairo: this.isSignatory,
isTanar: this.isTeacher,
osztalyKretaAzonosito: this.kretaClassId,
kretaAzonosito: this.kretaId,
nev: this.name,
titulus: this.title,
};
const errorMessages: Array<string> = [];
for (const error of errors) {
validFields[error.property as keyof EmployeeDetailsFields] = undefined;
errorMessages.push(...Object.values(error.constraints || {}));
}
return {
valid: validFields,
errors: errorMessages,
};
}
}