-
Notifications
You must be signed in to change notification settings - Fork 1
/
MessageLimitationsDto.ts
73 lines (60 loc) · 2.5 KB
/
MessageLimitationsDto.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
import { IsBoolean, IsNumber, validateSync, ValidationError } from 'class-validator';
export interface MessageLimitationsFields {
isCsakEgyCimzettLehet: boolean;
isKuldhetoUzenetekSzamaKorlatozvaVan: boolean;
kuldhetoUzenetekSzamaMegMa: number;
}
export default class MessageLimitationsDto implements Partial<MessageLimitationsFields> {
@IsBoolean()
private readonly isMessageOnlyOneAddresseeLimitation?: boolean;
@IsBoolean()
private readonly isSendableMessagesLimitation?: boolean;
@IsNumber()
private readonly sendableMessagesTodayCount?: number;
constructor(input: any) {
if (typeof input === 'object' && input !== null) {
this.isMessageOnlyOneAddresseeLimitation = typeof input['isCsakEgyCimzettLehet'] === 'boolean' ? input['isCsakEgyCimzettLehet'] :
undefined;
this.isSendableMessagesLimitation = typeof input['isKuldhetoUzenetekSzamaKorlatozvaVan'] === 'boolean' ?
input['isKuldhetoUzenetekSzamaKorlatozvaVan'] : undefined;
this.sendableMessagesTodayCount = typeof input['kuldhetoUzenetekSzamaMegMa'] === 'number' ? input['kuldhetoUzenetekSzamaMegMa'] :
undefined;
}
const errors = validateSync(this, { skipMissingProperties: true });
if (errors.length > 0) {
throw this.validationErrorResponse(errors);
}
}
public get isCsakEgyCimzettLehet(): boolean | undefined {
return this.isMessageOnlyOneAddresseeLimitation;
}
public get isKuldhetoUzenetekSzamaKorlatozvaVan(): boolean | undefined {
return this.isSendableMessagesLimitation;
}
public get kuldhetoUzenetekSzamaMegMa(): number | undefined {
return this.sendableMessagesTodayCount;
}
public get json(): MessageLimitationsFields {
return {
isCsakEgyCimzettLehet: this.isMessageOnlyOneAddresseeLimitation,
isKuldhetoUzenetekSzamaKorlatozvaVan: this.isSendableMessagesLimitation,
kuldhetoUzenetekSzamaMegMa: this.sendableMessagesTodayCount,
} as MessageLimitationsFields;
}
private validationErrorResponse(errors: Array<ValidationError>): object {
const validFields: Partial<MessageLimitationsFields> = {
isCsakEgyCimzettLehet: this.isMessageOnlyOneAddresseeLimitation,
isKuldhetoUzenetekSzamaKorlatozvaVan: this.isSendableMessagesLimitation,
kuldhetoUzenetekSzamaMegMa: this.sendableMessagesTodayCount,
};
const errorMessages: Array<string> = [];
for (const error of errors) {
validFields[error.property as keyof MessageLimitationsFields] = undefined;
errorMessages.push(...Object.values(error.constraints || {}));
}
return {
valid: validFields,
errors: errorMessages,
};
}
}