-
Notifications
You must be signed in to change notification settings - Fork 150
/
13-payload-validations.js
84 lines (63 loc) · 2.16 KB
/
13-payload-validations.js
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
// Example of payload validation:
module.exports = function (migration) {
// can't create content-type without name property
migration.createContentType('berlin', {
description: 'Where content is born'
});
migration.createContentType('london', {
name: 'The capital of England'
});
const area = migration.editContentType('london');
// can't create field without name and type property
area.createField('population');
const barcelona = migration.createContentType('barcelona', {
name: 'Sagrada Família'
});
barcelona.createField('paella')
.type('Boolean')
.name('is it rice?');
const paella = barcelona.editField('paella');
// can't set new ID for the field with requirements mismatch
paella.newId('1uno');
// can't set a non existing field as a the displayField
barcelona.displayField('area');
const paris = migration.createContentType('paris', {
name: 'croissant'
});
paris.createField('baguette')
.type('Symbol')
.name('what it tastes like');
// can't create field with wrong(misspelled) type value
paris.createField('frog')
.type('Nmber')
.name('what?');
paris.displayField('baguette');
const baguette = paris.editField('baguette');
// can't set field to deleted state without ommitting beforehand
baguette.deleted(true);
paris.deleteField('baguette');
const warsaw = migration.createContentType('warsaw', {
name: 'Fasolka po bretonsku'
});
// can't create field with duplicates in validations array
warsaw.createField('pierogi')
.type('Object')
.name('najlepszy')
.validations([{ in: ['smaczny'] }, { in: ['smaczny'] }]);
const krakow = migration.createContentType('krakow', {
name: 'zamek'
});
// can't create field with invalid validations property
krakow.createField('Żubrówka')
.type('Number')
.name('mocna')
.validations([{ elegancki: { haha: 5 } }]);
const munich = migration.createContentType('munich', {
name: 'ein prosit ein prosit'
});
// can't create field with invalid property type in validations
munich.createField('Helles')
.type('Location')
.name('hendl')
.validations([{ regexp: { pattern: 1 } }]);
};