@bluedot-innovation/models 2.0.0-alpha.2 → 2.0.0-alpha.5
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 +41 -0
- package/Models.js +8 -8
- package/README.MD +32 -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/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__/zone/beacon.spec.js +95 -0
- package/__tests__/zone/boundingBox.spec.js +61 -0
- package/__tests__/zone/circle.spec.js +71 -0
- package/__tests__/zone/data/beacon.data.json +12 -0
- package/__tests__/zone/data/boundingBox.data.json +12 -0
- package/__tests__/zone/data/polygon.data.json +46 -0
- package/__tests__/zone/data/polyline.data.json +46 -0
- package/__tests__/zone/data/zone-with-invalid-circle.json +34 -0
- package/__tests__/zone/data/zone.data.json +154 -0
- package/__tests__/zone/polygon.spec.js +61 -0
- package/__tests__/zone/polyline.spec.js +61 -0
- package/__tests__/zone/rules/beacon.rules.json +13 -0
- package/__tests__/zone/rules/boundingBox.rules.json +3 -0
- package/__tests__/zone/rules/circle.rules.json +3 -0
- package/__tests__/zone/rules/polygon.rules.json +3 -0
- package/__tests__/zone/rules/polyline.rules.json +3 -0
- package/__tests__/zone/zone.spec.js +101 -0
- package/models/AdminPortalUser.js +10 -11
- package/models/AdminUser.js +6 -5
- package/models/Application.js +31 -30
- package/models/Beacon.js +93 -78
- package/models/BeaconFilter.js +9 -10
- package/models/BearingFilter.js +38 -23
- package/models/BoundingBox.js +28 -20
- package/models/CalendarDateRangeFilter.js +28 -20
- package/models/Circle.js +28 -21
- 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 +28 -0
- package/models/DeviceRulesRequest.js +27 -28
- package/models/Fence.js +12 -13
- package/models/GeoFence.js +12 -14
- package/models/Geofeature.js +18 -18
- package/models/MessageAction.js +26 -18
- 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 +23 -15
- package/models/Polygon.js +26 -19
- package/models/Polyline.js +25 -19
- package/models/RuleRequestAggregation.js +14 -15
- package/models/SimpleCheckInZone.js +21 -21
- package/models/SingleUseToken.js +7 -8
- package/models/SpeedFilter.js +31 -19
- 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 +27 -18
- package/models/UrlAction.js +45 -0
- package/models/Zone.js +191 -266
- package/models/ZoneUIState.js +18 -18
- package/package.json +16 -6
- package/schemas/Point.js +10 -13
- package/__tests__/zone/checkActions.js +0 -62
- package/__tests__/zone/checkBearingFitler.js +0 -46
- package/__tests__/zone/checkBoundingBox.js +0 -42
- package/__tests__/zone/checkCalendarDateRangeFilterFitler.js +0 -46
- package/__tests__/zone/checkCircle.js +0 -39
- package/__tests__/zone/checkPercentageCrossedFitler.js +0 -46
- package/__tests__/zone/checkPolygon.js +0 -76
- package/__tests__/zone/checkPolyline.js +0 -76
- package/__tests__/zone/checkSpeedFitler.js +0 -46
- package/__tests__/zone/checkTimeOfDayRangeFitler.js +0 -46
- package/models/URLAction.js +0 -34
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
let mongoose = require('mongoose')
|
|
2
|
+
|
|
3
|
+
mongoose.Promise = global.Promise
|
|
4
|
+
|
|
5
|
+
let PolylineModel = require('../../models/Polyline')(mongoose)
|
|
6
|
+
let testCase = require('mocha').describe
|
|
7
|
+
let assertions = require('mocha').it
|
|
8
|
+
let chai = require('chai')
|
|
9
|
+
|
|
10
|
+
let assert = chai.assert
|
|
11
|
+
let mocha = require('mocha')
|
|
12
|
+
let beforeEach = mocha.beforeEach
|
|
13
|
+
|
|
14
|
+
let rules = require('./rules/polyline.rules.json')
|
|
15
|
+
|
|
16
|
+
let polyline
|
|
17
|
+
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
polyline = JSON.parse(JSON.stringify(require('./data/polyline.data.json')))
|
|
20
|
+
})
|
|
21
|
+
testCase('Polyline', () => {
|
|
22
|
+
testCase('Valid Polyline', () => {
|
|
23
|
+
assertions('should validate a valid polyline ', (done) => {
|
|
24
|
+
let Polyline = new PolylineModel(polyline)
|
|
25
|
+
Polyline.validate((err, res) => {
|
|
26
|
+
assert.notExists(res)
|
|
27
|
+
assert(err === null, 'err should equals null')
|
|
28
|
+
done()
|
|
29
|
+
})
|
|
30
|
+
})
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
testCase('Invalid Polyline', () => {
|
|
34
|
+
assertions('should not validate a polyline with invalid polyline', (done) => {
|
|
35
|
+
delete polyline[rules.requiredFields[0]]
|
|
36
|
+
let Polyline = new PolylineModel(polyline)
|
|
37
|
+
Polyline.validate((err, res) => {
|
|
38
|
+
assert.exists(err, 'err object should exist')
|
|
39
|
+
assert.isObject(err)
|
|
40
|
+
done()
|
|
41
|
+
})
|
|
42
|
+
})
|
|
43
|
+
testCase('check each required property of the model and validate that it is present', () => {
|
|
44
|
+
let requiredFields = rules.requiredFields
|
|
45
|
+
requiredFields.map((i) => {
|
|
46
|
+
assertions(`should throw an error with property '${i}' if '${i}' is not present`, (done) => {
|
|
47
|
+
// delete i from geofeatures' polyline child
|
|
48
|
+
delete polyline[i]
|
|
49
|
+
let Polyline = new PolylineModel(polyline)
|
|
50
|
+
Polyline.validate((err, res) => {
|
|
51
|
+
assert.notExists(res)
|
|
52
|
+
assert.exists(err, 'err object should exist')
|
|
53
|
+
assert.isObject(err)
|
|
54
|
+
assert.nestedProperty(err, `errors.${i}`, 'error should have a radius property')
|
|
55
|
+
done()
|
|
56
|
+
})
|
|
57
|
+
})
|
|
58
|
+
})
|
|
59
|
+
})
|
|
60
|
+
})
|
|
61
|
+
})
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"requiredFields":["name", "longitude", "latitude", "beaconType"],
|
|
3
|
+
"dependentRequiredFields": [
|
|
4
|
+
{
|
|
5
|
+
"property": "beaconType",
|
|
6
|
+
"pairings": [
|
|
7
|
+
{"value": "ios", "requiredFields": ["major", "minor"]},
|
|
8
|
+
{"value": "android", "requiredFields": ["txPower", "macAddress"]},
|
|
9
|
+
{"value": "both", "requiredFields": ["major", "minor", "txPower", "macAddress"]}
|
|
10
|
+
]
|
|
11
|
+
}
|
|
12
|
+
]
|
|
13
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
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
|
+
let invalidZone
|
|
15
|
+
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
zone = JSON.parse(JSON.stringify(require('./data/zone.data.json')))
|
|
18
|
+
invalidZone = JSON.parse(JSON.stringify(require('./data/zone-with-invalid-circle.json')))
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
testCase('Zone', () => {
|
|
22
|
+
testCase('Valid Zone ', () => {
|
|
23
|
+
assertions('should validate a valid zone ', (done) => {
|
|
24
|
+
let Zone = new ZoneModel(zone)
|
|
25
|
+
Zone.validate((err, res) => {
|
|
26
|
+
assert.notExists(res)
|
|
27
|
+
assert(err === null, 'err equals null')
|
|
28
|
+
done()
|
|
29
|
+
})
|
|
30
|
+
})
|
|
31
|
+
assertions('should instantiate a circle', (done) => {
|
|
32
|
+
zone.geofeatures = zone.geofeatures.filter(gf => gf.type.match(/^circle$/))
|
|
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
|
+
assertions('should instantiate a bounding box', (done) => {
|
|
41
|
+
zone.geofeatures = zone.geofeatures.filter(gf => gf.type.match(/^boundingBox$/))
|
|
42
|
+
let Zone = new ZoneModel(zone)
|
|
43
|
+
Zone.validate((err, res) => {
|
|
44
|
+
assert.notExists(res)
|
|
45
|
+
assert(err === null, 'err equals null')
|
|
46
|
+
done()
|
|
47
|
+
})
|
|
48
|
+
})
|
|
49
|
+
assertions('should instantiate a polygon', (done) => {
|
|
50
|
+
zone.geofeatures = zone.geofeatures.filter(gf => gf.type.match(/^polygon$/))
|
|
51
|
+
let Zone = new ZoneModel(zone)
|
|
52
|
+
Zone.validate((err, res) => {
|
|
53
|
+
assert.notExists(res)
|
|
54
|
+
assert(err === null, 'err equals null')
|
|
55
|
+
done()
|
|
56
|
+
})
|
|
57
|
+
})
|
|
58
|
+
assertions('should instantiate a polyline', (done) => {
|
|
59
|
+
zone.geofeatures = zone.geofeatures.filter(gf => gf.type.match(/^polyline$/))
|
|
60
|
+
let Zone = new ZoneModel(zone)
|
|
61
|
+
Zone.validate((err, res) => {
|
|
62
|
+
assert.notExists(res)
|
|
63
|
+
assert(err === null, 'err equals null')
|
|
64
|
+
done()
|
|
65
|
+
})
|
|
66
|
+
})
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
testCase('Invalid Zone ', () => {
|
|
70
|
+
assertions('should throw an error when validating an invalid zone ', (done) => {
|
|
71
|
+
let Zone = new ZoneModel(invalidZone)
|
|
72
|
+
Zone.validate((err, res) => {
|
|
73
|
+
assert.exists(err, 'err object should exist')
|
|
74
|
+
assert.isObject(err)
|
|
75
|
+
done()
|
|
76
|
+
})
|
|
77
|
+
})
|
|
78
|
+
assertions('should throw an error when action is invalid', (done) => {
|
|
79
|
+
delete zone.actions[1].url
|
|
80
|
+
let Zone = new ZoneModel(zone)
|
|
81
|
+
Zone.validate((err, res) => {
|
|
82
|
+
assert.exists(err, 'err object should exist')
|
|
83
|
+
assert.isObject(err)
|
|
84
|
+
assert.nestedProperty(err, `errors.url`, 'error should have a url property')
|
|
85
|
+
assert.notNestedProperty(err, `errors.geofeatures`, 'error should have a url property')
|
|
86
|
+
done()
|
|
87
|
+
})
|
|
88
|
+
})
|
|
89
|
+
assertions('should throw an error when a filter is invalid', (done) => {
|
|
90
|
+
delete zone.filters[0].startDate
|
|
91
|
+
let Zone = new ZoneModel(zone)
|
|
92
|
+
Zone.validate((err, res) => {
|
|
93
|
+
assert.exists(err, 'err object should exist')
|
|
94
|
+
assert.isObject(err)
|
|
95
|
+
assert.nestedProperty(err, `errors.calendarDateRange`, 'error should have a url property')
|
|
96
|
+
assert.notNestedProperty(err, `errors.geofeatures`, 'error should have a url property')
|
|
97
|
+
done()
|
|
98
|
+
})
|
|
99
|
+
})
|
|
100
|
+
})
|
|
101
|
+
})
|
|
@@ -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,93 +1,108 @@
|
|
|
1
|
-
let mongoose
|
|
2
|
-
let StateEnum
|
|
3
|
-
let uuidv4
|
|
4
|
-
let Point
|
|
1
|
+
let mongoose = require('mongoose')
|
|
2
|
+
let StateEnum = require('@bluedot-innovation/enums').StateEnum
|
|
3
|
+
let uuidv4 = require('uuid/v4')
|
|
4
|
+
let Point = require('../schemas/Point')
|
|
5
5
|
|
|
6
6
|
let BeaconSchema = new mongoose.Schema({
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
txPower : { type: Number, default: 1 },
|
|
17
|
-
macAddress : { type: String },
|
|
18
|
-
proximityUUID : { type: String },
|
|
19
|
-
beaconType : { type: String },
|
|
20
|
-
location : { type: Point },
|
|
21
|
-
proximity : { type: String, default: 'Far', validate: validateBeacons }
|
|
7
|
+
customerApiKey: {type: String, validate: [{validator: validateKey, msg: 'Customer API Key is required'}]},
|
|
8
|
+
apiKey: {type: String, validate: [{validator: validateKey, msg: 'API Key is required'}]},
|
|
9
|
+
guid: {type: String, default: uuidv4},
|
|
10
|
+
type: {type: String},
|
|
11
|
+
name: {type: String, required: [true, 'name is required. ']},
|
|
12
|
+
longitude: {
|
|
13
|
+
type: Number,
|
|
14
|
+
required: true,
|
|
15
|
+
validate: [{validator: validateLongitude, msg: 'Longitude is required (insert format here)'}]
|
|
22
16
|
},
|
|
23
|
-
{
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
17
|
+
latitude: {
|
|
18
|
+
type: Number,
|
|
19
|
+
required: true,
|
|
20
|
+
validate: [{validator: validateLatitude, msg: 'Latitude is required (insert format here)'}]
|
|
21
|
+
},
|
|
22
|
+
description: {type: String, default: ''},
|
|
23
|
+
lastUpdateTime: {type: Date},
|
|
24
|
+
state: {type: String, default: StateEnum.active},
|
|
25
|
+
major: {type: Number, validate: [{validator: validateMajorMinor, msg: 'Major needs to be within range(1-65535)'}]},
|
|
26
|
+
minor: {type: Number, validate: [{validator: validateMajorMinor, msg: 'Minor needs to be within range(1-65535)'}]},
|
|
27
|
+
txPower: {type: Number},
|
|
28
|
+
macAddress: {type: String},
|
|
29
|
+
proximityUUID: {type: String},
|
|
30
|
+
beaconType: {
|
|
31
|
+
type: String,
|
|
32
|
+
required: true,
|
|
33
|
+
validate: {
|
|
34
|
+
isAsync: true,
|
|
35
|
+
validator: validateBeaconType,
|
|
36
|
+
msg: 'Async validation. Not used'
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
location: {type: Point},
|
|
40
|
+
proximity: {type: String, default: 'Far'}
|
|
41
|
+
})
|
|
28
42
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
//let proximity = this.proximity;
|
|
43
|
+
// mongoose validator helper plugin
|
|
44
|
+
BeaconSchema.post('validate', function (doc) {
|
|
45
|
+
console.debug('Beacon Schema post validate hook')
|
|
46
|
+
this.lastUpdateTime = Date.now()
|
|
47
|
+
Object.assign(this.errors || {}, this.errors || {}, this.customErrors)
|
|
48
|
+
})
|
|
36
49
|
|
|
37
|
-
|
|
50
|
+
function validateMajorMinor (v) {
|
|
51
|
+
'use strict'
|
|
52
|
+
return v >= 1 && v <= 65535
|
|
53
|
+
}
|
|
38
54
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
errorList = errorList + "Beacon should have a proximityUUID field. ";
|
|
45
|
-
}
|
|
55
|
+
function validateLatitude (longitude) {
|
|
56
|
+
'use strict'
|
|
57
|
+
let regex = new RegExp(/^[-+]?([1-8]?\d(\.\d+)?|90(\.0+)?)$/gi)
|
|
58
|
+
return regex.test(longitude)
|
|
59
|
+
}
|
|
46
60
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
errorList = errorList + proximityUUID + ' is not a valid ID.';
|
|
53
|
-
}
|
|
54
|
-
}
|
|
61
|
+
function validateLongitude (latitude) {
|
|
62
|
+
'use strict'
|
|
63
|
+
let regex = new RegExp(/^[-+]?(180(\.0+)?|((1[0-7]\d)|([1-9]?\d))(\.\d+)?)$/gi)
|
|
64
|
+
return regex.test(latitude)
|
|
65
|
+
}
|
|
55
66
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
67
|
+
function validateBeaconType (v, cb) {
|
|
68
|
+
'use strict'
|
|
69
|
+
let magicCallback = cb
|
|
70
|
+
const beaconType = v
|
|
71
|
+
const minor = this.minor
|
|
72
|
+
const major = this.major
|
|
73
|
+
const macAddress = this.macAddress
|
|
74
|
+
const txPower = this.txPower
|
|
61
75
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
errorList = errorList + "Beacon minor should be within the range 0 to 65535. ";
|
|
66
|
-
}
|
|
67
|
-
}
|
|
76
|
+
let androidRegex = new RegExp(/(android)/ig)
|
|
77
|
+
let iosRegex = new RegExp(/(ios)/ig)
|
|
78
|
+
let bothRegex = new RegExp(/(both)/ig)
|
|
68
79
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
}
|
|
80
|
+
if (androidRegex.test(beaconType)) {
|
|
81
|
+
magicCallback((!!macAddress && !!txPower), 'Beacon type "Android" must have both mac address and tx power values')
|
|
82
|
+
} else if (iosRegex.test(beaconType)) {
|
|
83
|
+
magicCallback((!!minor && !!major), 'Beacon type "IOS" must have both minor and major values')
|
|
84
|
+
} else if (bothRegex.test(beaconType)) {
|
|
85
|
+
magicCallback((!!minor && !!major && !!txPower && !!macAddress), 'Beacon type "Both" must have all of minor, major, tx power, and mac address values')
|
|
86
|
+
} else {
|
|
87
|
+
magicCallback(true)
|
|
79
88
|
}
|
|
89
|
+
}
|
|
80
90
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
console.log(errorList);
|
|
87
|
-
throw new Error(errorList);
|
|
88
|
-
}
|
|
91
|
+
function validateKey (apiKey) {
|
|
92
|
+
// todo beacon can be added via zone or individually. so decide whether we need to validate apikey/ customerapikey, or log in function will solve that
|
|
93
|
+
'use strict'
|
|
94
|
+
let regex = new RegExp(/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i)
|
|
95
|
+
return !!regex.test(apiKey)
|
|
89
96
|
}
|
|
90
97
|
|
|
91
|
-
|
|
98
|
+
// optional mongoose
|
|
99
|
+
module.exports = (mongooseInstance) => {
|
|
100
|
+
let Beacon
|
|
101
|
+
if (mongooseInstance) {
|
|
102
|
+
Beacon = mongooseInstance.model('Beacon', BeaconSchema)
|
|
103
|
+
} else {
|
|
104
|
+
Beacon = mongoose.model('Beacon', BeaconSchema)
|
|
105
|
+
}
|
|
92
106
|
|
|
93
|
-
|
|
107
|
+
return Beacon
|
|
108
|
+
}
|
package/models/BeaconFilter.js
CHANGED
|
@@ -3,21 +3,20 @@
|
|
|
3
3
|
* Copyright : Bluedot Innovations.
|
|
4
4
|
* Owner :
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
|
-
Schema = mongoose.Schema;
|
|
6
|
+
let mongoose = require('mongoose')
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
let BeaconFilterSchema = new mongoose.Schema(
|
|
10
9
|
{
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
'_class': {type: String, default: 'au.com.bluedot.application.spring.filter.spatial.BeaconFilter'},
|
|
11
|
+
'beacon': {},
|
|
12
|
+
'guid': String,
|
|
13
|
+
'type': {type: String, default: 'beacon'}
|
|
15
14
|
},
|
|
16
15
|
{
|
|
17
16
|
_id: false
|
|
18
17
|
}
|
|
19
|
-
)
|
|
18
|
+
)
|
|
20
19
|
|
|
21
|
-
|
|
20
|
+
let BeaconFilter = mongoose.model('BeaconFilter', BeaconFilterSchema)
|
|
22
21
|
|
|
23
|
-
module.exports = BeaconFilter
|
|
22
|
+
module.exports = BeaconFilter
|
package/models/BearingFilter.js
CHANGED
|
@@ -1,36 +1,51 @@
|
|
|
1
|
-
let mongoose
|
|
2
|
-
let uuidv4
|
|
1
|
+
let mongoose = require('mongoose')
|
|
2
|
+
let uuidv4 = require('uuid/v4')
|
|
3
3
|
|
|
4
|
-
let
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
let BearingFilterSchema = new mongoose.Schema({
|
|
5
|
+
guid: {type: String, default: uuidv4},
|
|
6
|
+
type: {type: String, required: true},
|
|
7
|
+
fromAngle: {type: Number, required: [true, 'fromAngle is required. '], min: 0, max: 359},
|
|
8
|
+
toAngle: {type: Number, required: true, min: 0, max: 359, validate: {validator: validateAngles, msg: 'default error message'}}
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
_id: false,
|
|
12
|
+
versionKey: false
|
|
13
|
+
}
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
function validateAngles (toAngle, cb) {
|
|
17
|
+
let magicCallback = cb
|
|
18
|
+
let fromAngle = this.fromAngle
|
|
19
|
+
|
|
20
|
+
if (!toAngle && toAngle !== 0) {
|
|
21
|
+
return magicCallback(false, 'toAngle is required')
|
|
13
22
|
}
|
|
14
|
-
);
|
|
15
23
|
|
|
16
|
-
|
|
17
|
-
|
|
24
|
+
if (toAngle === fromAngle) {
|
|
25
|
+
return magicCallback(false, 'fromAngle and toAngle cannot be the same')
|
|
26
|
+
}
|
|
18
27
|
|
|
19
28
|
if (fromAngle > toAngle) {
|
|
20
29
|
if ((fromAngle - toAngle) <= 270) {
|
|
21
|
-
|
|
30
|
+
return magicCallback(false, 'From Angle and To Angle must best separated by at least 90 degrees in both directions')
|
|
22
31
|
}
|
|
23
|
-
}
|
|
32
|
+
}
|
|
33
|
+
if (toAngle > fromAngle) {
|
|
24
34
|
if (((toAngle - fromAngle) < 90) || (((toAngle - fromAngle) > 270))) {
|
|
25
|
-
|
|
35
|
+
return magicCallback(false, 'From Angle and To Angle must best separated by at least 90 degrees in both directions')
|
|
26
36
|
}
|
|
27
|
-
} else {
|
|
28
|
-
throw new Error("fromAngle and toAngle cannot be same. ");
|
|
29
37
|
}
|
|
30
|
-
|
|
38
|
+
magicCallback(true)
|
|
31
39
|
}
|
|
32
40
|
|
|
41
|
+
// optional mongoose
|
|
42
|
+
module.exports = (mongooseInstance) => {
|
|
43
|
+
let BearingFilter
|
|
44
|
+
if (mongooseInstance) {
|
|
45
|
+
BearingFilter = mongooseInstance.model('BearingFilter', BearingFilterSchema)
|
|
46
|
+
} else {
|
|
47
|
+
BearingFilter = mongoose.model('BearingFilter', BearingFilterSchema)
|
|
48
|
+
}
|
|
33
49
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
module.exports = Bearing;
|
|
50
|
+
return BearingFilter
|
|
51
|
+
}
|