@bluedot-innovation/models 5.1.30 → 5.1.32
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
|
@@ -45,6 +45,7 @@ testCase('Circle', () => {
|
|
|
45
45
|
let Circle = new CircleModel(circle)
|
|
46
46
|
assert.isTrue(Circle.center.latitude instanceof mongoose.Types.Double)
|
|
47
47
|
assert.isTrue(Circle.center.longitude instanceof mongoose.Types.Double)
|
|
48
|
+
assert.isTrue(Circle.radius instanceof mongoose.Types.Double)
|
|
48
49
|
done()
|
|
49
50
|
})
|
|
50
51
|
})
|
|
@@ -339,6 +339,35 @@ describe('Zone', () => {
|
|
|
339
339
|
})
|
|
340
340
|
})
|
|
341
341
|
|
|
342
|
+
it('should throw an error when a zone has a low accuracy fence with Speed/travelDirection condition', (done) => {
|
|
343
|
+
zone.conditions.push({
|
|
344
|
+
"type": "speed",
|
|
345
|
+
"minimumSpeed": 0,
|
|
346
|
+
"maximumSpeed": 68.33142000000001
|
|
347
|
+
})
|
|
348
|
+
zone.geofeatures = [
|
|
349
|
+
{
|
|
350
|
+
"type": "boundingBox",
|
|
351
|
+
"name": "Test BoundingBox",
|
|
352
|
+
"accuracy": "low",
|
|
353
|
+
"northEast": {
|
|
354
|
+
"latitude": -37.81794619852986,
|
|
355
|
+
"longitude": 144.97999548912048
|
|
356
|
+
},
|
|
357
|
+
"southWest": {
|
|
358
|
+
"latitude": -37.81846319511329,
|
|
359
|
+
"longitude": 144.97921228408813
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
]
|
|
363
|
+
let Zone = new ZoneModel(zone)
|
|
364
|
+
Zone.validate((err, res) => {
|
|
365
|
+
assert.exists(err, 'err object should exist')
|
|
366
|
+
assert.match(err.message, /(This Zone contains one or more large Geofences. Travel Direction\/Speed conditions cannot be added to a Zone that contains large Geofences.)/i)
|
|
367
|
+
done()
|
|
368
|
+
})
|
|
369
|
+
})
|
|
370
|
+
|
|
342
371
|
describe('should throw an error when any of the values of the array contains a falsy value', () => {
|
|
343
372
|
let arrayTypeFields = rules.arrayTypeFields
|
|
344
373
|
|
package/helpers.js
CHANGED
|
@@ -2,6 +2,7 @@ var equal = require('deep-equal');
|
|
|
2
2
|
const { clean } = require('./utils');
|
|
3
3
|
const area = require('@turf/area').default;
|
|
4
4
|
const {polygon} = require('@turf/helpers');
|
|
5
|
+
const {BEACON, LOW_ACCURACY, TRAVEL_DIRECTION, SPEED} = require('./constants/commonConstants')
|
|
5
6
|
|
|
6
7
|
let helpers = {}
|
|
7
8
|
|
|
@@ -165,6 +166,32 @@ helpers.checkArrayContainsValidValues = function(document, properties, next) {
|
|
|
165
166
|
return next()
|
|
166
167
|
}
|
|
167
168
|
|
|
169
|
+
helpers.checkValidLowAccuracyFence = function(zone, next) {
|
|
170
|
+
let hasLowAccuracyFence = false;
|
|
171
|
+
|
|
172
|
+
if (!zone.geofeatures || !zone.geofeatures.length) return next()
|
|
173
|
+
zone.geofeatures.forEach(geofeature => {
|
|
174
|
+
if(!geofeature) return next(new Error("Geofeature must have a type"))
|
|
175
|
+
if(geofeature.type !== BEACON && geofeature.accuracy === LOW_ACCURACY){
|
|
176
|
+
hasLowAccuracyFence = true
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
if(hasLowAccuracyFence) {
|
|
181
|
+
if (!zone.conditions || !zone.conditions.length) return next()
|
|
182
|
+
|
|
183
|
+
const hasSpeedOrDirection = zone.conditions.find(condition => {
|
|
184
|
+
if(!condition) return next(new Error("condition must have a type"))
|
|
185
|
+
return (condition.type === TRAVEL_DIRECTION) || (condition.type === SPEED)
|
|
186
|
+
})
|
|
187
|
+
|
|
188
|
+
if(hasSpeedOrDirection) {
|
|
189
|
+
return next(new Error("This Zone contains one or more large Geofences. Travel Direction/Speed conditions cannot be added to a Zone that contains large Geofences."))
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
next()
|
|
193
|
+
}
|
|
194
|
+
|
|
168
195
|
helpers.validateNotNull = function(value) {
|
|
169
196
|
return value !== null
|
|
170
197
|
}
|
package/models/Zone.js
CHANGED
|
@@ -141,7 +141,8 @@ zoneSchema.pre('validate', function(next) {
|
|
|
141
141
|
new Promise((resolve, reject) => helpers.checkArrayContainsValidValues(this, ['geofeatures', 'actions', 'conditions', 'tags'], resolve)),
|
|
142
142
|
new Promise((resolve, reject) => helpers.checkConditionsSuitableForBeacon(this, resolve)),
|
|
143
143
|
new Promise((resolve, reject) => helpers.checkMinimumGeofeaturesValidForZone(this, resolve)),
|
|
144
|
-
new Promise((resolve, reject) => helpers.validateTravelPathConditionCount(this, resolve))
|
|
144
|
+
new Promise((resolve, reject) => helpers.validateTravelPathConditionCount(this, resolve)),
|
|
145
|
+
new Promise((resolve, reject) => helpers.checkValidLowAccuracyFence(this, resolve))
|
|
145
146
|
]).then(results => {
|
|
146
147
|
for( let result of results ) {
|
|
147
148
|
if( result )
|
|
@@ -2,6 +2,7 @@ let mongoose = require('mongoose')
|
|
|
2
2
|
let ZoneEnum = require('@bluedot-innovation/enums').ZoneEnum
|
|
3
3
|
let Point = require('../../schemas/Point')
|
|
4
4
|
let uuidv4 = require('uuid/v4')
|
|
5
|
+
let Double = require('@mongoosejs/double')
|
|
5
6
|
|
|
6
7
|
let schema = {
|
|
7
8
|
_id: {type: String, default: uuidv4},
|
|
@@ -9,7 +10,7 @@ let schema = {
|
|
|
9
10
|
name: {type: String, required: [true, 'name is required. ']},
|
|
10
11
|
color: String,
|
|
11
12
|
accuracy: {type: String, enum: Object.values(ZoneEnum.fenceAccuracy)},
|
|
12
|
-
radius: {type:
|
|
13
|
+
radius: {type: Double, required: [true, 'radius is required. '], min: 5},
|
|
13
14
|
center: {type: Point, required: [true, 'center is required. ']}
|
|
14
15
|
}
|
|
15
16
|
|
package/package.json
CHANGED