@bluedot-innovation/models 2.0.21-alpha.3 → 2.0.21
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 +4 -0
- package/helpers.js +1 -18
- package/models/Zone.js +3 -6
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/helpers.js
CHANGED
|
@@ -20,29 +20,12 @@ helpers.validateCustomData = function (data) {
|
|
|
20
20
|
let hasValidationErrors = false
|
|
21
21
|
|
|
22
22
|
customDataKeys.forEach(key => {
|
|
23
|
-
const alphaNumericValidation = new RegExp(
|
|
23
|
+
const alphaNumericValidation = new RegExp(/^\w+$/)
|
|
24
24
|
if(!alphaNumericValidation.test(key)){
|
|
25
25
|
hasValidationErrors = true
|
|
26
26
|
}
|
|
27
27
|
})
|
|
28
28
|
|
|
29
|
-
const checkDuplicateKeys = [...new Set(customDataKeys)]
|
|
30
|
-
if(customDataKeys.length > checkDuplicateKeys.length) {
|
|
31
|
-
hasValidationErrors = true
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return !hasValidationErrors
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
helpers.checkDuplicateKeys = function (data) {
|
|
38
|
-
const customDataKeys = Object.keys(data)
|
|
39
|
-
let hasValidationErrors = false
|
|
40
|
-
|
|
41
|
-
const duplicateKeys = [...new Set(customDataKeys)]
|
|
42
|
-
if(customDataKeys.length > duplicateKeys.length) {
|
|
43
|
-
hasValidationErrors = true
|
|
44
|
-
}
|
|
45
|
-
|
|
46
29
|
return !hasValidationErrors
|
|
47
30
|
}
|
|
48
31
|
|
package/models/Zone.js
CHANGED
|
@@ -27,11 +27,6 @@ let helpers = require('../helpers')
|
|
|
27
27
|
// Schema //
|
|
28
28
|
// ////// //
|
|
29
29
|
|
|
30
|
-
let customDataValidators = [
|
|
31
|
-
{validator: helpers.validateCustomData, msg: 'CustomData key should have alpha numeric and _ characters only'},
|
|
32
|
-
{validator: helpers.checkDuplicateKeys, msg: 'CustomData key should be unique'},
|
|
33
|
-
];
|
|
34
|
-
|
|
35
30
|
let actionSchema = new Schema({},
|
|
36
31
|
{ discriminatorKey: 'type', _id: false })
|
|
37
32
|
|
|
@@ -66,7 +61,7 @@ let zoneSchema = new Schema({
|
|
|
66
61
|
required: true
|
|
67
62
|
},
|
|
68
63
|
triggerOnExit: {type: Boolean, default: false},
|
|
69
|
-
customData: {type: Schema.Types.Mixed
|
|
64
|
+
customData: {type: Schema.Types.Mixed},
|
|
70
65
|
creationTime: {type: Date, default: Date.now},
|
|
71
66
|
lastUpdateTime: {type: Date, default: Date.now},
|
|
72
67
|
projectId: {type: String, required: [true, 'projectId is required']},
|
|
@@ -92,6 +87,8 @@ zoneSchema.path('geofeatures').discriminator('polygon', new Schema(polygonSchema
|
|
|
92
87
|
zoneSchema.path('geofeatures').discriminator('polyline', new Schema(polylineSchema))
|
|
93
88
|
zoneSchema.path('geofeatures').discriminator('boundingBox', new Schema(boundingBoxSchema))
|
|
94
89
|
|
|
90
|
+
zoneSchema.path('customData').validate(helpers.validateCustomData, 'CustomData key should have alpha numeric and _ characters only')
|
|
91
|
+
|
|
95
92
|
// optional mongoose
|
|
96
93
|
const model = (mongooseInstance) => {
|
|
97
94
|
let Zone
|