@bluedot-innovation/models 5.1.31 → 5.1.33
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__/geofeature/circle/circle.spec.js +1 -0
- package/__tests__/zone/zone.spec.js +12 -1
- package/constants/tests.js +2 -1
- package/helpers.js +18 -0
- package/models/Zone.js +2 -1
- package/models/geofeatures/Circle.js +2 -1
- package/package.json +1 -1
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
|
})
|
|
@@ -4,7 +4,7 @@ let chai = require('chai')
|
|
|
4
4
|
let assert = chai.assert
|
|
5
5
|
let rules = require('./zone.rules.json')
|
|
6
6
|
let helpers = require('../helpers')
|
|
7
|
-
let { FALSY_VALUES } = require('../../constants/tests')
|
|
7
|
+
let { FALSY_VALUES, GEOFEATURE_ID } = require('../../constants/tests')
|
|
8
8
|
|
|
9
9
|
let ZoneModel = require('../../Models').Zone(mongoose)
|
|
10
10
|
let ZoneModelBuiltInMongoose = require('../../Models').Zone()
|
|
@@ -379,5 +379,16 @@ describe('Zone', () => {
|
|
|
379
379
|
})
|
|
380
380
|
})
|
|
381
381
|
})
|
|
382
|
+
|
|
383
|
+
it('should throw an error when geofeatures have the same _id', (done) => {
|
|
384
|
+
zone.geofeatures[0]._id = GEOFEATURE_ID
|
|
385
|
+
zone.geofeatures[1]._id = GEOFEATURE_ID
|
|
386
|
+
let Zone = new ZoneModel(zone)
|
|
387
|
+
Zone.validate((err, res) => {
|
|
388
|
+
assert.exists(err, 'err object should exist')
|
|
389
|
+
assert.match(err.message, /(Duplicate values are not allowed for geofeatures _id.)/i)
|
|
390
|
+
done()
|
|
391
|
+
})
|
|
392
|
+
})
|
|
382
393
|
})
|
|
383
394
|
})
|
package/constants/tests.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
exports.FALSY_VALUES = [null, false, NaN, "", undefined]
|
|
1
|
+
exports.FALSY_VALUES = [null, false, NaN, "", undefined]
|
|
2
|
+
exports.GEOFEATURE_ID = 'd4dc6266-3380-4f61-b534-3ebe1258a545'
|
package/helpers.js
CHANGED
|
@@ -192,6 +192,24 @@ helpers.checkValidLowAccuracyFence = function(zone, next) {
|
|
|
192
192
|
next()
|
|
193
193
|
}
|
|
194
194
|
|
|
195
|
+
helpers.checkDuplicateGeofeaturesId = function(zone, next) {
|
|
196
|
+
if (!zone.geofeatures || !zone.geofeatures.length) return next()
|
|
197
|
+
zone.geofeatures.forEach(geofeature => {
|
|
198
|
+
if(!geofeature) return next(new Error("Geofeature must have a type"))
|
|
199
|
+
})
|
|
200
|
+
|
|
201
|
+
if (zone.geofeatures && zone.geofeatures.length > 0) {
|
|
202
|
+
const geofeatureIds = new Set()
|
|
203
|
+
const hasDuplicates = zone.geofeatures.some(geofeature => {
|
|
204
|
+
return geofeatureIds.size === geofeatureIds.add(geofeature._id).size
|
|
205
|
+
})
|
|
206
|
+
if (hasDuplicates) {
|
|
207
|
+
return next(new Error("Duplicate values are not allowed for geofeatures _id."))
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
next()
|
|
211
|
+
}
|
|
212
|
+
|
|
195
213
|
helpers.validateNotNull = function(value) {
|
|
196
214
|
return value !== null
|
|
197
215
|
}
|
package/models/Zone.js
CHANGED
|
@@ -142,7 +142,8 @@ zoneSchema.pre('validate', function(next) {
|
|
|
142
142
|
new Promise((resolve, reject) => helpers.checkConditionsSuitableForBeacon(this, resolve)),
|
|
143
143
|
new Promise((resolve, reject) => helpers.checkMinimumGeofeaturesValidForZone(this, resolve)),
|
|
144
144
|
new Promise((resolve, reject) => helpers.validateTravelPathConditionCount(this, resolve)),
|
|
145
|
-
new Promise((resolve, reject) => helpers.checkValidLowAccuracyFence(this, resolve))
|
|
145
|
+
new Promise((resolve, reject) => helpers.checkValidLowAccuracyFence(this, resolve)),
|
|
146
|
+
new Promise((resolve, reject) => helpers.checkDuplicateGeofeaturesId(this, resolve))
|
|
146
147
|
]).then(results => {
|
|
147
148
|
for( let result of results ) {
|
|
148
149
|
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