-
Notifications
You must be signed in to change notification settings - Fork 1
/
TeszekRegistrationDto.ts
60 lines (49 loc) · 1.63 KB
/
TeszekRegistrationDto.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
import { IsString, validateSync, ValidationError } from 'class-validator';
export interface TeszekRegistrationFields {
Id: string;
RegisztracioIdopontja: string;
}
export default class TeszekRegistrationDto implements Partial<TeszekRegistrationFields> {
@IsString()
private readonly id?: string;
@IsString()
private readonly registrationDateAsString?: string;
constructor(input: any) {
if (typeof input === 'object' && input !== null) {
this.id = typeof input['Id'] === 'string' ? input['Id'].trim() : undefined;
this.registrationDateAsString = typeof input['RegisztracioIdopontja'] === 'string' ? input['RegisztracioIdopontja'].trim() :
undefined;
}
const errors = validateSync(this, { skipMissingProperties: true });
if (errors.length > 0) {
throw this.validationErrorResponse(errors);
}
}
public get Id(): string | undefined {
return this.id;
}
public get RegisztracioIdopontja(): string | undefined {
return this.registrationDateAsString;
}
public get json(): TeszekRegistrationFields {
return {
Id: this.id,
RegisztracioIdopontja: this.registrationDateAsString,
} as TeszekRegistrationFields;
}
private validationErrorResponse(errors: Array<ValidationError>): object {
const validFields: Partial<TeszekRegistrationFields> = {
Id: this.id,
RegisztracioIdopontja: this.registrationDateAsString,
};
const errorMessages: Array<string> = [];
for (const error of errors) {
validFields[error.property as keyof TeszekRegistrationFields] = undefined;
errorMessages.push(...Object.values(error.constraints || {}));
}
return {
valid: validFields,
errors: errorMessages,
};
}
}