-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSendMessageToBinRequestDto.ts
61 lines (50 loc) · 1.78 KB
/
SendMessageToBinRequestDto.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
import { IsArray, IsBoolean, IsNumber, validateSync, ValidationError } from 'class-validator';
export interface SendMessageToBinRequestFields {
isKuka: boolean;
postaladaElemAzonositoLista: Array<number>;
}
export default class SendMessageToBinRequestDto implements Partial<SendMessageToBinRequestFields> {
@IsBoolean()
private readonly deleted?: boolean;
@IsArray()
@IsNumber({}, { each: true })
private readonly mailBoxItemId?: Array<number>;
constructor(input: any) {
if (typeof input === 'object' && input !== null) {
this.deleted = typeof input['isKuka'] === 'boolean' ? input['isKuka'] : undefined;
this.mailBoxItemId = Array.isArray(input['postaladaElemAzonositoLista']) ?
input['postaladaElemAzonositoLista'].map((item: any) => Number(item)) : undefined;
}
const errors = validateSync(this, { skipMissingProperties: true });
if (errors.length > 0) {
throw this.validationErrorResponse(errors);
}
}
public get isKuka(): boolean | undefined {
return this.deleted;
}
public get postaladaElemAzonositoLista(): Array<number> | undefined {
return this.mailBoxItemId;
}
public get json(): SendMessageToBinRequestFields {
return {
isKuka: this.deleted,
postaladaElemAzonositoLista: this.mailBoxItemId,
} as SendMessageToBinRequestFields;
}
private validationErrorResponse(errors: Array<ValidationError>): object {
const validFields: Partial<SendMessageToBinRequestFields> = {
isKuka: this.deleted,
postaladaElemAzonositoLista: this.mailBoxItemId,
};
const errorMessages: Array<string> = [];
for (const error of errors) {
validFields[error.property as keyof SendMessageToBinRequestFields] = undefined;
errorMessages.push(...Object.values(error.constraints || {}));
}
return {
valid: validFields,
errors: errorMessages,
};
}
}