@bluedot-innovation/models 1.0.26-alpha → 2.0.0-alpha.10
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/.eslintrc.js +6 -0
- package/.gitlab-ci.yml +43 -0
- package/.nyc_output/.gitkeep +0 -0
- package/Models.js +8 -8
- package/README.MD +36 -0
- package/__tests__/action/message/messageAction.data.json +5 -0
- package/__tests__/action/message/messageAction.rules.json +3 -0
- package/__tests__/action/message/messageAction.spec.js +61 -0
- package/__tests__/action/url/urlAction.data.json +4 -0
- package/__tests__/action/url/urlAction.rules.json +3 -0
- package/__tests__/action/url/urlAction.spec.js +62 -0
- package/__tests__/dailyStats/checkDailyStats.js +30 -0
- package/__tests__/filter/beacon/beaconFilter.data.json +1 -0
- package/__tests__/filter/beacon/beaconFilter.rules.json +3 -0
- package/__tests__/filter/beacon/beaconFilter.spec.js +1 -0
- package/__tests__/filter/bearing/bearingFilter.data.json +5 -0
- package/__tests__/filter/bearing/bearingFilter.rules.json +3 -0
- package/__tests__/filter/bearing/bearingFilter.spec.js +95 -0
- package/__tests__/filter/calendarDateRange/calendarDateRangeFilter.data.json +5 -0
- package/__tests__/filter/calendarDateRange/calendarDateRangeFilter.rules.json +3 -0
- package/__tests__/filter/calendarDateRange/calendarDateRangeFilter.spec.js +62 -0
- package/__tests__/filter/percentageCrossed/percentageCrossedFilter.data.json +5 -0
- package/__tests__/filter/percentageCrossed/percentageCrossedFilter.rules.json +3 -0
- package/__tests__/filter/percentageCrossed/percentageCrossedFilter.spec.js +62 -0
- package/__tests__/filter/speed/speedFilter.data.json +5 -0
- package/__tests__/filter/speed/speedFilter.rules.json +3 -0
- package/__tests__/filter/speed/speedFilter.spec.js +73 -0
- package/__tests__/filter/timeOfDayRange/timeOfDayRange.data.json +5 -0
- package/__tests__/filter/timeOfDayRange/timeOfDayRange.rules.json +3 -0
- package/__tests__/filter/timeOfDayRange/timeOfDayRange.spec.js +73 -0
- package/__tests__/geofeature/beacon/beacon.data.json +12 -0
- package/__tests__/geofeature/beacon/beacon.rules.json +13 -0
- package/__tests__/geofeature/beacon/beacon.spec.js +95 -0
- package/__tests__/geofeature/boundingBox/boundingBox.data.json +12 -0
- package/__tests__/geofeature/boundingBox/boundingBox.rules.json +3 -0
- package/__tests__/geofeature/boundingBox/boundingBox.spec.js +61 -0
- package/__tests__/geofeature/circle/circle.data.json +9 -0
- package/__tests__/geofeature/circle/circle.rules.json +3 -0
- package/__tests__/geofeature/circle/circle.spec.js +62 -0
- package/__tests__/geofeature/polygon/polygon.data.json +46 -0
- package/__tests__/geofeature/polygon/polygon.rules.json +3 -0
- package/__tests__/geofeature/polygon/polygon.spec.js +61 -0
- package/__tests__/geofeature/polyline/polyline.data.json +46 -0
- package/__tests__/geofeature/polyline/polyline.rules.json +3 -0
- package/__tests__/geofeature/polyline/polyline.spec.js +61 -0
- package/__tests__/zone/zone.action.spec.js +50 -0
- package/__tests__/zone/zone.data.json +154 -0
- package/__tests__/zone/zone.filter.spec.js +50 -0
- package/__tests__/zone/zone.geofeatures.spec.js +64 -0
- package/__tests__/zone/zone.spec.js +98 -0
- package/models/AdminPortalUser.js +10 -11
- package/models/AdminUser.js +6 -5
- package/models/Application.js +31 -30
- package/models/Beacon.js +102 -32
- package/models/BeaconFilter.js +30 -12
- package/models/BearingFilter.js +56 -17
- package/models/BoundingBox.js +36 -14
- package/models/CalendarDateRangeFilter.js +41 -0
- package/models/Circle.js +37 -19
- package/models/Contract.js +37 -38
- package/models/Customer.js +31 -31
- package/models/CustomerLogin.js +9 -10
- package/models/DBEvent.js +13 -14
- package/models/DailyStats.js +7 -7
- package/models/DeviceRulesRequest.js +27 -28
- package/models/Fence.js +12 -13
- package/models/GeoFence.js +12 -14
- package/models/Geofeature.js +16 -18
- package/models/MessageAction.js +32 -25
- package/models/NotificationLogEntry.js +7 -8
- package/models/POILocation.js +6 -7
- package/models/POILookup.js +8 -9
- package/models/POIResult.js +7 -8
- package/models/PartnerCustomer.js +12 -13
- package/models/PartnerPasswordReset.js +8 -9
- package/models/PartnerUser.js +10 -11
- package/models/Partners.js +11 -12
- package/models/PercentageCrossedFilter.js +30 -16
- package/models/Polygon.js +34 -15
- package/models/Polyline.js +35 -15
- package/models/RuleRequestAggregation.js +14 -17
- package/models/SimpleCheckInZone.js +21 -21
- package/models/SingleUseToken.js +7 -8
- package/models/SpeedFilter.js +43 -16
- package/models/TestDevice.js +11 -12
- package/models/TestDeviceCluster.js +9 -10
- package/models/TestInstance.js +9 -10
- package/models/TestScenario.js +9 -10
- package/models/TimeOfDayRange.js +16 -16
- package/models/TimeOfDayRangeFilter.js +39 -16
- package/models/UrlAction.js +51 -0
- package/models/Zone.js +97 -0
- package/models/ZoneUIState.js +18 -18
- package/package.json +25 -4
- package/schemas/Point.js +13 -0
- package/NodeModels.iml +0 -9
- package/models/ApplicationNotificationAction.js +0 -30
- package/models/ApplicationUsage.js +0 -11
- package/models/ConfigurationParameters.js +0 -20
- package/models/DateRangeFilter.js +0 -20
- package/models/FormattedBeacon.js +0 -16
- package/models/FormattedCircle.js +0 -12
- package/models/FormattedConditions.js +0 -11
- package/models/FormattedDateRange.js +0 -11
- package/models/FormattedPercentageCrossed.js +0 -12
- package/models/FormattedPoint.js +0 -10
- package/models/FormattedPolygon.js +0 -11
- package/models/FormattedPolyline.js +0 -11
- package/models/FormattedRectangle.js +0 -12
- package/models/FormattedTimeActive.js +0 -17
- package/models/FormattedZone.js +0 -28
- package/models/MonthlyStats.js +0 -28
- package/models/Point.js +0 -20
- package/models/PropertyMapping.js +0 -17
- package/models/Reference.js +0 -19
- package/models/SequenceFilter.js +0 -18
- package/models/SoundAction.js +0 -28
- package/models/URLAction.js +0 -31
- package/models/VibrationAction.js +0 -28
- package/models/property.js +0 -25
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "TDD zone",
|
|
3
|
+
"minimumRetriggerTime": "60",
|
|
4
|
+
"checkout": true,
|
|
5
|
+
"applicationId": "c7058934-f1e6-4176-8730-a0bd28e8e0a9",
|
|
6
|
+
"customData": [
|
|
7
|
+
{
|
|
8
|
+
"name1": "A Custom action1"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"name2": "A Custom action2"
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
"actions": [
|
|
15
|
+
{
|
|
16
|
+
"type": "message",
|
|
17
|
+
"message": "hello",
|
|
18
|
+
"title": "hello"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"type": "url",
|
|
22
|
+
"url": "https://www.google.com"
|
|
23
|
+
}
|
|
24
|
+
],
|
|
25
|
+
"filters": [
|
|
26
|
+
{
|
|
27
|
+
"type" : "calendarDateRange",
|
|
28
|
+
"startDate" : "2017-11-14",
|
|
29
|
+
"endDate" : "2017-11-15"
|
|
30
|
+
}
|
|
31
|
+
],
|
|
32
|
+
"geofeatures": [{
|
|
33
|
+
"type": "beacon",
|
|
34
|
+
"name": "create beacon",
|
|
35
|
+
"proximityUUID": "23a01af0-232a-4518-9c0e-323fb773f5ef",
|
|
36
|
+
"latitude": -37.8159544565362,
|
|
37
|
+
"longitude": 144.9723565578461,
|
|
38
|
+
"beaconType": "Both",
|
|
39
|
+
"major": 10000,
|
|
40
|
+
"phone": 123123123123,
|
|
41
|
+
"minor": 56466,
|
|
42
|
+
"txPower": -77,
|
|
43
|
+
"macAddress": "01:17:c5:31:84:19"
|
|
44
|
+
},{
|
|
45
|
+
"type": "circle",
|
|
46
|
+
"name": "Test Circle",
|
|
47
|
+
"radius": 10,
|
|
48
|
+
"center": {
|
|
49
|
+
"latitude": -37.8159544565362,
|
|
50
|
+
"longitude": 144.9723565578461
|
|
51
|
+
}
|
|
52
|
+
},{
|
|
53
|
+
"type": "boundingBox",
|
|
54
|
+
"name": "Test BoundingBox",
|
|
55
|
+
"northEast": {
|
|
56
|
+
"latitude": -37.81794619852986,
|
|
57
|
+
"longitude": 144.97999548912048
|
|
58
|
+
},
|
|
59
|
+
"southWest": {
|
|
60
|
+
"latitude": -37.81846319511329,
|
|
61
|
+
"longitude": 144.97921228408813
|
|
62
|
+
}
|
|
63
|
+
},{
|
|
64
|
+
"type": "polygon",
|
|
65
|
+
"name": "Test Polygon",
|
|
66
|
+
"vertices": [
|
|
67
|
+
{
|
|
68
|
+
"latitude": -37.81902680201739,
|
|
69
|
+
"longitude": 144.9821037054062
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
"latitude": -37.8196878692931,
|
|
73
|
+
"longitude": 144.98161554336548
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"latitude": -37.82052267015026,
|
|
77
|
+
"longitude": 144.9816906452179
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"latitude": -37.82128118660006,
|
|
81
|
+
"longitude": 144.98312830924988
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"latitude": -37.82102693614463,
|
|
85
|
+
"longitude": 144.98458743095398
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
"latitude": -37.820196378553405,
|
|
89
|
+
"longitude": 144.98524725437164
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
"latitude": -37.81895899991077,
|
|
93
|
+
"longitude": 144.9847161769867
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
"latitude": -37.81865812731128,
|
|
97
|
+
"longitude": 144.9839222431183
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
"latitude": -37.81866660261256,
|
|
101
|
+
"longitude": 144.98308539390564
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
"latitude": -37.81902680201739,
|
|
105
|
+
"longitude": 144.9821037054062
|
|
106
|
+
}
|
|
107
|
+
]
|
|
108
|
+
},{
|
|
109
|
+
"type": "polyline",
|
|
110
|
+
"name": "Test Polygon",
|
|
111
|
+
"vertices": [
|
|
112
|
+
{
|
|
113
|
+
"latitude": -37.81902680201739,
|
|
114
|
+
"longitude": 144.9821037054062
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
"latitude": -37.8196878692931,
|
|
118
|
+
"longitude": 144.98161554336548
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
"latitude": -37.82052267015026,
|
|
122
|
+
"longitude": 144.9816906452179
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
"latitude": -37.82128118660006,
|
|
126
|
+
"longitude": 144.98312830924988
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
"latitude": -37.82102693614463,
|
|
130
|
+
"longitude": 144.98458743095398
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
"latitude": -37.820196378553405,
|
|
134
|
+
"longitude": 144.98524725437164
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
"latitude": -37.81895899991077,
|
|
138
|
+
"longitude": 144.9847161769867
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
"latitude": -37.81865812731128,
|
|
142
|
+
"longitude": 144.9839222431183
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
"latitude": -37.81866660261256,
|
|
146
|
+
"longitude": 144.98308539390564
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
"latitude": -37.81902680201739,
|
|
150
|
+
"longitude": 144.9821037054062
|
|
151
|
+
}
|
|
152
|
+
]
|
|
153
|
+
}]
|
|
154
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
let mongoose = require('mongoose')
|
|
2
|
+
|
|
3
|
+
mongoose.Promise = global.Promise
|
|
4
|
+
|
|
5
|
+
let ZoneModel = require('../../models/Zone')(mongoose)
|
|
6
|
+
let testCase = require('mocha').describe
|
|
7
|
+
let assertions = require('mocha').it
|
|
8
|
+
let chai = require('chai')
|
|
9
|
+
let assert = chai.assert
|
|
10
|
+
let mocha = require('mocha')
|
|
11
|
+
let beforeEach = mocha.beforeEach
|
|
12
|
+
|
|
13
|
+
let zone
|
|
14
|
+
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
zone = JSON.parse(JSON.stringify(require('./zone.data.json')))
|
|
17
|
+
// remove actions as it's not tested
|
|
18
|
+
delete zone.actions
|
|
19
|
+
// remove all but 1 geofeatures as geofeatures are required
|
|
20
|
+
zone.geofeatures = zone.geofeatures.filter(x => x.type.match(/circle/i))
|
|
21
|
+
// remove customData
|
|
22
|
+
delete zone.customData
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
testCase('Zone - Filter', () => {
|
|
26
|
+
testCase('Valid Zone - Filter', () => {
|
|
27
|
+
assertions('should not throw an error when a valid filter is instantiated within a zone', (done) => {
|
|
28
|
+
let Zone = new ZoneModel(zone)
|
|
29
|
+
Zone.validate((err, res) => {
|
|
30
|
+
assert.notExists(res)
|
|
31
|
+
assert(err === null, 'err equals null')
|
|
32
|
+
done()
|
|
33
|
+
})
|
|
34
|
+
})
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
testCase('Invalid Zone - Filter', () => {
|
|
38
|
+
assertions('should throw an error when an invalid filter is instantiated within a zone', (done) => {
|
|
39
|
+
delete zone.filters[0].startDate
|
|
40
|
+
let Zone = new ZoneModel(zone)
|
|
41
|
+
Zone.validate((err, res) => {
|
|
42
|
+
assert.exists(err, 'err object should exist')
|
|
43
|
+
assert.isObject(err)
|
|
44
|
+
assert('filters.0.startDate' in err.errors)
|
|
45
|
+
assert.notNestedProperty(err, `errors.geofeatures`, 'error should have a url property')
|
|
46
|
+
done()
|
|
47
|
+
})
|
|
48
|
+
})
|
|
49
|
+
})
|
|
50
|
+
})
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
let mongoose = require('mongoose')
|
|
2
|
+
|
|
3
|
+
mongoose.Promise = global.Promise
|
|
4
|
+
|
|
5
|
+
let ZoneModel = require('../../models/Zone')(mongoose)
|
|
6
|
+
let testCase = require('mocha').describe
|
|
7
|
+
let assertions = require('mocha').it
|
|
8
|
+
let chai = require('chai')
|
|
9
|
+
let assert = chai.assert
|
|
10
|
+
let mocha = require('mocha')
|
|
11
|
+
let beforeEach = mocha.beforeEach
|
|
12
|
+
|
|
13
|
+
let zone
|
|
14
|
+
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
zone = JSON.parse(JSON.stringify(require('./zone.data.json')))
|
|
17
|
+
// remove filters as it's not tested
|
|
18
|
+
delete zone.filters
|
|
19
|
+
|
|
20
|
+
// geofeatures are tested individually so we only need to try one in Zones' test
|
|
21
|
+
zone.geofeatures = zone.geofeatures.filter(x => x.type.match(/beacon/i))
|
|
22
|
+
|
|
23
|
+
// remove customData
|
|
24
|
+
delete zone.customData
|
|
25
|
+
|
|
26
|
+
// remove actions
|
|
27
|
+
delete zone.actions
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
testCase('Zone - Action', () => {
|
|
31
|
+
testCase('Valid Zone - Action', () => {
|
|
32
|
+
assertions('should not throw an error when a valid geofeature is instantiated within a zone', (done) => {
|
|
33
|
+
let Zone = new ZoneModel(zone)
|
|
34
|
+
Zone.validate((err, res) => {
|
|
35
|
+
assert.notExists(res)
|
|
36
|
+
assert(err === null, 'err equals null')
|
|
37
|
+
done()
|
|
38
|
+
})
|
|
39
|
+
})
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
testCase('Invalid Zone - Action', () => {
|
|
43
|
+
assertions('should throw an error when an invalid geofeature is instantiated within a zone', (done) => {
|
|
44
|
+
delete zone.geofeatures[0].name
|
|
45
|
+
let Zone = new ZoneModel(zone)
|
|
46
|
+
Zone.validate((err, res) => {
|
|
47
|
+
assert.exists(err, 'err object should exist')
|
|
48
|
+
assert.isObject(err)
|
|
49
|
+
assert('geofeatures.0.name' in err.errors)
|
|
50
|
+
done()
|
|
51
|
+
})
|
|
52
|
+
})
|
|
53
|
+
assertions('should throw an error when an invalid geofeature (complex validation) is instantiated within a zone', (done) => {
|
|
54
|
+
delete zone.geofeatures[0].minor
|
|
55
|
+
let Zone = new ZoneModel(zone)
|
|
56
|
+
Zone.validate((err, res) => {
|
|
57
|
+
assert.exists(err, 'err object should exist')
|
|
58
|
+
assert.isObject(err)
|
|
59
|
+
assert('geofeatures.0.beaconType' in err.errors)
|
|
60
|
+
done()
|
|
61
|
+
})
|
|
62
|
+
})
|
|
63
|
+
})
|
|
64
|
+
})
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
let mongoose = require('mongoose')
|
|
2
|
+
|
|
3
|
+
mongoose.Promise = global.Promise
|
|
4
|
+
|
|
5
|
+
let ZoneModel = require('../../models/Zone')(mongoose)
|
|
6
|
+
let testCase = require('mocha').describe
|
|
7
|
+
let assertions = require('mocha').it
|
|
8
|
+
let chai = require('chai')
|
|
9
|
+
let assert = chai.assert
|
|
10
|
+
let mocha = require('mocha')
|
|
11
|
+
let beforeEach = mocha.beforeEach
|
|
12
|
+
|
|
13
|
+
let zone
|
|
14
|
+
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
zone = JSON.parse(JSON.stringify(require('./zone.data.json')))
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
testCase('Zone', () => {
|
|
20
|
+
testCase('Valid Zone ', () => {
|
|
21
|
+
assertions('should validate a valid zone ', (done) => {
|
|
22
|
+
let Zone = new ZoneModel(zone)
|
|
23
|
+
Zone.validate((err, res) => {
|
|
24
|
+
assert.notExists(res)
|
|
25
|
+
assert(err === null, 'err equals null')
|
|
26
|
+
done()
|
|
27
|
+
})
|
|
28
|
+
})
|
|
29
|
+
assertions('should instantiate a circle', (done) => {
|
|
30
|
+
zone.geofeatures = zone.geofeatures.filter(gf => gf.type.match(/^circle$/))
|
|
31
|
+
let Zone = new ZoneModel(zone)
|
|
32
|
+
Zone.validate((err, res) => {
|
|
33
|
+
assert.notExists(res)
|
|
34
|
+
assert(err === null, 'err equals null')
|
|
35
|
+
done()
|
|
36
|
+
})
|
|
37
|
+
})
|
|
38
|
+
assertions('should instantiate a bounding box', (done) => {
|
|
39
|
+
zone.geofeatures = zone.geofeatures.filter(gf => gf.type.match(/^boundingBox$/))
|
|
40
|
+
let Zone = new ZoneModel(zone)
|
|
41
|
+
Zone.validate((err, res) => {
|
|
42
|
+
assert.notExists(res)
|
|
43
|
+
assert(err === null, 'err equals null')
|
|
44
|
+
done()
|
|
45
|
+
})
|
|
46
|
+
})
|
|
47
|
+
assertions('should instantiate a polygon', (done) => {
|
|
48
|
+
zone.geofeatures = zone.geofeatures.filter(gf => gf.type.match(/^polygon$/))
|
|
49
|
+
let Zone = new ZoneModel(zone)
|
|
50
|
+
Zone.validate((err, res) => {
|
|
51
|
+
assert.notExists(res)
|
|
52
|
+
assert(err === null, 'err equals null')
|
|
53
|
+
done()
|
|
54
|
+
})
|
|
55
|
+
})
|
|
56
|
+
assertions('should instantiate a polyline', (done) => {
|
|
57
|
+
zone.geofeatures = zone.geofeatures.filter(gf => gf.type.match(/^polyline$/))
|
|
58
|
+
let Zone = new ZoneModel(zone)
|
|
59
|
+
Zone.validate((err, res) => {
|
|
60
|
+
assert.notExists(res)
|
|
61
|
+
assert(err === null, 'err equals null')
|
|
62
|
+
done()
|
|
63
|
+
})
|
|
64
|
+
})
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
testCase('Invalid Zone ', () => {
|
|
68
|
+
assertions('should throw an error when validating an invalid zone ', (done) => {
|
|
69
|
+
delete zone.name
|
|
70
|
+
let Zone = new ZoneModel(zone)
|
|
71
|
+
Zone.validate((err, res) => {
|
|
72
|
+
assert.exists(err, 'err object should exist')
|
|
73
|
+
assert.isObject(err)
|
|
74
|
+
done()
|
|
75
|
+
})
|
|
76
|
+
})
|
|
77
|
+
assertions('should throw an error when action is invalid', (done) => {
|
|
78
|
+
delete zone.actions[1].url
|
|
79
|
+
let Zone = new ZoneModel(zone)
|
|
80
|
+
Zone.validate((err, res) => {
|
|
81
|
+
assert.exists(err, 'err object should exist')
|
|
82
|
+
assert.isObject(err)
|
|
83
|
+
assert('actions.1.url' in err.errors, `errors should have a 'actions.1.url' property`)
|
|
84
|
+
done()
|
|
85
|
+
})
|
|
86
|
+
})
|
|
87
|
+
assertions('should throw an error when a filter is invalid', (done) => {
|
|
88
|
+
delete zone.filters[0].startDate
|
|
89
|
+
let Zone = new ZoneModel(zone)
|
|
90
|
+
Zone.validate((err, res) => {
|
|
91
|
+
assert.exists(err, 'err object should exist')
|
|
92
|
+
assert.isObject(err)
|
|
93
|
+
assert('filters.0.startDate' in err.errors, `errors should have a 'filters.0.startDate' property`)
|
|
94
|
+
done()
|
|
95
|
+
})
|
|
96
|
+
})
|
|
97
|
+
})
|
|
98
|
+
})
|
|
@@ -2,25 +2,24 @@
|
|
|
2
2
|
* Copyright : Bluedot Innovations.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
let mongoose = require('mongoose')
|
|
6
|
+
let Enums = require('@bluedot-innovation/enums')
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
let AdminPortalUser = mongoose.model('AdminPortalUser', new mongoose.Schema(
|
|
9
9
|
{
|
|
10
10
|
emailAddress: String,
|
|
11
11
|
password: String,
|
|
12
12
|
firstName: String,
|
|
13
13
|
lastName: String,
|
|
14
|
-
state: {type:String, default: Enums.StateEnum.active},
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
state: {type: String, default: Enums.StateEnum.active},
|
|
15
|
+
'creationTime': {type: Date, default: Date.now},
|
|
16
|
+
'dataSource': {type: String, select: false, default: 'AdminPortal'},
|
|
17
17
|
adminId: String,
|
|
18
18
|
secret: String
|
|
19
19
|
},
|
|
20
20
|
{
|
|
21
|
-
collection
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
);
|
|
21
|
+
collection: 'adminPortalUser'
|
|
22
|
+
})
|
|
23
|
+
)
|
|
25
24
|
|
|
26
|
-
module.exports = AdminPortalUser
|
|
25
|
+
module.exports = AdminPortalUser
|
package/models/AdminUser.js
CHANGED
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
* Copyright : Bluedot Innovations.
|
|
4
4
|
* Owner :
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
{ collection
|
|
9
|
-
))
|
|
10
|
-
|
|
6
|
+
let mongoose = require('mongoose')
|
|
7
|
+
let AdminUser = mongoose.model('AdminUser', new mongoose.Schema({},
|
|
8
|
+
{ collection: 'AdminUser' }
|
|
9
|
+
))
|
|
10
|
+
|
|
11
|
+
module.exports = AdminUser
|
package/models/Application.js
CHANGED
|
@@ -3,36 +3,37 @@
|
|
|
3
3
|
* Copyright : Bluedot Innovations.
|
|
4
4
|
* Owner :
|
|
5
5
|
*/
|
|
6
|
-
var mongoose = require('mongoose');
|
|
7
|
-
var Enums = require('@bluedot-innovation/enums');
|
|
8
|
-
Schema = mongoose.Schema;
|
|
9
6
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
7
|
+
let mongoose = require('mongoose')
|
|
8
|
+
let Enums = require('@bluedot-innovation/enums')
|
|
9
|
+
let Schema = mongoose.Schema
|
|
10
|
+
|
|
11
|
+
let ApplicationSchema = new mongoose.Schema({
|
|
12
|
+
_id: {type: String},
|
|
13
|
+
_class: {type: String, default: 'au.com.bluedot.application.model.client.Application'},
|
|
14
|
+
state: {type: String, default: Enums.StateEnum.active, select: false},
|
|
15
|
+
nextRuleUpdateInterval: {type: Number, select: false},
|
|
16
|
+
nextRuleUpdateIntervalFormatted: {type: String, required: true},
|
|
17
|
+
lastUpdateTime: {type: Date, select: false},
|
|
18
|
+
creationTime: {type: Date, select: false},
|
|
19
|
+
'administrator': {type: String, select: false},
|
|
20
|
+
enableDataAnonymisation: {type: Boolean, select: false},
|
|
21
|
+
apiKey: String,
|
|
22
|
+
dataSource: {type: String, select: false, default: 'openApi'},
|
|
23
|
+
name: {type: String},
|
|
24
|
+
packageName: {type: String},
|
|
25
|
+
customerId: String,
|
|
26
|
+
firebaseApiKey: String,
|
|
27
|
+
lastPushSync: Date,
|
|
28
|
+
webhook: {
|
|
29
|
+
url: String,
|
|
30
|
+
enabled: Boolean,
|
|
31
|
+
params: {}
|
|
33
32
|
},
|
|
34
|
-
{
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
configurationParameters: {type: Schema.Types.Mixed, default: null}
|
|
34
|
+
},
|
|
35
|
+
{collection: 'application'})
|
|
36
|
+
|
|
37
|
+
let Application = mongoose.model('Application', ApplicationSchema)
|
|
37
38
|
|
|
38
|
-
module.exports = Application
|
|
39
|
+
module.exports = Application
|
package/models/Beacon.js
CHANGED
|
@@ -1,36 +1,106 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
1
|
+
let mongoose = require('mongoose')
|
|
2
|
+
let StateEnum = require('@bluedot-innovation/enums').StateEnum
|
|
3
|
+
let Point = require('../schemas/Point')
|
|
4
|
+
let uuidv4 = require('uuid/v4')
|
|
5
|
+
|
|
6
|
+
let schema = {
|
|
7
|
+
guid: {type: String, default: uuidv4},
|
|
8
|
+
name: {type: String, required: [true, 'name is required. ']},
|
|
9
|
+
longitude: {
|
|
10
|
+
type: Number,
|
|
11
|
+
required: true,
|
|
12
|
+
validate: [{validator: validateLongitude, msg: 'Longitude is required (insert format here)'}]
|
|
13
|
+
},
|
|
14
|
+
latitude: {
|
|
15
|
+
type: Number,
|
|
16
|
+
required: true,
|
|
17
|
+
validate: [{validator: validateLatitude, msg: 'Latitude is required (insert format here)'}]
|
|
18
|
+
},
|
|
19
|
+
description: {type: String, default: ''},
|
|
20
|
+
lastUpdateTime: {type: Date},
|
|
21
|
+
state: {type: String, default: StateEnum.active},
|
|
22
|
+
major: {type: Number, validate: [{validator: validateMajorMinor, msg: 'Major needs to be within range(1-65535)'}]},
|
|
23
|
+
minor: {type: Number, validate: [{validator: validateMajorMinor, msg: 'Minor needs to be within range(1-65535)'}]},
|
|
24
|
+
txPower: {type: Number},
|
|
25
|
+
macAddress: {type: String},
|
|
26
|
+
proximityUUID: {type: String},
|
|
27
|
+
beaconType: {
|
|
28
|
+
type: String,
|
|
29
|
+
required: true,
|
|
30
|
+
validate: {
|
|
31
|
+
isAsync: true,
|
|
32
|
+
validator: validateBeaconType,
|
|
33
|
+
msg: 'Async validation. Not used'
|
|
34
|
+
}
|
|
29
35
|
},
|
|
30
|
-
{
|
|
31
|
-
|
|
36
|
+
location: {type: Point},
|
|
37
|
+
proximity: {type: String, default: 'Far'}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
let BeaconSchema = new mongoose.Schema(schema)
|
|
41
|
+
|
|
42
|
+
BeaconSchema.add({
|
|
43
|
+
type:
|
|
44
|
+
{type: String, required: true}
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
// mongoose validator helper plugin
|
|
48
|
+
BeaconSchema.post('validate', function (doc) {
|
|
49
|
+
console.debug('Beacon Schema post validate hook')
|
|
50
|
+
this.lastUpdateTime = Date.now()
|
|
51
|
+
Object.assign(this.errors || {}, this.errors || {}, this.customErrors)
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
function validateMajorMinor (v) {
|
|
55
|
+
'use strict'
|
|
56
|
+
return v >= 1 && v <= 65535
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function validateLatitude (longitude) {
|
|
60
|
+
'use strict'
|
|
61
|
+
let regex = new RegExp(/^[-+]?([1-8]?\d(\.\d+)?|90(\.0+)?)$/gi)
|
|
62
|
+
return regex.test(longitude)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function validateLongitude (latitude) {
|
|
66
|
+
'use strict'
|
|
67
|
+
let regex = new RegExp(/^[-+]?(180(\.0+)?|((1[0-7]\d)|([1-9]?\d))(\.\d+)?)$/gi)
|
|
68
|
+
return regex.test(latitude)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function validateBeaconType (v, cb) {
|
|
72
|
+
'use strict'
|
|
73
|
+
let magicCallback = cb
|
|
74
|
+
const beaconType = v
|
|
75
|
+
const minor = this.minor
|
|
76
|
+
const major = this.major
|
|
77
|
+
const macAddress = this.macAddress
|
|
78
|
+
const txPower = this.txPower
|
|
79
|
+
|
|
80
|
+
let androidRegex = new RegExp(/(android)/ig)
|
|
81
|
+
let iosRegex = new RegExp(/(ios)/ig)
|
|
82
|
+
let bothRegex = new RegExp(/(both)/ig)
|
|
32
83
|
|
|
33
|
-
|
|
84
|
+
if (androidRegex.test(beaconType)) {
|
|
85
|
+
magicCallback((!!macAddress && !!txPower), 'Beacon type "Android" must have both mac address and tx power values')
|
|
86
|
+
} else if (iosRegex.test(beaconType)) {
|
|
87
|
+
magicCallback((!!minor && !!major), 'Beacon type "IOS" must have both minor and major values')
|
|
88
|
+
} else if (bothRegex.test(beaconType)) {
|
|
89
|
+
magicCallback((!!minor && !!major && !!txPower && !!macAddress), 'Beacon type "Both" must have all of minor, major, tx power, and mac address values')
|
|
90
|
+
} else {
|
|
91
|
+
magicCallback(true)
|
|
92
|
+
}
|
|
93
|
+
}
|
|
34
94
|
|
|
35
|
-
|
|
95
|
+
// optional mongoose
|
|
96
|
+
module.exports = (mongooseInstance) => {
|
|
97
|
+
let Beacon
|
|
98
|
+
if (mongooseInstance) {
|
|
99
|
+
Beacon = mongooseInstance.model('Beacon', BeaconSchema)
|
|
100
|
+
} else {
|
|
101
|
+
Beacon = mongoose.model('Beacon', BeaconSchema)
|
|
102
|
+
}
|
|
36
103
|
|
|
104
|
+
return Beacon
|
|
105
|
+
}
|
|
106
|
+
module.exports.beaconSchema = schema
|
package/models/BeaconFilter.js
CHANGED
|
@@ -3,21 +3,39 @@
|
|
|
3
3
|
* Copyright : Bluedot Innovations.
|
|
4
4
|
* Owner :
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
|
-
Schema = mongoose.Schema;
|
|
6
|
+
let mongoose = require('mongoose')
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
{
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
let schema = {
|
|
9
|
+
'_class': {type: String, default: 'au.com.bluedot.application.spring.filter.spatial.BeaconFilter'},
|
|
10
|
+
'beacon': {},
|
|
11
|
+
'guid': String,
|
|
12
|
+
'type': {type: String, default: 'beacon'}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
let BeaconFilterSchema = new mongoose.Schema(
|
|
16
|
+
schema,
|
|
16
17
|
{
|
|
17
18
|
_id: false
|
|
18
19
|
}
|
|
19
|
-
)
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
BeaconFilterSchema.add({
|
|
23
|
+
type:
|
|
24
|
+
{type: String, required: true}
|
|
25
|
+
})
|
|
20
26
|
|
|
21
|
-
|
|
27
|
+
let BeaconFilter = mongoose.model('BeaconFilter', BeaconFilterSchema)
|
|
28
|
+
|
|
29
|
+
// optional mongoose
|
|
30
|
+
module.exports = (mongooseInstance) => {
|
|
31
|
+
let BeaconFilter
|
|
32
|
+
if (mongooseInstance) {
|
|
33
|
+
BeaconFilter = mongooseInstance.model('BeaconFilter', BeaconFilterSchema)
|
|
34
|
+
} else {
|
|
35
|
+
BeaconFilter = mongoose.model('BeaconFilter', BeaconFilterSchema)
|
|
36
|
+
}
|
|
22
37
|
|
|
23
|
-
|
|
38
|
+
return BeaconFilter
|
|
39
|
+
}
|
|
40
|
+
module.exports = BeaconFilter
|
|
41
|
+
module.exports.beaconFilterChema = schema
|