@bluedot-innovation/models 5.1.27-alpha.4 → 5.1.27-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__tests__/helpers.js +6 -0
- package/__tests__/zone/zone.spec.js +5 -9
- package/models/Zone.js +6 -5
- package/package.json +1 -1
package/__tests__/helpers.js
CHANGED
|
@@ -23,4 +23,10 @@ helpers.testNullValue = (docObject, model, callback) => {
|
|
|
23
23
|
})
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
helpers.removeDuplicatedTags = zone => {
|
|
27
|
+
if (zone.tags && zone.tags.length) {
|
|
28
|
+
zone.tags = [...new Set(zone.tags.map(tag => typeof tag === 'string' ? tag.toLowerCase() : tag))]
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
26
32
|
module.exports = helpers
|
|
@@ -86,16 +86,12 @@ describe('Zone', () => {
|
|
|
86
86
|
})
|
|
87
87
|
})
|
|
88
88
|
|
|
89
|
-
it('should set tags to lowercase and remove the duplicated tag', (
|
|
89
|
+
it('should set tags to lowercase and remove the duplicated tag', () => {
|
|
90
90
|
zone.tags = ["TAG", 1, "TaG", 1]
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
assert.
|
|
94
|
-
assert.
|
|
95
|
-
assert.strictEqual(Zone._doc.tags.length, 2)
|
|
96
|
-
assert.strictEqual(Zone._doc.tags[0], "tag")
|
|
97
|
-
assert.strictEqual(Zone._doc.tags[1], "1")
|
|
98
|
-
done()
|
|
91
|
+
helpers.removeDuplicatedTags(zone)
|
|
92
|
+
assert.strictEqual(zone.tags.length, 2)
|
|
93
|
+
assert.strictEqual(zone.tags[0], "tag")
|
|
94
|
+
assert.strictEqual(zone.tags[1], 1)
|
|
99
95
|
})
|
|
100
96
|
})
|
|
101
97
|
|
package/models/Zone.js
CHANGED
|
@@ -37,9 +37,10 @@ let customDataValidators = [
|
|
|
37
37
|
{validator: helpers.isValidCustomDataCount, msg: 'Only 5 custom data fields are allowed to be added per zone'}
|
|
38
38
|
];
|
|
39
39
|
|
|
40
|
-
const tagsFormation = (zone
|
|
41
|
-
zone.tags
|
|
42
|
-
|
|
40
|
+
const tagsFormation = (zone) => {
|
|
41
|
+
if (zone.tags && zone.tags.length) {
|
|
42
|
+
zone.tags = [...new Set(zone.tags.map(tag => typeof tag === 'string' ? tag.toLowerCase() : String(tag)))]
|
|
43
|
+
}
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
let actionSchema = new Schema({},
|
|
@@ -140,13 +141,13 @@ zoneSchema.pre('validate', function(next) {
|
|
|
140
141
|
new Promise((resolve, reject) => helpers.checkArrayContainsValidValues(this, ['geofeatures', 'actions', 'conditions', 'tags'], resolve)),
|
|
141
142
|
new Promise((resolve, reject) => helpers.checkConditionsSuitableForBeacon(this, resolve)),
|
|
142
143
|
new Promise((resolve, reject) => helpers.checkMinimumGeofeaturesValidForZone(this, resolve)),
|
|
143
|
-
new Promise((resolve, reject) => helpers.validateTravelPathConditionCount(this, resolve))
|
|
144
|
-
new Promise((resolve, reject) => tagsFormation(this, next))
|
|
144
|
+
new Promise((resolve, reject) => helpers.validateTravelPathConditionCount(this, resolve))
|
|
145
145
|
]).then(results => {
|
|
146
146
|
for( let result of results ) {
|
|
147
147
|
if( result )
|
|
148
148
|
return next(result)
|
|
149
149
|
}
|
|
150
|
+
tagsFormation(this)
|
|
150
151
|
next()
|
|
151
152
|
}).catch((error) => console.log('Validation error ', error));
|
|
152
153
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bluedot-innovation/models",
|
|
3
|
-
"version": "5.1.27-alpha.
|
|
3
|
+
"version": "5.1.27-alpha.6",
|
|
4
4
|
"main": "Models.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"lint": "./node_modules/.bin/eslint -c .eslintrc.js ./models/*.js ./__tests__/**/*.js ./__tests__/**/**/*.js ./schemas/*.js",
|