@bluedot-innovation/models 5.1.27 → 5.1.28
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/CHANGELOG.md +3 -0
- package/__tests__/helpers.js +6 -0
- package/__tests__/zone/zone.spec.js +5 -9
- package/models/Zone.js +6 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
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() : String(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,8 +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 = (
|
|
41
|
-
|
|
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
|
+
}
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
let actionSchema = new Schema({},
|
|
@@ -84,7 +86,7 @@ let zoneSchema = new Schema({
|
|
|
84
86
|
message: '{VALUE} is not a number'
|
|
85
87
|
}
|
|
86
88
|
},
|
|
87
|
-
tags: {type: [String],
|
|
89
|
+
tags: {type: [String], validate: helpers.validateNotNull},
|
|
88
90
|
conditions: {
|
|
89
91
|
type: [conditionSchema],
|
|
90
92
|
validate: {
|
|
@@ -145,6 +147,7 @@ zoneSchema.pre('validate', function(next) {
|
|
|
145
147
|
if( result )
|
|
146
148
|
return next(result)
|
|
147
149
|
}
|
|
150
|
+
tagsFormation(this)
|
|
148
151
|
next()
|
|
149
152
|
}).catch((error) => console.log('Validation error ', error));
|
|
150
153
|
})
|
package/package.json
CHANGED