-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathcolumn-request.dto.ts
More file actions
198 lines (175 loc) · 4.77 KB
/
column-request.dto.ts
File metadata and controls
198 lines (175 loc) · 4.77 KB
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
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import {
IsArray,
IsBoolean,
IsOptional,
IsString,
IsEnum,
IsNumber,
ValidateIf,
IsNotEmpty,
Validate,
ValidateNested,
} from 'class-validator';
import { Type } from 'class-transformer';
import { ValidationTypesEnum } from '@impler/client';
import { IsValidRegex } from '@shared/framework/is-valid-regex.validator';
import { IsValidDigitsConstraint } from '@shared/framework/is-valid-digits.validator';
import { IsNumberOrString } from '@shared/framework/number-or-string.validator';
import { ColumnDelimiterEnum, ColumnTypesEnum } from '@impler/shared';
export class ValidationDto {
@ApiProperty({
description: 'Specifies the type of column',
enum: ValidationTypesEnum,
})
@IsEnum(ValidationTypesEnum, {
message: `type must be one of ${Object.values(ValidationTypesEnum).join(', ')}`,
})
validate: ValidationTypesEnum;
@ApiPropertyOptional({
description: 'Message to be shown on error',
})
@IsString()
@IsOptional()
errorMessage?: string;
@ApiPropertyOptional({
description: 'Minimum value for digit validation',
})
@IsNumber()
@IsOptional()
@ValidateIf((object) => object.validate === ValidationTypesEnum.DIGITS)
@Validate(IsValidDigitsConstraint, {
message: 'Invalid number of digits',
})
min?: number;
@ApiPropertyOptional({
description: 'Maximum value for digit validation',
})
@IsNumber()
@IsOptional()
@ValidateIf((object) => object.validate === ValidationTypesEnum.DIGITS)
@Validate(IsValidDigitsConstraint, {
message: 'Invalid number of digits',
})
max?: number;
@ApiPropertyOptional({
description: 'Unique key of the validator',
})
@IsString()
@ValidateIf((object) => object.validate === ValidationTypesEnum.UNIQUE_WITH)
uniqueKey: string;
}
export class ColumnRequestDto {
@ApiProperty({
description: 'Name of the column',
type: 'string',
})
@IsString()
name: string;
@ApiProperty({
description: 'Key of the column',
})
@IsString()
key: string;
@ApiProperty({
description: 'Description of the column',
})
@IsOptional()
@IsString()
description?: string;
@ApiProperty({
description: 'Alternative possible keys of the column',
type: Array<string>,
})
@IsArray()
@IsOptional()
@Type(() => Array<string>)
alternateKeys: string[];
@ApiPropertyOptional({
description: 'While true, it Indicates column value should exists in data',
})
@IsBoolean()
@IsOptional()
isRequired? = false;
@ApiPropertyOptional({
description: 'While true, it Indicates column value should be unique in data',
})
@IsBoolean()
@IsOptional()
isUnique? = false;
@ApiPropertyOptional({
description: 'While true, it Indicates column value should be frozen in data',
})
@IsBoolean()
@IsOptional()
isFrozen? = false;
@ApiProperty({
description: 'Specifies the type of column',
enum: ColumnTypesEnum,
})
@IsEnum(ColumnTypesEnum, {
message: `type must be one of ${Object.values(ColumnTypesEnum).join(', ')}`,
})
type: ColumnTypesEnum;
@ApiPropertyOptional({
description: 'Regex if type is Regex',
})
@ValidateIf((object) => object.type === ColumnTypesEnum.REGEX)
@Validate(IsValidRegex)
@IsNotEmpty()
regex: string;
@ApiPropertyOptional({
description: 'Description of Regex',
})
@ValidateIf((object) => object.type === ColumnTypesEnum.REGEX)
@IsString()
@IsOptional()
regexDescription: string;
@ApiPropertyOptional({
description: 'List of possible values for column if type is Select',
})
@ValidateIf((object) => object.type === ColumnTypesEnum.SELECT)
@Type(() => Array<string>)
selectValues: string[] = [];
@ApiPropertyOptional({
description: 'List of date formats for column if type is Date',
})
@ValidateIf((object) => object.type === ColumnTypesEnum.DATE)
@Type(() => Array<string>)
dateFormats: string[];
@ApiProperty({
description: 'Sequence of column',
})
@IsNumber()
@IsOptional()
sequence: number;
@ApiProperty({
description: 'Default value for cell',
})
@IsOptional()
@Validate(IsNumberOrString)
defaultValue?: string | number;
@ApiPropertyOptional({
description: 'If true, column can have multiple values',
})
@IsBoolean()
@IsOptional()
allowMultiSelect?: boolean;
@ApiPropertyOptional({
description: 'Specify the delimiter for multi-select value',
enum: ColumnDelimiterEnum,
})
@IsOptional()
@IsEnum(ColumnDelimiterEnum, {
message: `Delimiter must be one of ${Object.values(ColumnDelimiterEnum).join(', ')}`,
})
delimiter?: ColumnDelimiterEnum;
@ApiPropertyOptional({
description: 'Validations for column',
})
@IsArray()
@IsOptional()
@Type(() => ValidationDto)
@ValidateNested({ each: true })
validations?: ValidationDto[];
}