@bluedot-innovation/models 5.1.27-alpha.3 → 5.1.27-alpha.5
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 +5 -7
- 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() : tag))]
|
|
43
|
+
}
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
let actionSchema = new Schema({},
|
|
@@ -146,14 +147,11 @@ zoneSchema.pre('validate', function(next) {
|
|
|
146
147
|
if( result )
|
|
147
148
|
return next(result)
|
|
148
149
|
}
|
|
150
|
+
tagsFormation(this)
|
|
149
151
|
next()
|
|
150
152
|
}).catch((error) => console.log('Validation error ', error));
|
|
151
153
|
})
|
|
152
154
|
|
|
153
|
-
zoneSchema.pre('save', function (next) {
|
|
154
|
-
tagsFormation(this, next)
|
|
155
|
-
})
|
|
156
|
-
|
|
157
155
|
// optional mongoose
|
|
158
156
|
const model = (mongooseInstance) => {
|
|
159
157
|
let Zone
|
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.5",
|
|
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",
|