@bluedot-innovation/models 5.1.29 → 5.1.31
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 +6 -0
- package/__tests__/zone/zone.spec.js +29 -0
- package/constants/commonConstants.js +4 -0
- package/helpers.js +27 -0
- package/models/Zone.js +2 -1
- package/models/conditions/DayRange.js +3 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
## 5.1.31
|
|
2
|
+
- Validated Travel Direction/Speed conditions cannot be added to a Zone that contains large(low accuracy) Geofences.
|
|
3
|
+
|
|
4
|
+
## 5.1.30
|
|
5
|
+
- Added DayRange validation
|
|
6
|
+
|
|
1
7
|
## 5.1.29
|
|
2
8
|
- Validated BoundingBox and Polygon's area should be at least 70 square metres
|
|
3
9
|
|
|
@@ -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 )
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
let mongoose = require('mongoose')
|
|
2
2
|
|
|
3
3
|
let schema = {
|
|
4
|
-
startDate: {type: Date},
|
|
4
|
+
startDate: {type: Date, validate: validateDateRange},
|
|
5
5
|
endDate: {type: Date}
|
|
6
6
|
}
|
|
7
7
|
|
|
@@ -11,7 +11,7 @@ let DayRangeConditionSchema = new mongoose.Schema(schema, {
|
|
|
11
11
|
})
|
|
12
12
|
|
|
13
13
|
DayRangeConditionSchema.add({
|
|
14
|
-
type: {type: String, required: true, validate:
|
|
14
|
+
type: {type: String, required: true, validate: validateDateRange}
|
|
15
15
|
})
|
|
16
16
|
|
|
17
17
|
function validateDateRange (type, callback) {
|
|
@@ -20,7 +20,7 @@ function validateDateRange (type, callback) {
|
|
|
20
20
|
|
|
21
21
|
if (!startDate && !endDate) return callback(false, `Must have a startDate, endDate, or both.`)
|
|
22
22
|
|
|
23
|
-
if (!startDate) startDate = new Date(
|
|
23
|
+
if (!startDate) startDate = new Date(startDate)
|
|
24
24
|
|
|
25
25
|
if (!endDate) endDate = new Date(endDate)
|
|
26
26
|
|
package/package.json
CHANGED