@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 CHANGED
@@ -1,3 +1,6 @@
1
+ ## 5.1.28
2
+ - Fixed PATCH tags with lowercase and unique strings
3
+
1
4
  ## 5.1.27
2
5
  - Fixed validations for `macAddress` in Beacon model
3
6
 
@@ -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', (done) => {
89
+ it('should set tags to lowercase and remove the duplicated tag', () => {
90
90
  zone.tags = ["TAG", 1, "TaG", 1]
91
-
92
- let Zone = new ZoneModel(zone)
93
- assert.exists(Zone._doc)
94
- assert.exists(Zone._doc.tags)
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 = (tags) => {
41
- return [...new Set(tags.map(tag => typeof tag === 'string' ? tag.toLowerCase(): tag))]
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], set : tagsFormation, validate: helpers.validateNotNull},
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bluedot-innovation/models",
3
- "version": "5.1.27",
3
+ "version": "5.1.28",
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",