Skip to content

Commit e5785c5

Browse files
authored
Merge pull request #7 from SlicingDice/feature/handle-list-create-field
Handle createField operation with a list of fields
2 parents 2cdab3d + 4383867 commit e5785c5

File tree

1 file changed

+35
-24
lines changed

1 file changed

+35
-24
lines changed

src/slicer.js

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -234,73 +234,84 @@
234234
}
235235

236236
// Check field name
237-
validateName() {
238-
if (!this.query.hasOwnProperty("name")) {
237+
validateName(query) {
238+
if (!query.hasOwnProperty("name")) {
239239
throw new errors.InvalidFieldDescriptionError("The field's name can't be empty/None.");
240240
}
241241
else {
242-
let name = this.query["name"];
242+
let name = query["name"];
243243
if (name.length > 80) {
244244
throw new errors.InvalidFieldDescriptionError("The field's name have a very big content. (Max: 80 chars)");
245245
}
246246
}
247247
}
248248

249249
// Check field description
250-
validateDescription() {
251-
let description = this.query.description;
250+
validateDescription(query) {
251+
let description = query.description;
252252
if (description.length > 80){
253253
throw new errors.InvalidFieldDescriptionError("The field's description have a very big content. (Max: 300chars)");
254254
}
255255
}
256256

257257
// Check field type
258-
validateFieldType() {
258+
validateFieldType(query) {
259259
// The field should have a type property
260-
if (!this.query.hasOwnProperty("type")){
260+
if (!query.hasOwnProperty("type")){
261261
throw new errors.InvalidFieldError("The field should have a type.");
262262
}
263263
}
264264

265265
// If field is decimal check if it has decimal or decimal-time-series type
266-
validateDecimalType() {
266+
validateDecimalType(query) {
267267
let decimal_types = ["decimal", "decimal-time-series"];
268-
if (!decimal_types.includes(this.query["decimal-place"])) {
268+
if (!decimal_types.includes(query["decimal-place"])) {
269269
throw new errors.InvalidFieldError("This field is only accepted on type 'decimal' or 'decimal-time-series'");
270270
}
271271
}
272272

273273
// Check if string field is valid
274-
checkStrTypeIntegrity() {
275-
if (!this.query.hasOwnProperty("cardinality")){
274+
checkStrTypeIntegrity(query) {
275+
if (!query.hasOwnProperty("cardinality")){
276276
throw new errors.InvalidFieldError("The field with type string should have 'cardinality' key.");
277277
}
278278
}
279279

280280
// Check if enumerated field is valid
281-
validateEnumeratedType() {
282-
if (!this.query.hasOwnProperty("range")){
281+
validateEnumeratedType(query) {
282+
if (!query.hasOwnProperty("range")){
283283
throw new errors.InvalidFieldError("The 'enumerated' type needs of the 'range' parameter.");
284284
}
285285
}
286286

287287
// If field is valid this returns true
288288
validator() {
289-
this.validateName();
290-
this.validateFieldType();
291-
if (this.query["type"] == "string") {
292-
this.checkStrTypeIntegrity();
289+
if (this.query instanceof Array) {
290+
for (let i = 0; i < this.query.length; i++) {
291+
this.validateField(this.query[i]);
292+
}
293+
} else {
294+
this.validateField(this.query);
293295
}
294-
if (this.query["type"] == "enumerated") {
295-
this.validateEnumeratedType();
296+
297+
return true;
298+
}
299+
300+
validateField(query) {
301+
this.validateName(query);
302+
this.validateFieldType(query);
303+
if (query["type"] === "string") {
304+
this.checkStrTypeIntegrity(query);
296305
}
297-
if (this.query.hasOwnProperty("description")) {
298-
this.validateDescription();
306+
if (query["type"] === "enumerated") {
307+
this.validateEnumeratedType(query);
299308
}
300-
if (this.query.hasOwnProperty('decimal-place')) {
301-
this.validateDecimalType();
309+
if (query.hasOwnProperty("description")) {
310+
this.validateDescription(query);
311+
}
312+
if (query.hasOwnProperty("decimal-place")) {
313+
this.validateDecimalType(query);
302314
}
303-
return true;
304315
}
305316
}
306317

0 commit comments

Comments
 (0)