@bluedot-innovation/models 5.1.27-alpha.1 → 5.1.27-alpha.2

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.
Files changed (2) hide show
  1. package/models/Zone.js +8 -3
  2. package/package.json +1 -1
package/models/Zone.js CHANGED
@@ -37,8 +37,9 @@ 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, next) => {
41
+ zone.tags = [...new Set(zone.tags.map(tag => tag.toLowerCase()))]
42
+ next()
42
43
  }
43
44
 
44
45
  let actionSchema = new Schema({},
@@ -84,7 +85,7 @@ let zoneSchema = new Schema({
84
85
  message: '{VALUE} is not a number'
85
86
  }
86
87
  },
87
- tags: {type: [String], set : tagsFormation, validate: helpers.validateNotNull},
88
+ tags: {type: [String], validate: helpers.validateNotNull},
88
89
  conditions: {
89
90
  type: [conditionSchema],
90
91
  validate: {
@@ -149,6 +150,10 @@ zoneSchema.pre('validate', function(next) {
149
150
  }).catch((error) => console.log('Validation error ', error));
150
151
  })
151
152
 
153
+ zoneSchema.pre('save', function (next) {
154
+ tagsFormation(this, next)
155
+ })
156
+
152
157
  // optional mongoose
153
158
  const model = (mongooseInstance) => {
154
159
  let Zone
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bluedot-innovation/models",
3
- "version": "5.1.27-alpha.1",
3
+ "version": "5.1.27-alpha.2",
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",