@bluedot-innovation/models 4.0.0 → 5.0.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/.eslintrc.js +42 -0
- package/.gitlab-ci.yml +44 -0
- package/CHANGELOG.md +156 -0
- package/Models.js +55 -10
- package/README.MD +36 -0
- package/__tests__/account/account.data.json +12 -0
- package/__tests__/account/account.rules.js +8 -0
- package/__tests__/account/account.spec.js +83 -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 +73 -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 +74 -0
- package/__tests__/beacon/beacon.data.json +15 -0
- package/__tests__/beacon/beacon.rules.json +13 -0
- package/__tests__/beacon/beacon.spec.js +104 -0
- package/__tests__/condition/beacon/beaconFilter.data.json +1 -0
- package/__tests__/condition/beacon/beaconFilter.rules.json +3 -0
- package/__tests__/condition/beacon/beaconFilter.spec.js +1 -0
- package/__tests__/condition/dayRange/dayRange.data.json +5 -0
- package/__tests__/condition/dayRange/dayRange.rules.json +3 -0
- package/__tests__/condition/dayRange/dayRange.spec.js +95 -0
- package/__tests__/condition/percentageCrossed/travelPath.data.json +5 -0
- package/__tests__/condition/percentageCrossed/travelPath.rules.json +3 -0
- package/__tests__/condition/percentageCrossed/travelPath.spec.js +72 -0
- package/__tests__/condition/speed/speed.data.json +5 -0
- package/__tests__/condition/speed/speed.rules.json +3 -0
- package/__tests__/condition/speed/speed.spec.js +92 -0
- package/__tests__/condition/timeActive/timeActive.data.json +5 -0
- package/__tests__/condition/timeActive/timeActive.rules.json +14 -0
- package/__tests__/condition/timeActive/timeActive.spec.js +103 -0
- package/__tests__/condition/travelDirection/travelDirection.data.json +5 -0
- package/__tests__/condition/travelDirection/travelDirection.rules.json +3 -0
- package/__tests__/condition/travelDirection/travelDirection.spec.js +141 -0
- package/__tests__/dailyStats/checkDailyStats.js +31 -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 +87 -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 +71 -0
- package/__tests__/geofeature/geoline/geoline.data.json +46 -0
- package/__tests__/geofeature/geoline/geoline.rules.json +3 -0
- package/__tests__/geofeature/geoline/geoline.spec.js +70 -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 +132 -0
- package/__tests__/geofeature/zoneBeacon/zoneBeacon.data.json +16 -0
- package/__tests__/geofeature/zoneBeacon/zoneBeacon.rules.json +13 -0
- package/__tests__/geofeature/zoneBeacon/zoneBeacon.spec.js +71 -0
- package/__tests__/monthlyStats/monthlyStats.data.json +29 -0
- package/__tests__/monthlyStats/monthlyStats.spec.js +75 -0
- package/__tests__/project/project.data.json +18 -0
- package/__tests__/project/project.remote.config.json +122 -0
- package/__tests__/project/project.rules.json +9 -0
- package/__tests__/project/project.spec.js +100 -0
- package/__tests__/ruleRequestAggregation/ruleRequestAggregation.data.json +8 -0
- package/__tests__/ruleRequestAggregation/ruleRequestAggregation.spec.js +78 -0
- package/__tests__/setup.js +7 -0
- package/__tests__/user/user.data.js +19 -0
- package/__tests__/user/user.rules.js +8 -0
- package/__tests__/user/user.spec.js +130 -0
- package/__tests__/utils/utils.spec.js +26 -0
- package/__tests__/zone/zone.action.spec.js +50 -0
- package/__tests__/zone/zone.condition.spec.js +94 -0
- package/__tests__/zone/zone.data.json +157 -0
- package/__tests__/zone/zone.geofeatures.spec.js +75 -0
- package/__tests__/zone/zone.spec.js +140 -0
- package/constants/errorMessages.js +2 -0
- package/helpers.js +117 -0
- package/models/Account.js +50 -0
- package/models/AdminPortalUser.js +10 -11
- package/models/Beacon.js +84 -32
- package/models/Contract.js +37 -38
- 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/MessageAction.js +26 -26
- package/models/MonthlyStats.js +35 -19
- 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/Project.js +63 -0
- package/models/RuleRequestAggregation.js +33 -17
- package/models/SingleUseToken.js +7 -8
- 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/UrlAction.js +37 -0
- package/models/User.js +61 -0
- package/models/Zone.js +126 -0
- package/models/ZoneUIState.js +18 -18
- package/models/conditions/DayRange.js +44 -0
- package/models/conditions/Speed.js +42 -0
- package/models/conditions/TimeActive.js +50 -0
- package/models/conditions/TravelDirection.js +59 -0
- package/models/conditions/TravelPath.js +36 -0
- package/models/geofeatures/BoundingBox.js +44 -0
- package/models/geofeatures/Circle.js +39 -0
- package/models/geofeatures/Geoline.js +34 -0
- package/models/geofeatures/Polygon.js +45 -0
- package/models/geofeatures/ZoneBeacon.js +28 -0
- package/package.json +30 -6
- package/schemas/AccuracySuppression.js +14 -0
- package/schemas/AndroidConfig.js +35 -0
- package/schemas/IosConfig.js +38 -0
- package/schemas/MultiLineStringGeometry.js +14 -0
- package/schemas/Point.js +13 -0
- package/schemas/PointGeometry.js +14 -0
- package/schemas/PolygonGeometry.js +14 -0
- package/schemas/ProjectPermission.js +21 -0
- package/schemas/StarvationDetection.js +11 -0
- package/schemas/Telemetry.js +36 -0
- package/schemas/Webhook.js +22 -0
- package/utils/index.js +39 -0
- package/utils/validators.js +6 -0
- package/validators/checkDistanceBetweenVertices.js +21 -0
- package/yarn.lock +2796 -0
- package/models/AdminUser.js +0 -10
- package/models/Application.js +0 -38
- package/models/ApplicationNotificationAction.js +0 -30
- package/models/ApplicationUsage.js +0 -11
- package/models/BeaconFilter.js +0 -23
- package/models/BearingFilter.js +0 -19
- package/models/BoundingBox.js +0 -17
- package/models/Circle.js +0 -21
- package/models/ConfigurationParameters.js +0 -20
- package/models/Customer.js +0 -38
- package/models/DateRangeFilter.js +0 -20
- package/models/Fence.js +0 -21
- 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/GeoFence.js +0 -23
- package/models/Geofeature.js +0 -26
- package/models/PercentageCrossedFilter.js +0 -19
- package/models/Point.js +0 -20
- package/models/Polygon.js +0 -18
- package/models/Polyline.js +0 -18
- package/models/PropertyMapping.js +0 -17
- package/models/Reference.js +0 -19
- package/models/SequenceFilter.js +0 -18
- package/models/SimpleCheckInZone.js +0 -29
- package/models/SoundAction.js +0 -28
- package/models/SpeedFilter.js +0 -19
- package/models/TimeOfDayRangeFilter.js +0 -19
- package/models/URLAction.js +0 -31
- package/models/VibrationAction.js +0 -28
- package/models/property.js +0 -25
- package/package-lock.json.bak +0 -170
package/helpers.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
var equal = require('deep-equal');
|
|
2
|
+
const { clean } = require('./utils');
|
|
3
|
+
|
|
4
|
+
let helpers = {}
|
|
5
|
+
|
|
6
|
+
helpers.validateUUIDv4 = function (id) {
|
|
7
|
+
const expression = '^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$'
|
|
8
|
+
const regex = new RegExp(expression, 'i')
|
|
9
|
+
return regex.test(id)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
helpers.validateEmail = function (value) {
|
|
13
|
+
const regex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
|
|
14
|
+
return regex.test(value);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
helpers.threeOrMoreVertices = function(vertices) {
|
|
18
|
+
return vertices.length >= 3;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
helpers.validateCustomData = function (data) {
|
|
22
|
+
const customDataKeys = Object.keys(data)
|
|
23
|
+
let hasValidationErrors = false
|
|
24
|
+
|
|
25
|
+
customDataKeys.forEach(key => {
|
|
26
|
+
const alphaNumericValidation = new RegExp(/^[\w\s]+$/)
|
|
27
|
+
if(!alphaNumericValidation.test(key)){
|
|
28
|
+
hasValidationErrors = true
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
const checkDuplicateKeys = [...new Set(customDataKeys)]
|
|
33
|
+
if(customDataKeys.length > checkDuplicateKeys.length) {
|
|
34
|
+
hasValidationErrors = true
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return !hasValidationErrors
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
helpers.checkDuplicateKeys = function (data) {
|
|
41
|
+
const customDataKeys = Object.keys(data)
|
|
42
|
+
let hasValidationErrors = false
|
|
43
|
+
|
|
44
|
+
const duplicateKeys = [...new Set(customDataKeys)]
|
|
45
|
+
if(customDataKeys.length > duplicateKeys.length) {
|
|
46
|
+
hasValidationErrors = true
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return !hasValidationErrors
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
helpers.checkIsDifferent = function(propertyName) {
|
|
53
|
+
return function(propertyA) {
|
|
54
|
+
const propertyB = this[propertyName];
|
|
55
|
+
|
|
56
|
+
if (equal(clean(propertyA), clean(propertyB))) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return true
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
helpers.checkConditionsSuitableForBeacon = function(zone, next) {
|
|
65
|
+
let hasBeacons = false;
|
|
66
|
+
if( zone.geofeatures && zone.geofeatures.length ) {
|
|
67
|
+
for( let geofeature of zone.geofeatures ) {
|
|
68
|
+
if( geofeature.type === "beacon" ) {
|
|
69
|
+
hasBeacons = true;
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if( !hasBeacons )
|
|
75
|
+
return next(); // No beacons.
|
|
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
|
+
}
|
|
82
|
+
if( condition.type === "speed" ) {
|
|
83
|
+
return next(new Error("Zone cannot both contain a beacon and have a Speed condition."))
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
next();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
helpers.checkMinimumGeofeaturesValidForZone = function(zone, next) {
|
|
90
|
+
if( !zone.geofeatures )
|
|
91
|
+
return next();
|
|
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
|
+
return next(new Error("Zone must not have minimumGeofeaturesCrossed higher than geofeatures count"))
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
next();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
helpers.validateTravelPathConditionCount = function(zone, next) {
|
|
103
|
+
if( !zone.conditions )
|
|
104
|
+
return next();
|
|
105
|
+
if( !zone.conditions || !zone.conditions.length )
|
|
106
|
+
return next(); // No conditions.
|
|
107
|
+
|
|
108
|
+
let numberOfTravelPathConditions = 0
|
|
109
|
+
|
|
110
|
+
for( let condition of zone.conditions ) {
|
|
111
|
+
if( condition.type === "travelPath" ) numberOfTravelPathConditions ++
|
|
112
|
+
if ( numberOfTravelPathConditions > 1 ) return next(new Error("Zone must not have more than 1 travel path condition"))
|
|
113
|
+
}
|
|
114
|
+
next();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
module.exports = helpers
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Created by Richard Tan on 27/02/18.
|
|
3
|
+
* Copyright : Bluedot Innovation.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
let mongoose = require('mongoose')
|
|
7
|
+
// let Schema = mongoose.Schema
|
|
8
|
+
let StateEnum = require('@bluedot-innovation/enums').StateEnum
|
|
9
|
+
let uuidv4 = require('uuid/v4')
|
|
10
|
+
let patcher = require('mongoose-json-patch')
|
|
11
|
+
const helpers = require('../helpers')
|
|
12
|
+
|
|
13
|
+
let AccountSchema = new mongoose.Schema({
|
|
14
|
+
_id: {type: String, default: uuidv4},
|
|
15
|
+
customerApiKey: {type: String, default: uuidv4}, // Backwards compatability
|
|
16
|
+
name: {type: String, required: true},
|
|
17
|
+
createdBy: {
|
|
18
|
+
// type: Schema.Types.ObjectId,
|
|
19
|
+
type: String,
|
|
20
|
+
validator: helpers.validateUUIDv4,
|
|
21
|
+
required: true,
|
|
22
|
+
// Adding a default to allow the lambdas to pass until we know who
|
|
23
|
+
// the createdBy will be.
|
|
24
|
+
default: uuidv4
|
|
25
|
+
},
|
|
26
|
+
state: {type: String, default: StateEnum.active},
|
|
27
|
+
poiCredits: Number,
|
|
28
|
+
integrations: Object,
|
|
29
|
+
features: Object,
|
|
30
|
+
creationTime: {type: Date, default: Date.now},
|
|
31
|
+
lastUpdateTime: {type: Date, default: Date.now}
|
|
32
|
+
},
|
|
33
|
+
{collection: 'account'})
|
|
34
|
+
|
|
35
|
+
AccountSchema.plugin(patcher)
|
|
36
|
+
|
|
37
|
+
// optional mongoose
|
|
38
|
+
let model = (mongooseInstance) => {
|
|
39
|
+
let Account
|
|
40
|
+
if (mongooseInstance) {
|
|
41
|
+
Account = mongooseInstance.model('Account', AccountSchema)
|
|
42
|
+
} else {
|
|
43
|
+
Account = mongoose.model('Account', AccountSchema)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return Account
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
|
|
50
|
+
module.exports = { Model: model, Schema: AccountSchema }
|
|
@@ -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/Beacon.js
CHANGED
|
@@ -1,36 +1,88 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"beaconType": String,
|
|
25
|
-
"altitude": Number,
|
|
26
|
-
"altitudeAccuracy": Number,
|
|
27
|
-
"dataSource" : {type:String, select: false, default : 'openApi'},
|
|
28
|
-
"geometry" : {type: Schema.Types.Mixed, default: {}}
|
|
1
|
+
const { BeaconEnum, StateEnum } = require('@bluedot-innovation/enums')
|
|
2
|
+
const PointGeometry = require('../schemas/PointGeometry')
|
|
3
|
+
const patcher = require('mongoose-json-patch')
|
|
4
|
+
const Point = require('../schemas/Point')
|
|
5
|
+
const mongoose = require('mongoose')
|
|
6
|
+
const uuidv4 = require('uuid/v4')
|
|
7
|
+
|
|
8
|
+
let schema = {
|
|
9
|
+
_id: {type: String, default: uuidv4},
|
|
10
|
+
name: {type: String, required: [true, 'name is required.']},
|
|
11
|
+
description: {type: String, default: ''},
|
|
12
|
+
creationTime: {type: Date, default: Date.now},
|
|
13
|
+
lastUpdateTime: {type: Date, default: Date.now},
|
|
14
|
+
state: {type: String, default: StateEnum.active},
|
|
15
|
+
beaconType: {
|
|
16
|
+
type: String,
|
|
17
|
+
required: true,
|
|
18
|
+
enum: [BeaconEnum.IOS, BeaconEnum.ANDROID, BeaconEnum.BOTH],
|
|
19
|
+
validate: {
|
|
20
|
+
isAsync: true,
|
|
21
|
+
validator: validateBeaconType,
|
|
22
|
+
msg: 'Async validation. This message is not used'
|
|
23
|
+
}
|
|
29
24
|
},
|
|
30
|
-
{
|
|
31
|
-
|
|
25
|
+
location: {type: Point, required: true},
|
|
26
|
+
geometry: {type: PointGeometry},
|
|
27
|
+
accountId: {type: String, required: true},
|
|
28
|
+
// These must be unique
|
|
29
|
+
major: {type: Number, validate: [{validator: validateMajorMinor, msg: 'Major needs to be within range(0-65535)'}]},
|
|
30
|
+
minor: {type: Number, validate: [{validator: validateMajorMinor, msg: 'Minor needs to be within range(0-65535)'}]},
|
|
31
|
+
txPower: {type: Number},
|
|
32
|
+
macAddress: {type: String},
|
|
33
|
+
proximityUUID: {type: String}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let BeaconSchema = new mongoose.Schema(schema, {collection: 'beacon', autoIndex: false})
|
|
37
|
+
|
|
38
|
+
BeaconSchema.index({ macAddress: 1 })
|
|
39
|
+
BeaconSchema.index({ proximityUUID: 1, major: 1, minor: 1 })
|
|
40
|
+
BeaconSchema.index({ accountId: 1, geometry: '2dsphere' })
|
|
41
|
+
|
|
42
|
+
BeaconSchema.plugin(patcher)
|
|
43
|
+
|
|
44
|
+
// mongoose validator helper plugin
|
|
45
|
+
BeaconSchema.post('validate', function (doc) {
|
|
46
|
+
// Beacon Schema post validate hook
|
|
47
|
+
this.lastUpdateTime = Date.now()
|
|
48
|
+
Object.assign(this.errors || {}, this.errors || {}, this.customErrors)
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
function validateMajorMinor (v) {
|
|
52
|
+
'use strict'
|
|
53
|
+
return v >= 0 && v <= 65535
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function validateBeaconType (v, callback) {
|
|
57
|
+
'use strict'
|
|
58
|
+
const beaconType = v
|
|
59
|
+
const { minor, major, macAddress, proximityUUID } = this;
|
|
60
|
+
|
|
61
|
+
let androidRegex = new RegExp(/(android)/ig)
|
|
62
|
+
let iosRegex = new RegExp(/(ios)/ig)
|
|
63
|
+
let bothRegex = new RegExp(/(both)/ig)
|
|
64
|
+
|
|
65
|
+
if (androidRegex.test(beaconType)) {
|
|
66
|
+
callback((!!macAddress), "Beacon type 'Android' must have a mac address")
|
|
67
|
+
} else if (iosRegex.test(beaconType)) {
|
|
68
|
+
callback((!!proximityUUID && !!minor && !!major), "Beacon type 'IOS' must have 'proximityUUID', 'minor' and 'major' values")
|
|
69
|
+
} else if (bothRegex.test(beaconType)) {
|
|
70
|
+
callback((!!proximityUUID && !!minor && !!major && !!macAddress), "Beacon type 'Both' must have all of 'proximityUUID', 'minor', 'major', and 'mac address' values")
|
|
71
|
+
} else {
|
|
72
|
+
callback(true)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
32
75
|
|
|
33
|
-
|
|
76
|
+
// optional mongoose
|
|
77
|
+
let model = (mongooseInstance) => {
|
|
78
|
+
const instance = mongooseInstance || mongoose
|
|
79
|
+
let Beacon = instance.model('Beacon', BeaconSchema)
|
|
34
80
|
|
|
35
|
-
|
|
81
|
+
Beacon.on('index', function (error) {
|
|
82
|
+
console.log(error.message)
|
|
83
|
+
})
|
|
36
84
|
|
|
85
|
+
return Beacon
|
|
86
|
+
}
|
|
87
|
+
// Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
|
|
88
|
+
module.exports = { Model: model, Schema: BeaconSchema, beaconSchema: schema }
|
package/models/Contract.js
CHANGED
|
@@ -3,43 +3,42 @@
|
|
|
3
3
|
* Copyright : Bluedot Innovations.
|
|
4
4
|
* Owner :
|
|
5
5
|
*/
|
|
6
|
-
|
|
6
|
+
let mongoose = require('mongoose')
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
collection
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
);
|
|
8
|
+
let Contract = mongoose.model('Contract', new mongoose.Schema(
|
|
9
|
+
{
|
|
10
|
+
customerId: String,
|
|
11
|
+
organisationName: String,
|
|
12
|
+
addressLine1: String,
|
|
13
|
+
addressLine2: String,
|
|
14
|
+
addressCity: String,
|
|
15
|
+
addressRegion: String,
|
|
16
|
+
addressPostcode: String,
|
|
17
|
+
addressCountry: String,
|
|
18
|
+
billingFirstName: String,
|
|
19
|
+
billingLastName: String,
|
|
20
|
+
billingTaxNumber: String,
|
|
21
|
+
billingEmail: String,
|
|
22
|
+
tradingName: String,
|
|
23
|
+
salesforceUrl: String,
|
|
24
|
+
startDate: {type: Date, default: Date.now},
|
|
25
|
+
endDate: {type: Date, default: Date.now},
|
|
26
|
+
frequency: mongoose.Schema.Types.Number,
|
|
27
|
+
monthEntries: [],
|
|
28
|
+
currency: {type: String, default: 'USD'},
|
|
29
|
+
currencyRate: Number,
|
|
30
|
+
template: String,
|
|
31
|
+
addedBy: String,
|
|
32
|
+
lastEditedBy: String,
|
|
33
|
+
xeroContactId: String,
|
|
34
|
+
state: String,
|
|
35
|
+
creationTime: {type: Date, default: Date.now},
|
|
36
|
+
lastUpdateTime: {type: Date, default: Date.now},
|
|
37
|
+
dataSource: {type: String, select: false, default: 'adminPortal'}
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
collection: 'contract'
|
|
41
|
+
})
|
|
42
|
+
)
|
|
44
43
|
|
|
45
|
-
module.exports = Contract
|
|
44
|
+
module.exports = Contract
|
package/models/CustomerLogin.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Created by andrewstirling on 20/6/17.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
var mongoose = require('mongoose')
|
|
6
|
-
var StateEnum = require('@bluedot-innovation/enums').StateEnum
|
|
5
|
+
var mongoose = require('mongoose')
|
|
6
|
+
var StateEnum = require('@bluedot-innovation/enums').StateEnum
|
|
7
7
|
|
|
8
8
|
var CustomerLogin = mongoose.model('CustomerLogin', new mongoose.Schema(
|
|
9
9
|
{
|
|
@@ -19,16 +19,15 @@ var CustomerLogin = mongoose.model('CustomerLogin', new mongoose.Schema(
|
|
|
19
19
|
integrations: {},
|
|
20
20
|
resetToken: String,
|
|
21
21
|
lastLoginTime: Date,
|
|
22
|
-
state: {type:String, default: StateEnum.active},
|
|
23
|
-
creationTime
|
|
24
|
-
lastUpdateTime
|
|
22
|
+
state: {type: String, default: StateEnum.active},
|
|
23
|
+
creationTime: {type: Date, default: Date.now},
|
|
24
|
+
lastUpdateTime: {type: Date, default: Date.now},
|
|
25
25
|
createdBy: String,
|
|
26
26
|
lastUpdatedBy: String
|
|
27
27
|
},
|
|
28
28
|
{
|
|
29
|
-
collection
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
);
|
|
29
|
+
collection: 'customerLogin'
|
|
30
|
+
})
|
|
31
|
+
)
|
|
33
32
|
|
|
34
|
-
module.exports = CustomerLogin
|
|
33
|
+
module.exports = CustomerLogin
|
package/models/DBEvent.js
CHANGED
|
@@ -3,19 +3,18 @@
|
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
)
|
|
19
|
-
|
|
8
|
+
let DBEventSchema = new mongoose.Schema({
|
|
9
|
+
_class: {type: String, default: 'au.com.bluedot.application.spring.DBEvent'},
|
|
10
|
+
customerId: String,
|
|
11
|
+
customerEmail: String,
|
|
12
|
+
actionName: String,
|
|
13
|
+
referenceId: String,
|
|
14
|
+
creationTime: {type: Date, select: false, default: Date.now}
|
|
15
|
+
},
|
|
16
|
+
{collection: 'dbevent'}
|
|
17
|
+
)
|
|
18
|
+
let DBEvent = mongoose.model('DBEvent', DBEventSchema)
|
|
20
19
|
|
|
21
|
-
module.exports = DBEvent
|
|
20
|
+
module.exports = DBEvent
|
package/models/DailyStats.js
CHANGED
|
@@ -4,25 +4,25 @@
|
|
|
4
4
|
* Owner :
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
const mongoose = require('mongoose')
|
|
8
|
-
|
|
7
|
+
const mongoose = require('mongoose')
|
|
8
|
+
const Schema = mongoose.Schema
|
|
9
|
+
const uuidv4 = require('uuid/v4')
|
|
9
10
|
|
|
10
11
|
const DailyStats = mongoose.model(
|
|
11
12
|
'DailyStats',
|
|
12
13
|
new Schema(
|
|
13
14
|
{
|
|
14
|
-
_id: {
|
|
15
|
+
_id: {type: String, default: uuidv4},
|
|
15
16
|
totalEndUsers: Number,
|
|
16
17
|
totalIos: Number,
|
|
17
18
|
totalAndroid: Number,
|
|
18
|
-
|
|
19
|
-
creationTime: { type: Date, default: Date.now }
|
|
19
|
+
creationDate: {type: Date, default: Date.now}
|
|
20
20
|
},
|
|
21
21
|
{
|
|
22
22
|
collection: 'dailyStats',
|
|
23
23
|
versionKey: false
|
|
24
24
|
}
|
|
25
25
|
)
|
|
26
|
-
)
|
|
26
|
+
)
|
|
27
27
|
|
|
28
|
-
module.exports = DailyStats
|
|
28
|
+
module.exports = DailyStats
|
|
@@ -3,35 +3,34 @@
|
|
|
3
3
|
* Copyright : Bluedot Innovations.
|
|
4
4
|
* Owner :
|
|
5
5
|
*/
|
|
6
|
-
var mongoose = require('mongoose')
|
|
6
|
+
var mongoose = require('mongoose')
|
|
7
7
|
|
|
8
8
|
var DeviceRulesRequest = mongoose.model('DeviceRulesRequest', new mongoose.Schema(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
},
|
|
17
|
-
installationReference : String,
|
|
18
|
-
apiKey : String,
|
|
19
|
-
packageName : String,
|
|
20
|
-
clientEmail : String,
|
|
21
|
-
batteryStatus : String,
|
|
22
|
-
deviceType : String,
|
|
23
|
-
locationMethod : String,
|
|
24
|
-
platform : String,
|
|
25
|
-
sdkVersion : String,
|
|
26
|
-
osVersion : String,
|
|
27
|
-
speed : Number,
|
|
28
|
-
creationTime : { type: Date, default: Date.now },
|
|
29
|
-
lastUpdateTime : { type: Date, default: Date.now }
|
|
9
|
+
{
|
|
10
|
+
_id: String,
|
|
11
|
+
_class: {type: String, default: 'au.com.bluedot.application.model.client.DeviceRulesRequest'},
|
|
12
|
+
currentDeviceLocation: {
|
|
13
|
+
'longitude': Number,
|
|
14
|
+
'latitude': Number,
|
|
15
|
+
'geometryType': String
|
|
30
16
|
},
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
17
|
+
installationReference: String,
|
|
18
|
+
apiKey: String,
|
|
19
|
+
packageName: String,
|
|
20
|
+
clientEmail: String,
|
|
21
|
+
batteryStatus: String,
|
|
22
|
+
deviceType: String,
|
|
23
|
+
locationMethod: String,
|
|
24
|
+
platform: String,
|
|
25
|
+
sdkVersion: String,
|
|
26
|
+
osVersion: String,
|
|
27
|
+
speed: Number,
|
|
28
|
+
creationTime: { type: Date, default: Date.now },
|
|
29
|
+
lastUpdateTime: { type: Date, default: Date.now }
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
collection: 'deviceRulesRequest'
|
|
33
|
+
})
|
|
34
|
+
)
|
|
36
35
|
|
|
37
|
-
module.exports = DeviceRulesRequest
|
|
36
|
+
module.exports = DeviceRulesRequest
|
package/models/MessageAction.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
* Created by Arun on 10/09/2014.
|
|
3
|
-
* Copyright : Bluedot Innovations.
|
|
4
|
-
* Owner :
|
|
5
|
-
*/
|
|
6
|
-
var mongoose = require('mongoose');
|
|
7
|
-
var StateEnum = require('@bluedot-innovation/enums').StateEnum;
|
|
1
|
+
let mongoose = require('mongoose')
|
|
8
2
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
3
|
+
let schema = {
|
|
4
|
+
title: {type: String, required: [true, 'title is required. ']},
|
|
5
|
+
message: {type: String, required: [true, 'message is required. ']}
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
let MessageActionSchema = new mongoose.Schema(schema, {
|
|
9
|
+
_id: false,
|
|
10
|
+
versionKey: false
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
MessageActionSchema.add({
|
|
14
|
+
type: {type: String, required: true}
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
// optional mongoose
|
|
18
|
+
let model = (mongooseInstance) => {
|
|
19
|
+
let MessageAction
|
|
20
|
+
if (mongooseInstance) {
|
|
21
|
+
MessageAction = mongooseInstance.model('MessageAction', MessageActionSchema)
|
|
22
|
+
} else {
|
|
23
|
+
MessageAction = mongoose.model('MessageAction', MessageActionSchema)
|
|
25
24
|
}
|
|
26
|
-
);
|
|
27
|
-
var MessageAction = mongoose.model('MessageAction', MessageActionSchema);
|
|
28
25
|
|
|
29
|
-
|
|
26
|
+
return MessageAction
|
|
27
|
+
}
|
|
28
|
+
// Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
|
|
29
|
+
module.exports = { Model: model, Schema: MessageActionSchema, messageActionSchema: schema }
|