@bluedot-innovation/models 3.0.17 → 3.1.1
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 +7 -0
- package/Models.js +14 -14
- package/__tests__/{filter → condition}/dayRange/dayRange.spec.js +12 -12
- package/__tests__/{filter → condition}/percentageCrossed/travelPath.spec.js +11 -11
- package/__tests__/{filter → condition}/speed/speed.spec.js +21 -21
- package/__tests__/{filter → condition}/timeActive/timeActive.data.json +1 -1
- package/__tests__/{filter → condition}/timeActive/timeActive.spec.js +25 -25
- package/__tests__/{filter → condition}/travelDirection/travelDirection.spec.js +20 -20
- package/__tests__/geofeature/{polyline/polyline.data.json → geoline/geoline.data.json} +3 -3
- package/__tests__/geofeature/{polyline/polyline.spec.js → geoline/geoline.spec.js} +22 -22
- package/__tests__/user/user.spec.js +0 -1
- package/__tests__/zone/zone.action.spec.js +2 -2
- package/__tests__/zone/{zone.filter.spec.js → zone.condition.spec.js} +10 -10
- package/__tests__/zone/zone.data.json +3 -3
- package/__tests__/zone/zone.geofeatures.spec.js +2 -2
- package/__tests__/zone/zone.spec.js +9 -9
- package/helpers.js +12 -12
- package/models/Zone.js +17 -17
- package/models/{filters → conditions}/DayRange.js +7 -7
- package/models/{filters → conditions}/Speed.js +7 -7
- package/models/{filters → conditions}/TimeActive.js +7 -7
- package/models/{filters → conditions}/TravelDirection.js +7 -7
- package/models/{filters → conditions}/TravelPath.js +9 -9
- package/models/geofeatures/{Polyline.js → Geoline.js} +8 -8
- package/package.json +1 -1
- package/validators/checkDistanceBetweenVertices.js +1 -1
- package/models/SimpleCheckInZone.js +0 -29
- /package/__tests__/{filter → condition}/beacon/beaconFilter.data.json +0 -0
- /package/__tests__/{filter → condition}/beacon/beaconFilter.rules.json +0 -0
- /package/__tests__/{filter → condition}/beacon/beaconFilter.spec.js +0 -0
- /package/__tests__/{filter → condition}/dayRange/dayRange.data.json +0 -0
- /package/__tests__/{filter → condition}/dayRange/dayRange.rules.json +0 -0
- /package/__tests__/{filter → condition}/percentageCrossed/travelPath.data.json +0 -0
- /package/__tests__/{filter → condition}/percentageCrossed/travelPath.rules.json +0 -0
- /package/__tests__/{filter → condition}/speed/speed.data.json +0 -0
- /package/__tests__/{filter → condition}/speed/speed.rules.json +0 -0
- /package/__tests__/{filter → condition}/timeActive/timeActive.rules.json +0 -0
- /package/__tests__/{filter → condition}/travelDirection/travelDirection.data.json +0 -0
- /package/__tests__/{filter → condition}/travelDirection/travelDirection.rules.json +0 -0
- /package/__tests__/geofeature/{polyline/polyline.rules.json → geoline/geoline.rules.json} +0 -0
package/CHANGELOG.md
CHANGED
package/Models.js
CHANGED
|
@@ -19,15 +19,15 @@ Models.Zone = require('./models/Zone').Model
|
|
|
19
19
|
Models.BoundingBox = require('./models/geofeatures/BoundingBox').Model
|
|
20
20
|
Models.Circle = require('./models/geofeatures/Circle').Model
|
|
21
21
|
Models.Polygon = require('./models/geofeatures/Polygon').Model
|
|
22
|
-
Models.
|
|
22
|
+
Models.Geoline = require('./models/geofeatures/Geoline').Model
|
|
23
23
|
Models.ZoneBeacon = require('./models/geofeatures/ZoneBeacon').Model
|
|
24
24
|
|
|
25
|
-
//
|
|
26
|
-
Models.DayRange = require('./models/
|
|
27
|
-
Models.TimeActive = require('./models/
|
|
28
|
-
Models.TravelPath = require('./models/
|
|
29
|
-
Models.Speed = require('./models/
|
|
30
|
-
Models.TravelDirection = require('./models/
|
|
25
|
+
// Conditions
|
|
26
|
+
Models.DayRange = require('./models/conditions/DayRange').Model
|
|
27
|
+
Models.TimeActive = require('./models/conditions/TimeActive').Model
|
|
28
|
+
Models.TravelPath = require('./models/conditions/TravelPath').Model
|
|
29
|
+
Models.Speed = require('./models/conditions/Speed').Model
|
|
30
|
+
Models.TravelDirection = require('./models/conditions/TravelDirection').Model
|
|
31
31
|
|
|
32
32
|
let Schemas = {}
|
|
33
33
|
|
|
@@ -45,15 +45,15 @@ Schemas.Zone = require('./models/Zone').Schema
|
|
|
45
45
|
Schemas.BoundingBox = require('./models/geofeatures/BoundingBox').Schema
|
|
46
46
|
Schemas.Circle = require('./models/geofeatures/Circle').Schema
|
|
47
47
|
Schemas.Polygon = require('./models/geofeatures/Polygon').Schema
|
|
48
|
-
Schemas.
|
|
48
|
+
Schemas.Geoline = require('./models/geofeatures/Geoline').Schema
|
|
49
49
|
Schemas.ZoneBeacon = require('./models/geofeatures/ZoneBeacon').Schema
|
|
50
50
|
|
|
51
|
-
//
|
|
52
|
-
Schemas.DayRange = require('./models/
|
|
53
|
-
Schemas.Speed = require('./models/
|
|
54
|
-
Schemas.TimeActive = require('./models/
|
|
55
|
-
Schemas.TravelPath = require('./models/
|
|
56
|
-
Schemas.TravelDirection = require('./models/
|
|
51
|
+
// Conditions
|
|
52
|
+
Schemas.DayRange = require('./models/conditions/DayRange').Schema
|
|
53
|
+
Schemas.Speed = require('./models/conditions/Speed').Schema
|
|
54
|
+
Schemas.TimeActive = require('./models/conditions/TimeActive').Schema
|
|
55
|
+
Schemas.TravelPath = require('./models/conditions/TravelPath').Schema
|
|
56
|
+
Schemas.TravelDirection = require('./models/conditions/TravelDirection').Schema
|
|
57
57
|
|
|
58
58
|
Models.Schemas = Schemas
|
|
59
59
|
module.exports = Models
|
|
@@ -19,11 +19,11 @@ beforeEach(() => {
|
|
|
19
19
|
dayRange = JSON.parse(JSON.stringify(require('./dayRange.data.json')))
|
|
20
20
|
})
|
|
21
21
|
|
|
22
|
-
testCase('
|
|
23
|
-
testCase('Valid
|
|
22
|
+
testCase('DayRangeCondition', () => {
|
|
23
|
+
testCase('Valid DayRangeCondition', () => {
|
|
24
24
|
assertions('should validate a valid dayRange', (done) => {
|
|
25
|
-
let
|
|
26
|
-
|
|
25
|
+
let DayRangeCondition = new DayRangeModel(dayRange)
|
|
26
|
+
DayRangeCondition.validate((err, res) => {
|
|
27
27
|
assert.notExists(res)
|
|
28
28
|
assert(err === null, 'err should equals null')
|
|
29
29
|
done()
|
|
@@ -31,11 +31,11 @@ testCase('DayRangeFilter', () => {
|
|
|
31
31
|
})
|
|
32
32
|
})
|
|
33
33
|
|
|
34
|
-
testCase('Invalid
|
|
35
|
-
assertions('should not validate a dayRange with invalid
|
|
34
|
+
testCase('Invalid DayRangeCondition', () => {
|
|
35
|
+
assertions('should not validate a dayRange with invalid DayRangeCondition', (done) => {
|
|
36
36
|
delete dayRange[rules.requiredFields[0]]
|
|
37
|
-
let
|
|
38
|
-
|
|
37
|
+
let DayRangeCondition = new DayRangeModel(dayRange)
|
|
38
|
+
DayRangeCondition.validate((err, res) => {
|
|
39
39
|
assert.exists(err, 'err object should exist')
|
|
40
40
|
assert.isObject(err)
|
|
41
41
|
done()
|
|
@@ -45,8 +45,8 @@ testCase('DayRangeFilter', () => {
|
|
|
45
45
|
assertions('should throw an error if both startDate and endDate are not provided', (done) => {
|
|
46
46
|
delete dayRange.startDate
|
|
47
47
|
delete dayRange.endDate
|
|
48
|
-
let
|
|
49
|
-
|
|
48
|
+
let DayRangeCondition = new DayRangeModel(dayRange)
|
|
49
|
+
DayRangeCondition.validate((err, res) => {
|
|
50
50
|
assert.exists(err, 'err object should exist')
|
|
51
51
|
assert.isObject(err)
|
|
52
52
|
done()
|
|
@@ -59,8 +59,8 @@ testCase('DayRangeFilter', () => {
|
|
|
59
59
|
assertions(`should throw an error with property '${i}' if '${i}' is not present`, (done) => {
|
|
60
60
|
// delete i from geofeatures' dayRange child
|
|
61
61
|
delete dayRange[i]
|
|
62
|
-
let
|
|
63
|
-
|
|
62
|
+
let DayRangeCondition = new DayRangeModel(dayRange)
|
|
63
|
+
DayRangeCondition.validate((err, res) => {
|
|
64
64
|
assert.notExists(res)
|
|
65
65
|
assert.exists(err, 'err object should exist')
|
|
66
66
|
assert.isObject(err)
|
|
@@ -2,7 +2,7 @@ let mongoose = require('mongoose')
|
|
|
2
2
|
|
|
3
3
|
mongoose.Promise = global.Promise
|
|
4
4
|
|
|
5
|
-
let
|
|
5
|
+
let TravelPathConditionModel = require('../../../Models').TravelPath(mongoose)
|
|
6
6
|
let testCase = require('mocha').describe
|
|
7
7
|
let assertions = require('mocha').it
|
|
8
8
|
let chai = require('chai')
|
|
@@ -19,11 +19,11 @@ beforeEach(() => {
|
|
|
19
19
|
travelPath = JSON.parse(JSON.stringify(require('./travelPath.data.json')))
|
|
20
20
|
})
|
|
21
21
|
|
|
22
|
-
testCase('
|
|
23
|
-
testCase('Valid
|
|
22
|
+
testCase('PercentageCrossedCondition', () => {
|
|
23
|
+
testCase('Valid PercentageCrossedCondition', () => {
|
|
24
24
|
assertions('should validate a valid travelPath ', (done) => {
|
|
25
|
-
let
|
|
26
|
-
|
|
25
|
+
let PercentageCrossedCondition = new TravelPathConditionModel(travelPath)
|
|
26
|
+
PercentageCrossedCondition.validate((err, res) => {
|
|
27
27
|
assert.notExists(res)
|
|
28
28
|
assert(err === null, 'err should equals null')
|
|
29
29
|
done()
|
|
@@ -31,11 +31,11 @@ testCase('PercentageCrossedFilter', () => {
|
|
|
31
31
|
})
|
|
32
32
|
})
|
|
33
33
|
|
|
34
|
-
testCase('Invalid
|
|
35
|
-
assertions('should not validate a travelPath with invalid
|
|
34
|
+
testCase('Invalid PercentageCrossedCondition', () => {
|
|
35
|
+
assertions('should not validate a travelPath with invalid PercentageCrossedCondition', (done) => {
|
|
36
36
|
delete travelPath[rules.requiredFields[0]]
|
|
37
|
-
let
|
|
38
|
-
|
|
37
|
+
let PercentageCrossedCondition = new TravelPathConditionModel(travelPath)
|
|
38
|
+
PercentageCrossedCondition.validate((err, res) => {
|
|
39
39
|
assert.exists(err, 'err object should exist')
|
|
40
40
|
assert.isObject(err)
|
|
41
41
|
done()
|
|
@@ -47,8 +47,8 @@ testCase('PercentageCrossedFilter', () => {
|
|
|
47
47
|
assertions(`should throw an error with property '${i}' if '${i}' is not present`, (done) => {
|
|
48
48
|
// delete i from geofeatures' travelPath child
|
|
49
49
|
delete travelPath[i]
|
|
50
|
-
let
|
|
51
|
-
|
|
50
|
+
let PercentageCrossedCondition = new TravelPathConditionModel(travelPath)
|
|
51
|
+
PercentageCrossedCondition.validate((err, res) => {
|
|
52
52
|
assert.notExists(res)
|
|
53
53
|
assert.exists(err, 'err object should exist')
|
|
54
54
|
assert.isObject(err)
|
|
@@ -2,7 +2,7 @@ let mongoose = require('mongoose')
|
|
|
2
2
|
|
|
3
3
|
mongoose.Promise = global.Promise
|
|
4
4
|
|
|
5
|
-
let
|
|
5
|
+
let SpeedConditionModel = require('../../../Models').Speed(mongoose)
|
|
6
6
|
let testCase = require('mocha').describe
|
|
7
7
|
let assertions = require('mocha').it
|
|
8
8
|
let chai = require('chai')
|
|
@@ -13,17 +13,17 @@ let beforeEach = mocha.beforeEach
|
|
|
13
13
|
|
|
14
14
|
let rules = require('./speed.rules.json')
|
|
15
15
|
|
|
16
|
-
let
|
|
16
|
+
let speedCondition
|
|
17
17
|
|
|
18
18
|
beforeEach(() => {
|
|
19
|
-
|
|
19
|
+
speedCondition = JSON.parse(JSON.stringify(require('./speed.data.json')))
|
|
20
20
|
})
|
|
21
21
|
|
|
22
|
-
testCase('
|
|
23
|
-
testCase('Valid
|
|
24
|
-
assertions('should validate a valid
|
|
25
|
-
let
|
|
26
|
-
|
|
22
|
+
testCase('SpeedCondition', () => {
|
|
23
|
+
testCase('Valid SpeedCondition', () => {
|
|
24
|
+
assertions('should validate a valid speedCondition ', (done) => {
|
|
25
|
+
let SpeedCondition = new SpeedConditionModel(speedCondition)
|
|
26
|
+
SpeedCondition.validate((err, res) => {
|
|
27
27
|
assert.notExists(res)
|
|
28
28
|
assert(err === null, 'err should equals null')
|
|
29
29
|
done()
|
|
@@ -31,21 +31,21 @@ testCase('SpeedFilter', () => {
|
|
|
31
31
|
})
|
|
32
32
|
})
|
|
33
33
|
|
|
34
|
-
testCase('Invalid
|
|
35
|
-
assertions('should not validate a
|
|
36
|
-
delete
|
|
37
|
-
let
|
|
38
|
-
|
|
34
|
+
testCase('Invalid SpeedCondition', () => {
|
|
35
|
+
assertions('should not validate a speedCondition with invalid SpeedCondition', (done) => {
|
|
36
|
+
delete speedCondition[rules.requiredFields[0]]
|
|
37
|
+
let SpeedCondition = new SpeedConditionModel(speedCondition)
|
|
38
|
+
SpeedCondition.validate((err, res) => {
|
|
39
39
|
assert.exists(err, 'err object should exist')
|
|
40
40
|
assert.isObject(err)
|
|
41
41
|
done()
|
|
42
42
|
})
|
|
43
43
|
})
|
|
44
44
|
assertions('should throw an error when maxSpeed is less than 5 of minSpeed', (done) => {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
let
|
|
48
|
-
|
|
45
|
+
speedCondition.minimumSpeed = 10
|
|
46
|
+
speedCondition.maximumSpeed = 11
|
|
47
|
+
let SpeedCondition = new SpeedConditionModel(speedCondition)
|
|
48
|
+
SpeedCondition.validate((err, res) => {
|
|
49
49
|
assert.exists(err, 'err object should exist')
|
|
50
50
|
assert.isObject(err)
|
|
51
51
|
assert.nestedProperty(err, `errors.maximumSpeed`, 'error should have a maximumSpeed property')
|
|
@@ -56,10 +56,10 @@ testCase('SpeedFilter', () => {
|
|
|
56
56
|
let requiredFields = rules.requiredFields
|
|
57
57
|
requiredFields.map((i) => {
|
|
58
58
|
assertions(`should throw an error with property '${i}' if '${i}' is not present`, (done) => {
|
|
59
|
-
// delete i from geofeatures'
|
|
60
|
-
delete
|
|
61
|
-
let
|
|
62
|
-
|
|
59
|
+
// delete i from geofeatures' speedCondition child
|
|
60
|
+
delete speedCondition[i]
|
|
61
|
+
let SpeedCondition = new SpeedConditionModel(speedCondition)
|
|
62
|
+
SpeedCondition.validate((err, res) => {
|
|
63
63
|
assert.notExists(res)
|
|
64
64
|
assert.exists(err, 'err object should exist')
|
|
65
65
|
assert.isObject(err)
|
|
@@ -2,7 +2,7 @@ let mongoose = require('mongoose')
|
|
|
2
2
|
|
|
3
3
|
mongoose.Promise = global.Promise
|
|
4
4
|
|
|
5
|
-
let
|
|
5
|
+
let TimeActiveConditionModel = require('../../../Models').TimeActive(mongoose)
|
|
6
6
|
let testCase = require('mocha').describe
|
|
7
7
|
let assertions = require('mocha').it
|
|
8
8
|
let chai = require('chai')
|
|
@@ -12,17 +12,17 @@ let beforeEach = mocha.beforeEach
|
|
|
12
12
|
|
|
13
13
|
let rules = require('./timeActive.rules.json')
|
|
14
14
|
|
|
15
|
-
let
|
|
15
|
+
let timeActiveCondition
|
|
16
16
|
|
|
17
17
|
beforeEach(() => {
|
|
18
|
-
|
|
18
|
+
timeActiveCondition = JSON.parse(JSON.stringify(require('./timeActive.data.json')))
|
|
19
19
|
})
|
|
20
20
|
|
|
21
|
-
testCase('
|
|
22
|
-
testCase('Valid
|
|
23
|
-
assertions('should validate a valid
|
|
24
|
-
let
|
|
25
|
-
|
|
21
|
+
testCase('TimeOfDayRangeCondition', () => {
|
|
22
|
+
testCase('Valid TimeOfDayRangeCondition', () => {
|
|
23
|
+
assertions('should validate a valid timeActiveCondition ', (done) => {
|
|
24
|
+
let TimeOfDayRangeCondition = new TimeActiveConditionModel(timeActiveCondition)
|
|
25
|
+
TimeOfDayRangeCondition.validate((err, res) => {
|
|
26
26
|
assert.notExists(res)
|
|
27
27
|
assert(err === null, 'err should equals null')
|
|
28
28
|
done()
|
|
@@ -30,21 +30,21 @@ testCase('TimeOfDayRangeFilter', () => {
|
|
|
30
30
|
})
|
|
31
31
|
})
|
|
32
32
|
|
|
33
|
-
testCase('Invalid
|
|
34
|
-
assertions('should not validate a
|
|
35
|
-
delete
|
|
36
|
-
let
|
|
37
|
-
|
|
33
|
+
testCase('Invalid TimeOfDayRangeCondition', () => {
|
|
34
|
+
assertions('should not validate a timeActiveCondition with invalid TimeOfDayRangeCondition', (done) => {
|
|
35
|
+
delete timeActiveCondition[rules.requiredFields[0]]
|
|
36
|
+
let TimeOfDayRangeCondition = new TimeActiveConditionModel(timeActiveCondition)
|
|
37
|
+
TimeOfDayRangeCondition.validate((err, res) => {
|
|
38
38
|
assert.exists(err, 'err object should exist')
|
|
39
39
|
assert.isObject(err)
|
|
40
40
|
done()
|
|
41
41
|
})
|
|
42
42
|
})
|
|
43
43
|
assertions('should throw an error when toTime === fromTime', (done) => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
let
|
|
47
|
-
|
|
44
|
+
timeActiveCondition.toTime = "00:30:00"
|
|
45
|
+
timeActiveCondition.fromTime = "00:30:00"
|
|
46
|
+
let TimeOfDayRangeCondition = new TimeActiveConditionModel(timeActiveCondition)
|
|
47
|
+
TimeOfDayRangeCondition.validate((err, res) => {
|
|
48
48
|
assert.exists(err, 'err object should exist')
|
|
49
49
|
assert.isObject(err)
|
|
50
50
|
assert.nestedProperty(err, `errors.toTime`, 'error should have a toTime property')
|
|
@@ -58,10 +58,10 @@ testCase('TimeOfDayRangeFilter', () => {
|
|
|
58
58
|
invalidTimes.map(i => {
|
|
59
59
|
i.invalidInput.map(j => {
|
|
60
60
|
assertions(`should throw an error with property '${i.name}' if '${i.name} is invalid => ${i.name} = ${j}'`, done => {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
let
|
|
64
|
-
|
|
61
|
+
timeActiveCondition = JSON.parse(JSON.stringify(timeActiveCondition))
|
|
62
|
+
timeActiveCondition[i.name] = j
|
|
63
|
+
let TimeOfDayRangeCondition = new TimeActiveConditionModel(timeActiveCondition)
|
|
64
|
+
TimeOfDayRangeCondition.validate((err, res) => {
|
|
65
65
|
assert.exists(err, 'err object should exits')
|
|
66
66
|
assert.isObject(err)
|
|
67
67
|
assert.nestedProperty(err, `errors.${i.name}`, 'time format must be hh:mm:ss')
|
|
@@ -77,10 +77,10 @@ testCase('TimeOfDayRangeFilter', () => {
|
|
|
77
77
|
let requiredFields = rules.requiredFields
|
|
78
78
|
requiredFields.map((i) => {
|
|
79
79
|
assertions(`should throw an error with property '${i}' if '${i}' is not present`, (done) => {
|
|
80
|
-
// delete i from geofeatures'
|
|
81
|
-
delete
|
|
82
|
-
let
|
|
83
|
-
|
|
80
|
+
// delete i from geofeatures' timeActiveCondition child
|
|
81
|
+
delete timeActiveCondition[i]
|
|
82
|
+
let TimeOfDayRangeCondition = new TimeActiveConditionModel(timeActiveCondition)
|
|
83
|
+
TimeOfDayRangeCondition.validate((err, res) => {
|
|
84
84
|
assert.notExists(res)
|
|
85
85
|
assert.exists(err, 'err object should exist')
|
|
86
86
|
assert.isObject(err)
|
|
@@ -2,7 +2,7 @@ let mongoose = require('mongoose')
|
|
|
2
2
|
mongoose.Promise = global.Promise
|
|
3
3
|
|
|
4
4
|
const TravelDirectionModel = require('../../../Models').TravelDirection(mongoose)
|
|
5
|
-
const { isMinimumNinetyApart } = require.main.require('models/
|
|
5
|
+
const { isMinimumNinetyApart } = require.main.require('models/conditions/TravelDirection')
|
|
6
6
|
const describe = require('mocha').describe
|
|
7
7
|
const it = require('mocha').it
|
|
8
8
|
const chai = require('chai')
|
|
@@ -11,16 +11,16 @@ const mocha = require('mocha')
|
|
|
11
11
|
const beforeEach = mocha.beforeEach
|
|
12
12
|
const rules = require('./travelDirection.rules.json')
|
|
13
13
|
|
|
14
|
-
let
|
|
14
|
+
let travelDirectionCondition
|
|
15
15
|
|
|
16
16
|
beforeEach(() => {
|
|
17
|
-
|
|
17
|
+
travelDirectionCondition = JSON.parse(JSON.stringify(require('./travelDirection.data.json')))
|
|
18
18
|
})
|
|
19
19
|
|
|
20
20
|
describe('TravelDirection', () => {
|
|
21
21
|
describe('Valid TravelDirection', () => {
|
|
22
|
-
it('should validate a valid
|
|
23
|
-
let TravelDirection = new TravelDirectionModel(
|
|
22
|
+
it('should validate a valid travelDirectionCondition ', (done) => {
|
|
23
|
+
let TravelDirection = new TravelDirectionModel(travelDirectionCondition)
|
|
24
24
|
TravelDirection.validate((err, res) => {
|
|
25
25
|
assert.notExists(res)
|
|
26
26
|
assert(err === null, 'err should equals null')
|
|
@@ -30,9 +30,9 @@ describe('TravelDirection', () => {
|
|
|
30
30
|
})
|
|
31
31
|
|
|
32
32
|
describe('Invalid TravelDirection', () => {
|
|
33
|
-
it('should not validate a
|
|
34
|
-
delete
|
|
35
|
-
let TravelDirection = new TravelDirectionModel(
|
|
33
|
+
it('should not validate a travelDirectionCondition with invalid TravelDirection', (done) => {
|
|
34
|
+
delete travelDirectionCondition[rules.requiredFields[0]]
|
|
35
|
+
let TravelDirection = new TravelDirectionModel(travelDirectionCondition)
|
|
36
36
|
TravelDirection.validate((err, res) => {
|
|
37
37
|
assert.exists(err, 'err object should exist')
|
|
38
38
|
assert.isObject(err)
|
|
@@ -40,9 +40,9 @@ describe('TravelDirection', () => {
|
|
|
40
40
|
})
|
|
41
41
|
})
|
|
42
42
|
it('should throw an error when toAngle === fromAngle', (done) => {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
let TravelDirection = new TravelDirectionModel(
|
|
43
|
+
travelDirectionCondition.toAngle = 10
|
|
44
|
+
travelDirectionCondition.fromAngle = 10
|
|
45
|
+
let TravelDirection = new TravelDirectionModel(travelDirectionCondition)
|
|
46
46
|
TravelDirection.validate((err, res) => {
|
|
47
47
|
assert.exists(err, 'err object should exist')
|
|
48
48
|
assert.isObject(err)
|
|
@@ -51,9 +51,9 @@ describe('TravelDirection', () => {
|
|
|
51
51
|
})
|
|
52
52
|
})
|
|
53
53
|
it('should throw an error when toAngle < 90 degrees from fromAngle (and toAngle < fromAngle)', (done) => {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
let TravelDirection = new TravelDirectionModel(
|
|
54
|
+
travelDirectionCondition.toAngle = 5
|
|
55
|
+
travelDirectionCondition.fromAngle = 10
|
|
56
|
+
let TravelDirection = new TravelDirectionModel(travelDirectionCondition)
|
|
57
57
|
TravelDirection.validate((err, res) => {
|
|
58
58
|
assert.exists(err, 'err object should exist')
|
|
59
59
|
assert.isObject(err)
|
|
@@ -62,9 +62,9 @@ describe('TravelDirection', () => {
|
|
|
62
62
|
})
|
|
63
63
|
})
|
|
64
64
|
it('should throw an error when toAngle < 90 degrees from fromAngle (and toAngle > fromAngle)', (done) => {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
let TravelDirection = new TravelDirectionModel(
|
|
65
|
+
travelDirectionCondition.toAngle = 10
|
|
66
|
+
travelDirectionCondition.fromAngle = 5
|
|
67
|
+
let TravelDirection = new TravelDirectionModel(travelDirectionCondition)
|
|
68
68
|
TravelDirection.validate((err, res) => {
|
|
69
69
|
assert.exists(err, 'err object should exist')
|
|
70
70
|
assert.isObject(err)
|
|
@@ -76,9 +76,9 @@ describe('TravelDirection', () => {
|
|
|
76
76
|
let requiredFields = rules.requiredFields
|
|
77
77
|
requiredFields.map((i) => {
|
|
78
78
|
it(`should throw an error with property '${i}' if '${i}' is not present`, (done) => {
|
|
79
|
-
// delete i from geofeatures'
|
|
80
|
-
delete
|
|
81
|
-
let TravelDirection = new TravelDirectionModel(
|
|
79
|
+
// delete i from geofeatures' travelDirectionCondition child
|
|
80
|
+
delete travelDirectionCondition[i]
|
|
81
|
+
let TravelDirection = new TravelDirectionModel(travelDirectionCondition)
|
|
82
82
|
TravelDirection.validate((err, res) => {
|
|
83
83
|
assert.notExists(res)
|
|
84
84
|
assert.exists(err, 'err object should exist')
|
|
@@ -2,8 +2,8 @@ let mongoose = require('mongoose')
|
|
|
2
2
|
|
|
3
3
|
mongoose.Promise = global.Promise
|
|
4
4
|
|
|
5
|
-
let
|
|
6
|
-
let
|
|
5
|
+
let GeolineModel = require('../../../Models').Geoline(mongoose)
|
|
6
|
+
let GeolineModelBuiltInMongoose = require('../../../Models').Geoline()
|
|
7
7
|
let testCase = require('mocha').describe
|
|
8
8
|
let assertions = require('mocha').it
|
|
9
9
|
let chai = require('chai')
|
|
@@ -12,26 +12,26 @@ let assert = chai.assert
|
|
|
12
12
|
let mocha = require('mocha')
|
|
13
13
|
let beforeEach = mocha.beforeEach
|
|
14
14
|
|
|
15
|
-
let rules = require('./
|
|
15
|
+
let rules = require('./geoline.rules.json')
|
|
16
16
|
|
|
17
|
-
let
|
|
17
|
+
let geoline
|
|
18
18
|
|
|
19
19
|
beforeEach(() => {
|
|
20
|
-
|
|
20
|
+
geoline = JSON.parse(JSON.stringify(require('./geoline.data.json')))
|
|
21
21
|
})
|
|
22
|
-
testCase('
|
|
23
|
-
testCase('Valid
|
|
24
|
-
assertions('should validate a valid
|
|
25
|
-
let
|
|
26
|
-
|
|
22
|
+
testCase('Geoline', () => {
|
|
23
|
+
testCase('Valid Geoline', () => {
|
|
24
|
+
assertions('should validate a valid geoline ', (done) => {
|
|
25
|
+
let Geoline = new GeolineModel(geoline)
|
|
26
|
+
Geoline.validate((err, res) => {
|
|
27
27
|
assert.notExists(res)
|
|
28
28
|
assert(err === null, 'err should equals null')
|
|
29
29
|
done()
|
|
30
30
|
})
|
|
31
31
|
})
|
|
32
|
-
assertions('should validate a valid
|
|
33
|
-
let
|
|
34
|
-
|
|
32
|
+
assertions('should validate a valid geoline (built in mongoose)', (done) => {
|
|
33
|
+
let Geoline = new GeolineModelBuiltInMongoose(geoline)
|
|
34
|
+
Geoline.validate((err, res) => {
|
|
35
35
|
assert.notExists(res)
|
|
36
36
|
assert(err === null, 'err should equals null')
|
|
37
37
|
done()
|
|
@@ -39,11 +39,11 @@ testCase('Polyline', () => {
|
|
|
39
39
|
})
|
|
40
40
|
})
|
|
41
41
|
|
|
42
|
-
testCase('Invalid
|
|
43
|
-
assertions('should not validate a
|
|
44
|
-
delete
|
|
45
|
-
let
|
|
46
|
-
|
|
42
|
+
testCase('Invalid Geoline', () => {
|
|
43
|
+
assertions('should not validate a geoline with invalid geoline', (done) => {
|
|
44
|
+
delete geoline[rules.requiredFields[0]]
|
|
45
|
+
let Geoline = new GeolineModel(geoline)
|
|
46
|
+
Geoline.validate((err, res) => {
|
|
47
47
|
assert.exists(err, 'err object should exist')
|
|
48
48
|
assert.isObject(err)
|
|
49
49
|
done()
|
|
@@ -53,10 +53,10 @@ testCase('Polyline', () => {
|
|
|
53
53
|
let requiredFields = rules.requiredFields
|
|
54
54
|
requiredFields.map((i) => {
|
|
55
55
|
assertions(`should throw an error with property '${i}' if '${i}' is not present`, (done) => {
|
|
56
|
-
// delete i from geofeatures'
|
|
57
|
-
delete
|
|
58
|
-
let
|
|
59
|
-
|
|
56
|
+
// delete i from geofeatures' geoline child
|
|
57
|
+
delete geoline[i]
|
|
58
|
+
let Geoline = new GeolineModel(geoline)
|
|
59
|
+
Geoline.validate((err, res) => {
|
|
60
60
|
assert.notExists(res)
|
|
61
61
|
assert.exists(err, 'err object should exist')
|
|
62
62
|
assert.isObject(err)
|
|
@@ -14,8 +14,8 @@ let zone
|
|
|
14
14
|
|
|
15
15
|
beforeEach(() => {
|
|
16
16
|
zone = JSON.parse(JSON.stringify(require('./zone.data.json')))
|
|
17
|
-
// remove
|
|
18
|
-
delete zone.
|
|
17
|
+
// remove conditions as it's not tested
|
|
18
|
+
delete zone.conditions
|
|
19
19
|
// remove all but 1 geofeatures as geofeatures are required
|
|
20
20
|
zone.geofeatures = zone.geofeatures.filter(x => x.type.match(/circle/i))
|
|
21
21
|
// remove customData
|
|
@@ -24,9 +24,9 @@ beforeEach(() => {
|
|
|
24
24
|
delete zone.customData
|
|
25
25
|
})
|
|
26
26
|
|
|
27
|
-
testCase('Zone -
|
|
28
|
-
testCase('Valid Zone -
|
|
29
|
-
assertions('should not throw an error when a valid
|
|
27
|
+
testCase('Zone - Condition', () => {
|
|
28
|
+
testCase('Valid Zone - Condition', () => {
|
|
29
|
+
assertions('should not throw an error when a valid condition is instantiated within a zone', (done) => {
|
|
30
30
|
let Zone = new ZoneModel(zone)
|
|
31
31
|
Zone.validate((err, res) => {
|
|
32
32
|
assert.notExists(res)
|
|
@@ -36,19 +36,19 @@ testCase('Zone - Filter', () => {
|
|
|
36
36
|
})
|
|
37
37
|
})
|
|
38
38
|
|
|
39
|
-
testCase('Invalid Zone -
|
|
40
|
-
assertions('should throw an error when an invalid
|
|
41
|
-
zone.
|
|
39
|
+
testCase('Invalid Zone - Condition', () => {
|
|
40
|
+
assertions('should throw an error when an invalid condition is instantiated within a zone', (done) => {
|
|
41
|
+
zone.conditions[0].startDate = 'abc'
|
|
42
42
|
let Zone = new ZoneModel(zone)
|
|
43
43
|
Zone.validate((err, res) => {
|
|
44
44
|
assert.exists(err, 'err object should exist')
|
|
45
45
|
assert.isObject(err)
|
|
46
|
-
assert('
|
|
46
|
+
assert('conditions.0.startDate' in err.errors)
|
|
47
47
|
assert.notNestedProperty(err, `errors.geofeatures`, 'error should have a url property')
|
|
48
48
|
done()
|
|
49
49
|
})
|
|
50
50
|
})
|
|
51
|
-
assertions('should not throw an error when a valid
|
|
51
|
+
assertions('should not throw an error when a valid condition is instantiated within a zone', (done) => {
|
|
52
52
|
let Zone = new ZoneModel(zone)
|
|
53
53
|
Zone.validate((err, res) => {
|
|
54
54
|
assert.notExists(res)
|
|
@@ -56,9 +56,9 @@ testCase('Zone - Filter', () => {
|
|
|
56
56
|
done()
|
|
57
57
|
})
|
|
58
58
|
})
|
|
59
|
-
assertions('should throw an error when the minimumGeofeaturesCrossed for a travel path
|
|
59
|
+
assertions('should throw an error when the minimumGeofeaturesCrossed for a travel path condition is greater than the total number of geofeatures', (done) => {
|
|
60
60
|
zone.geofeatures = geofeatures
|
|
61
|
-
zone.
|
|
61
|
+
zone.conditions.push({
|
|
62
62
|
"type" : "travelPath",
|
|
63
63
|
"minimumGeofeaturesCrossed" : zone.geofeatures.length+1,
|
|
64
64
|
"timeOutSeconds": 120,
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
}
|
|
23
23
|
],
|
|
24
24
|
"beacons": [],
|
|
25
|
-
"
|
|
25
|
+
"conditions": [
|
|
26
26
|
{
|
|
27
27
|
"type" : "dayRange",
|
|
28
28
|
"startDate" : "2017-11-14",
|
|
@@ -109,8 +109,8 @@
|
|
|
109
109
|
}
|
|
110
110
|
]
|
|
111
111
|
},{
|
|
112
|
-
"type": "
|
|
113
|
-
"name": "Test
|
|
112
|
+
"type": "geoline",
|
|
113
|
+
"name": "Test Geoline",
|
|
114
114
|
"vertices": [
|
|
115
115
|
{
|
|
116
116
|
"latitude": -37.81902680201739,
|
|
@@ -14,8 +14,8 @@ let zone
|
|
|
14
14
|
|
|
15
15
|
beforeEach(() => {
|
|
16
16
|
zone = JSON.parse(JSON.stringify(require('./zone.data.json')))
|
|
17
|
-
// remove
|
|
18
|
-
delete zone.
|
|
17
|
+
// remove conditions as it's not tested
|
|
18
|
+
delete zone.conditions
|
|
19
19
|
|
|
20
20
|
// geofeatures are tested individually so we only need to try one in Zones' test
|
|
21
21
|
zone.geofeatures = zone.geofeatures.filter(x => x.type.match(/beacon/i))
|
|
@@ -57,8 +57,8 @@ describe('Zone', () => {
|
|
|
57
57
|
})
|
|
58
58
|
})
|
|
59
59
|
|
|
60
|
-
it('should instantiate a
|
|
61
|
-
zone.geofeatures = zone.geofeatures.filter(gf => gf.type.match(/^
|
|
60
|
+
it('should instantiate a geoline', (done) => {
|
|
61
|
+
zone.geofeatures = zone.geofeatures.filter(gf => gf.type.match(/^geoline$/))
|
|
62
62
|
let Zone = new ZoneModel(zone)
|
|
63
63
|
Zone.validate((err, res) => {
|
|
64
64
|
assert.notExists(res)
|
|
@@ -90,13 +90,13 @@ describe('Zone', () => {
|
|
|
90
90
|
})
|
|
91
91
|
})
|
|
92
92
|
|
|
93
|
-
it('should throw an error when a
|
|
94
|
-
zone.
|
|
93
|
+
it('should throw an error when a condition is invalid', (done) => {
|
|
94
|
+
zone.conditions[0].startDate = 'abc'
|
|
95
95
|
let Zone = new ZoneModel(zone)
|
|
96
96
|
Zone.validate((err, res) => {
|
|
97
97
|
assert.exists(err, 'err object should exist')
|
|
98
98
|
assert.isObject(err)
|
|
99
|
-
assert('
|
|
99
|
+
assert('conditions.0.startDate' in err.errors, `errors should have a 'conditions.0.startDate' property`)
|
|
100
100
|
done()
|
|
101
101
|
})
|
|
102
102
|
})
|
|
@@ -111,8 +111,8 @@ describe('Zone', () => {
|
|
|
111
111
|
})
|
|
112
112
|
})
|
|
113
113
|
|
|
114
|
-
it('should throw an error when it contains both a beacon and a travelDirection
|
|
115
|
-
zone.
|
|
114
|
+
it('should throw an error when it contains both a beacon and a travelDirection condition', (done) => {
|
|
115
|
+
zone.conditions.push(require('../condition/travelDirection/travelDirection.data.json'));
|
|
116
116
|
let Zone = new ZoneModel(zone)
|
|
117
117
|
Zone.validate((err, res) => {
|
|
118
118
|
assert.exists(err, 'err object should exist')
|
|
@@ -121,8 +121,8 @@ describe('Zone', () => {
|
|
|
121
121
|
})
|
|
122
122
|
})
|
|
123
123
|
|
|
124
|
-
it('should throw an error when it contains both a beacon and a speed
|
|
125
|
-
zone.
|
|
124
|
+
it('should throw an error when it contains both a beacon and a speed condition', (done) => {
|
|
125
|
+
zone.conditions.push(require('../condition/speed/speed.data.json'));
|
|
126
126
|
let Zone = new ZoneModel(zone)
|
|
127
127
|
Zone.validate((err, res) => {
|
|
128
128
|
assert.exists(err, 'err object should exist')
|
package/helpers.js
CHANGED
|
@@ -61,7 +61,7 @@ helpers.checkIsDifferent = function(propertyName) {
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
helpers.
|
|
64
|
+
helpers.checkConditionsSuitableForBeacon = function(zone, next) {
|
|
65
65
|
let hasBeacons = false;
|
|
66
66
|
if( zone.geofeatures && zone.geofeatures.length ) {
|
|
67
67
|
for( let geofeature of zone.geofeatures ) {
|
|
@@ -73,14 +73,14 @@ helpers.checkFiltersSuitableForBeacon = function(zone, next) {
|
|
|
73
73
|
}
|
|
74
74
|
if( !hasBeacons )
|
|
75
75
|
return next(); // No beacons.
|
|
76
|
-
if( !zone.
|
|
77
|
-
return next(); // No
|
|
78
|
-
for( let
|
|
79
|
-
if(
|
|
80
|
-
return next(new Error("Zone cannot both contain a beacon and have a Travel Direction
|
|
76
|
+
if( !zone.conditions || !zone.conditions.length )
|
|
77
|
+
return next(); // No conditions.
|
|
78
|
+
for( let condition of zone.conditions ) {
|
|
79
|
+
if( condition.type === "travelDirection" ) {
|
|
80
|
+
return next(new Error("Zone cannot both contain a beacon and have a Travel Direction condition."))
|
|
81
81
|
}
|
|
82
|
-
if(
|
|
83
|
-
return next(new Error("Zone cannot both contain a beacon and have a Speed
|
|
82
|
+
if( condition.type === "speed" ) {
|
|
83
|
+
return next(new Error("Zone cannot both contain a beacon and have a Speed condition."))
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
next();
|
|
@@ -89,10 +89,10 @@ helpers.checkFiltersSuitableForBeacon = function(zone, next) {
|
|
|
89
89
|
helpers.checkMinimumGeofeaturesValidForZone = function(zone, next) {
|
|
90
90
|
if( !zone.geofeatures )
|
|
91
91
|
return next();
|
|
92
|
-
if( !zone.
|
|
93
|
-
return next(); // No
|
|
94
|
-
for( let
|
|
95
|
-
if(
|
|
92
|
+
if( !zone.conditions || !zone.conditions.length )
|
|
93
|
+
return next(); // No conditions.
|
|
94
|
+
for( let condition of zone.conditions ) {
|
|
95
|
+
if( condition.type === "travelPath" && condition.minimumGeofeaturesCrossed > zone.geofeatures.length ) {
|
|
96
96
|
return next(new Error("Zone must not have minimumGeofeaturesCrossed higher than geofeatures count"))
|
|
97
97
|
}
|
|
98
98
|
}
|
package/models/Zone.js
CHANGED
|
@@ -11,16 +11,16 @@ let messageActionSchema = require('./MessageAction').messageActionSchema
|
|
|
11
11
|
let urlActionSchema = require('./UrlAction').urlActionSchema
|
|
12
12
|
let circleSchema = require('./geofeatures/Circle').circleSchema
|
|
13
13
|
let boundingBoxSchema = require('./geofeatures/BoundingBox').boundingBoxSchema
|
|
14
|
-
let
|
|
14
|
+
let geolineSchema = require('./geofeatures/Geoline').geolineSchema
|
|
15
15
|
let polygonSchema = require('./geofeatures/Polygon').polygonSchema
|
|
16
16
|
let beaconSchema = require('./geofeatures/ZoneBeacon').beaconSchema
|
|
17
17
|
|
|
18
|
-
//
|
|
19
|
-
let speedRawSchema = require('./
|
|
20
|
-
let dayRangeRawSchema = require('./
|
|
21
|
-
let travelDirectionRawSchema = require('./
|
|
22
|
-
let travelPathRawSchema = require('./
|
|
23
|
-
let timeActiveRawSchema = require('./
|
|
18
|
+
// Conditions
|
|
19
|
+
let speedRawSchema = require('./conditions/Speed').rawSchema
|
|
20
|
+
let dayRangeRawSchema = require('./conditions/DayRange').rawSchema
|
|
21
|
+
let travelDirectionRawSchema = require('./conditions/TravelDirection').rawSchema
|
|
22
|
+
let travelPathRawSchema = require('./conditions/TravelPath').rawSchema
|
|
23
|
+
let timeActiveRawSchema = require('./conditions/TimeActive').rawSchema
|
|
24
24
|
|
|
25
25
|
let uuidv4 = require('uuid/v4')
|
|
26
26
|
let patcher = require('mongoose-json-patch')
|
|
@@ -38,7 +38,7 @@ let customDataValidators = [
|
|
|
38
38
|
let actionSchema = new Schema({},
|
|
39
39
|
{ discriminatorKey: 'type', _id: false })
|
|
40
40
|
|
|
41
|
-
let
|
|
41
|
+
let conditionSchema = new Schema({},
|
|
42
42
|
{ discriminatorKey: 'type', _id: false })
|
|
43
43
|
|
|
44
44
|
let geofeatureSchema = new Schema({},
|
|
@@ -58,8 +58,8 @@ let zoneSchema = new Schema({
|
|
|
58
58
|
}
|
|
59
59
|
},
|
|
60
60
|
tags: {type: [String]},
|
|
61
|
-
|
|
62
|
-
type: [
|
|
61
|
+
conditions: {
|
|
62
|
+
type: [conditionSchema]
|
|
63
63
|
},
|
|
64
64
|
actions: {
|
|
65
65
|
type: [actionSchema]
|
|
@@ -83,21 +83,21 @@ zoneSchema.plugin(patcher)
|
|
|
83
83
|
zoneSchema.path('actions').discriminator('url', new Schema(urlActionSchema, {_id: false}))
|
|
84
84
|
zoneSchema.path('actions').discriminator('message', new Schema(messageActionSchema, {_id: false}))
|
|
85
85
|
|
|
86
|
-
zoneSchema.path('
|
|
87
|
-
zoneSchema.path('
|
|
88
|
-
zoneSchema.path('
|
|
89
|
-
zoneSchema.path('
|
|
90
|
-
zoneSchema.path('
|
|
86
|
+
zoneSchema.path('conditions').discriminator('dayRange', new Schema(dayRangeRawSchema, {_id: false}))
|
|
87
|
+
zoneSchema.path('conditions').discriminator('speed', new Schema(speedRawSchema, {_id: false}))
|
|
88
|
+
zoneSchema.path('conditions').discriminator('timeActive', new Schema(timeActiveRawSchema, {_id: false}))
|
|
89
|
+
zoneSchema.path('conditions').discriminator('travelDirection', new Schema(travelDirectionRawSchema, {_id: false}))
|
|
90
|
+
zoneSchema.path('conditions').discriminator('travelPath', new Schema(travelPathRawSchema, {_id: false}))
|
|
91
91
|
|
|
92
92
|
zoneSchema.path('geofeatures').discriminator('beacon', new Schema(beaconSchema))
|
|
93
93
|
zoneSchema.path('geofeatures').discriminator('circle', new Schema(circleSchema))
|
|
94
94
|
zoneSchema.path('geofeatures').discriminator('polygon', new Schema(polygonSchema))
|
|
95
|
-
zoneSchema.path('geofeatures').discriminator('
|
|
95
|
+
zoneSchema.path('geofeatures').discriminator('geoline', new Schema(geolineSchema))
|
|
96
96
|
zoneSchema.path('geofeatures').discriminator('boundingBox', new Schema(boundingBoxSchema))
|
|
97
97
|
|
|
98
98
|
zoneSchema.pre('validate', function(next) {
|
|
99
99
|
Promise.all([
|
|
100
|
-
new Promise((resolve, reject) => helpers.
|
|
100
|
+
new Promise((resolve, reject) => helpers.checkConditionsSuitableForBeacon(this, resolve)),
|
|
101
101
|
new Promise((resolve, reject) => helpers.checkMinimumGeofeaturesValidForZone(this, resolve))
|
|
102
102
|
]).then(results => {
|
|
103
103
|
for( let result of results ) {
|
|
@@ -6,12 +6,12 @@ let schema = {
|
|
|
6
6
|
endDate: {type: Date}
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
let
|
|
9
|
+
let DayRangeConditionSchema = new mongoose.Schema(schema, {
|
|
10
10
|
_id: false,
|
|
11
11
|
versionKey: false
|
|
12
12
|
})
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
DayRangeConditionSchema.add({
|
|
15
15
|
type: {type: String, required: true, validate: {isAsync: true, validator: validateDateRange}}
|
|
16
16
|
})
|
|
17
17
|
|
|
@@ -39,14 +39,14 @@ function validateDateRange (type, callback) {
|
|
|
39
39
|
|
|
40
40
|
// optional mongoose
|
|
41
41
|
let model = (mongooseInstance) => {
|
|
42
|
-
let
|
|
42
|
+
let DayRangeCondition
|
|
43
43
|
if (mongooseInstance) {
|
|
44
|
-
|
|
44
|
+
DayRangeCondition = mongooseInstance.model('DayRangeCondition', DayRangeConditionSchema)
|
|
45
45
|
} else {
|
|
46
|
-
|
|
46
|
+
DayRangeCondition = mongoose.model('DayRangeCondition', DayRangeConditionSchema)
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
return
|
|
49
|
+
return DayRangeCondition
|
|
50
50
|
}
|
|
51
51
|
// Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
|
|
52
|
-
module.exports = { Model: model, Schema:
|
|
52
|
+
module.exports = { Model: model, Schema: DayRangeConditionSchema, rawSchema: schema }
|
|
@@ -5,12 +5,12 @@ let schema = {
|
|
|
5
5
|
minimumSpeed: {type: Number, required: [true, 'minimumSpeed is required. '], min: 0},
|
|
6
6
|
maximumSpeed: {type: Number, required: true, validate: {isAsync: true, validator: validateMaxSpeed, msg: 'default error message'}}
|
|
7
7
|
}
|
|
8
|
-
let
|
|
8
|
+
let SpeedConditionSchema = new mongoose.Schema(schema, {
|
|
9
9
|
_id: false,
|
|
10
10
|
versionKey: false
|
|
11
11
|
})
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
SpeedConditionSchema.add({
|
|
14
14
|
type: {type: String, required: true}
|
|
15
15
|
})
|
|
16
16
|
|
|
@@ -29,14 +29,14 @@ function validateMaxSpeed (v, magicCallback) {
|
|
|
29
29
|
|
|
30
30
|
// optional mongoose
|
|
31
31
|
let model = (mongooseInstance) => {
|
|
32
|
-
let
|
|
32
|
+
let SpeedCondition
|
|
33
33
|
if (mongooseInstance) {
|
|
34
|
-
|
|
34
|
+
SpeedCondition = mongooseInstance.model('SpeedCondition', SpeedConditionSchema)
|
|
35
35
|
} else {
|
|
36
|
-
|
|
36
|
+
SpeedCondition = mongoose.model('SpeedCondition', SpeedConditionSchema)
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
return
|
|
39
|
+
return SpeedCondition
|
|
40
40
|
}
|
|
41
41
|
// Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
|
|
42
|
-
module.exports = { Model: model, Schema:
|
|
42
|
+
module.exports = { Model: model, Schema: SpeedConditionSchema, rawSchema: schema }
|
|
@@ -5,12 +5,12 @@ let schema = {
|
|
|
5
5
|
fromTime: {type: String, required: [true, 'time is required. '], validate: {isAsync: true, validator: validateTimeHHmmssFormat}},
|
|
6
6
|
toTime: {type: String, required: true, validate: [{isAsync: true, validator: validateTime}, {isAsync: true, validator: validateTimeHHmmssFormat}]}
|
|
7
7
|
}
|
|
8
|
-
let
|
|
8
|
+
let TimeActiveConditionSchema = new mongoose.Schema(schema, {
|
|
9
9
|
_id: false,
|
|
10
10
|
versionKey: false
|
|
11
11
|
})
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
TimeActiveConditionSchema.add({
|
|
14
14
|
type: {type: String, required: true}
|
|
15
15
|
})
|
|
16
16
|
|
|
@@ -36,15 +36,15 @@ function validateTimeHHmmssFormat(time, magicCallback) {
|
|
|
36
36
|
|
|
37
37
|
// optional mongoose
|
|
38
38
|
let model = (mongooseInstance) => {
|
|
39
|
-
let
|
|
39
|
+
let TimeActiveCondition
|
|
40
40
|
if (mongooseInstance) {
|
|
41
|
-
|
|
41
|
+
TimeActiveCondition = mongooseInstance.model('TimeActiveCondition', TimeActiveConditionSchema)
|
|
42
42
|
} else {
|
|
43
|
-
|
|
43
|
+
TimeActiveCondition = mongoose.model('TimeActiveCondition', TimeActiveConditionSchema)
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
return
|
|
46
|
+
return TimeActiveCondition
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
// Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
|
|
50
|
-
module.exports = { Model: model, Schema:
|
|
50
|
+
module.exports = { Model: model, Schema: TimeActiveConditionSchema, rawSchema: schema }
|
|
@@ -6,13 +6,13 @@ const schema = {
|
|
|
6
6
|
toAngle: {type: Number, required: true, min: 0, max: 359, validate: {isAsync: true, validator: validateAngles, msg: 'default error message'}}
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
const
|
|
9
|
+
const TravelDirectionConditionSchema = new mongoose.Schema(schema, {
|
|
10
10
|
_id: false,
|
|
11
11
|
versionKey: false
|
|
12
12
|
})
|
|
13
13
|
|
|
14
14
|
// For discriminator key
|
|
15
|
-
|
|
15
|
+
TravelDirectionConditionSchema.add({
|
|
16
16
|
type: {type: String, required: true}
|
|
17
17
|
})
|
|
18
18
|
|
|
@@ -49,19 +49,19 @@ function isMinimumNinetyApart (fromAngle, toAngle) {
|
|
|
49
49
|
|
|
50
50
|
// optional mongoose
|
|
51
51
|
let model = (mongooseInstance) => {
|
|
52
|
-
let
|
|
52
|
+
let TravelDirectionCondition
|
|
53
53
|
if (mongooseInstance) {
|
|
54
|
-
|
|
54
|
+
TravelDirectionCondition = mongooseInstance.model('TravelDirectionCondition', TravelDirectionConditionSchema)
|
|
55
55
|
} else {
|
|
56
|
-
|
|
56
|
+
TravelDirectionCondition = mongoose.model('TravelDirectionCondition', TravelDirectionConditionSchema)
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
return
|
|
59
|
+
return TravelDirectionCondition
|
|
60
60
|
}
|
|
61
61
|
// Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
|
|
62
62
|
module.exports = {
|
|
63
63
|
Model: model,
|
|
64
|
-
Schema:
|
|
64
|
+
Schema: TravelDirectionConditionSchema,
|
|
65
65
|
rawSchema: schema,
|
|
66
66
|
isMinimumNinetyApart
|
|
67
67
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// In V2 this is becoming "Travel Path"
|
|
1
|
+
// In V2 this is becoming "Travel Path" condition
|
|
2
2
|
let mongoose = require('mongoose')
|
|
3
3
|
let uuidv4 = require('uuid/v4')
|
|
4
4
|
|
|
@@ -12,25 +12,25 @@ let schema = {
|
|
|
12
12
|
sequential: {type: Boolean, default: false}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
let
|
|
15
|
+
let TravelPathConditionSchema = new mongoose.Schema(schema, {
|
|
16
16
|
_id: false,
|
|
17
|
-
versionKey: false
|
|
17
|
+
versionKey: false
|
|
18
18
|
})
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
TravelPathConditionSchema.add({
|
|
21
21
|
type: {type: String, required: true}
|
|
22
22
|
})
|
|
23
23
|
|
|
24
24
|
// optional mongoose
|
|
25
25
|
let model = (mongooseInstance) => {
|
|
26
|
-
let
|
|
26
|
+
let TravelPathCondition
|
|
27
27
|
if (mongooseInstance) {
|
|
28
|
-
|
|
28
|
+
TravelPathCondition = mongooseInstance.model('TravelPathCondition', TravelPathConditionSchema)
|
|
29
29
|
} else {
|
|
30
|
-
|
|
30
|
+
TravelPathCondition = mongoose.model('TravelPathCondition', TravelPathConditionSchema)
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
return
|
|
33
|
+
return TravelPathCondition
|
|
34
34
|
}
|
|
35
35
|
// Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
|
|
36
|
-
module.exports = { Model: model, Schema:
|
|
36
|
+
module.exports = { Model: model, Schema: TravelPathConditionSchema, rawSchema: schema }
|
|
@@ -7,28 +7,28 @@ const schema = {
|
|
|
7
7
|
_id: {type: String, default: uuidv4},
|
|
8
8
|
geometry: {type: {}},
|
|
9
9
|
name: {type: String, required: [true, 'name is required. ']},
|
|
10
|
-
vertices: {type: [Point], required: [true, 'vertices
|
|
10
|
+
vertices: {type: [Point], required: [true, 'vertices are required. ']}
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
const
|
|
13
|
+
const GeolineSchema = new mongoose.Schema(schema, {
|
|
14
14
|
_id: false,
|
|
15
15
|
versionKey: false
|
|
16
16
|
})
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
GeolineSchema.add({
|
|
19
19
|
type: {type: String, required: true}
|
|
20
20
|
})
|
|
21
21
|
|
|
22
22
|
// optional mongoose
|
|
23
23
|
let model = (mongooseInstance) => {
|
|
24
|
-
let
|
|
24
|
+
let Geoline
|
|
25
25
|
if (mongooseInstance) {
|
|
26
|
-
|
|
26
|
+
Geoline = mongooseInstance.model('Geoline', GeolineSchema)
|
|
27
27
|
} else {
|
|
28
|
-
|
|
28
|
+
Geoline = mongoose.model('Geoline', GeolineSchema)
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
return
|
|
31
|
+
return Geoline
|
|
32
32
|
}
|
|
33
33
|
// Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
|
|
34
|
-
module.exports = { Model: model, Schema:
|
|
34
|
+
module.exports = { Model: model, Schema: GeolineSchema, geolineSchema: schema }
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@ const { notSameThreeInARow, trimDecimals } = require('../utils');
|
|
|
4
4
|
/**
|
|
5
5
|
* checkDistanceBetweenVertices -
|
|
6
6
|
* Returns boolean signalling whether or not enough space between points in
|
|
7
|
-
* polygons and
|
|
7
|
+
* polygons and geolines. Checks closeness by checking if the same when trimmed
|
|
8
8
|
* to 6 decimal places
|
|
9
9
|
*/
|
|
10
10
|
const checkDistanceBetweenVertices = function(vertices) {
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Created by Arun on 10/09/2014.
|
|
3
|
-
* Copyright : Bluedot Innovations.
|
|
4
|
-
* Owner :
|
|
5
|
-
*/
|
|
6
|
-
let mongoose = require('mongoose')
|
|
7
|
-
let Schema = mongoose.Schema
|
|
8
|
-
let StateEnum = require('@bluedot-innovation/enums').StateEnum
|
|
9
|
-
|
|
10
|
-
let SimpleCheckInZoneSchema = new Schema({
|
|
11
|
-
_id: {type: String},
|
|
12
|
-
name: String,
|
|
13
|
-
description: {type: String, default: ''},
|
|
14
|
-
minimumRetriggerTime: {type: Number},
|
|
15
|
-
checkout: {type: Boolean, default: false},
|
|
16
|
-
dataSource: {type: String, select: false, default: 'openApi'},
|
|
17
|
-
conditionalActions: [],
|
|
18
|
-
spatialFilters: [],
|
|
19
|
-
creationTime: {type: Date, default: Date.now},
|
|
20
|
-
lastUpdateTime: {type: Date, default: Date.now},
|
|
21
|
-
activeTimeRange: Schema.Types.Mixed,
|
|
22
|
-
applicationId: String,
|
|
23
|
-
state: {type: String, default: StateEnum.active, select: false}
|
|
24
|
-
},
|
|
25
|
-
{collection: 'zone'})
|
|
26
|
-
|
|
27
|
-
let SimpleCheckInZone = mongoose.model('SimpleCheckInZone', SimpleCheckInZoneSchema)
|
|
28
|
-
|
|
29
|
-
module.exports = SimpleCheckInZone
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|