@bluedot-innovation/models 2.0.0-alpha1 → 2.0.0-beta.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/b3865a46e2cec635045d586cfc79e5c6.json +1 -0
- package/.nyc_output/d9020767349457a911ef2b431e357310.json +1 -0
- package/Models.js +48 -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 +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 +74 -0
- package/__tests__/dailyStats/checkDailyStats.js +31 -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 +62 -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/polygon/polygon.data.json +46 -0
- package/__tests__/geofeature/polygon/polygon.rules.json +3 -0
- package/__tests__/geofeature/polygon/polygon.spec.js +70 -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 +70 -0
- package/__tests__/monthlyStats/monthlyStats.data.json +29 -0
- package/__tests__/monthlyStats/monthlyStats.spec.js +68 -0
- package/__tests__/project/project.data.json +14 -0
- package/__tests__/project/project.rules.json +9 -0
- package/__tests__/project/project.spec.js +81 -0
- package/__tests__/ruleRequestAggregation/ruleRequestAggregation.data.json +8 -0
- package/__tests__/ruleRequestAggregation/ruleRequestAggregation.spec.js +69 -0
- package/__tests__/user/user.data.js +13 -0
- package/__tests__/user/user.rules.js +8 -0
- package/__tests__/user/user.spec.js +83 -0
- package/__tests__/zone/zone.action.spec.js +50 -0
- package/__tests__/zone/zone.data.json +156 -0
- package/__tests__/zone/zone.filter.spec.js +50 -0
- package/__tests__/zone/zone.geofeatures.spec.js +74 -0
- package/__tests__/zone/zone.spec.js +107 -0
- package/helpers.js +14 -0
- package/models/Account.js +49 -0
- package/models/AdminPortalUser.js +10 -11
- package/models/Beacon.js +92 -78
- package/models/BeaconFilter.js +28 -12
- package/models/BearingFilter.js +46 -23
- package/models/BoundingBox.js +37 -20
- package/models/CalendarDateRangeFilter.js +34 -19
- package/models/Circle.js +34 -18
- package/models/Contract.js +37 -38
- 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 +16 -18
- package/models/MessageAction.js +31 -16
- package/models/MonthlyStats.js +44 -0
- 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 -15
- package/models/Polygon.js +35 -19
- package/models/Polyline.js +35 -19
- package/models/Project.js +54 -0
- package/models/RuleRequestAggregation.js +33 -15
- package/models/SimpleCheckInZone.js +21 -21
- package/models/SingleUseToken.js +7 -8
- package/models/SpeedFilter.js +39 -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 +36 -18
- package/models/UrlAction.js +54 -0
- package/models/User.js +59 -0
- package/models/Zone.js +85 -273
- package/models/ZoneUIState.js +18 -18
- package/package.json +20 -8
- package/schemas/Point.js +10 -13
- package/schemas/Webhook.js +22 -0
- package/yarn.lock +2796 -0
- package/__tests__/zone/checkActions.js +0 -64
- package/__tests__/zone/checkAppId.js +0 -41
- package/__tests__/zone/checkBeacon.js +0 -46
- package/__tests__/zone/checkBearingFitler.js +0 -48
- package/__tests__/zone/checkBoundingBox.js +0 -44
- package/__tests__/zone/checkCalendarDateRangeFilterFitler.js +0 -48
- package/__tests__/zone/checkCircle.js +0 -41
- package/__tests__/zone/checkMRT.js +0 -46
- package/__tests__/zone/checkPercentageCrossedFitler.js +0 -48
- package/__tests__/zone/checkPolygon.js +0 -78
- package/__tests__/zone/checkPolyline.js +0 -78
- package/__tests__/zone/checkSpeedFitler.js +0 -48
- package/__tests__/zone/checkTimeOfDayRangeFitler.js +0 -48
- package/models/AdminUser.js +0 -10
- package/models/Application.js +0 -38
- package/models/Customer.js +0 -38
- package/models/URLAction.js +0 -34
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
let mongoose = require('mongoose')
|
|
2
|
+
let StateEnum = require('@bluedot-innovation/enums').StateEnum
|
|
3
|
+
let uuidv4 = require('uuid/v4')
|
|
4
|
+
|
|
5
|
+
let schema = {
|
|
6
|
+
guid: {type: String, default: uuidv4},
|
|
7
|
+
url: {
|
|
8
|
+
type: String,
|
|
9
|
+
required: [true, 'url is required. '],
|
|
10
|
+
validate: {
|
|
11
|
+
isAsync: true,
|
|
12
|
+
validator: validateURL
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
description: {type: String, default: ''},
|
|
16
|
+
creationTime: {type: Date, default: Date.now},
|
|
17
|
+
lastUpdateTime: {type: Date, default: Date.now},
|
|
18
|
+
state: {type: String, default: StateEnum.active, select: false}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
let URLActionSchema = new mongoose.Schema(schema,
|
|
22
|
+
{
|
|
23
|
+
_id: false,
|
|
24
|
+
__v: false
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
URLActionSchema.add({
|
|
28
|
+
type:
|
|
29
|
+
{type: String, required: true}
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
function validateURL (url, cb) {
|
|
33
|
+
let magicCallback = cb
|
|
34
|
+
let urlRegex = new RegExp('^(http[s]?:\\/\\/(www\\.)?|ftp:\\/\\/(www\\.)?|www\\.){1}([0-9A-Za-z-\\.@:%_+~#=]+)+((\\.[a-zA-Z]{2,3})+)(/(.)*)?(\\?(.)*)?')
|
|
35
|
+
if (!urlRegex.test(url)) {
|
|
36
|
+
return magicCallback(false, `${url} is not a valid URL`)
|
|
37
|
+
}
|
|
38
|
+
magicCallback(true)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// optional mongoose
|
|
42
|
+
const model = (mongooseInstance) => {
|
|
43
|
+
let Urlaction
|
|
44
|
+
if (mongooseInstance) {
|
|
45
|
+
Urlaction = mongooseInstance.model('Urlaction', URLActionSchema)
|
|
46
|
+
} else {
|
|
47
|
+
Urlaction = mongoose.model('Urlaction', URLActionSchema)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return Urlaction
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
|
|
54
|
+
module.exports = { Model: model, Schema: URLActionSchema, urlActionSchema: schema }
|
package/models/User.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Created by Richard Tan on 27/02/18.
|
|
3
|
+
* Copyright : Bluedot Innovation.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
let StateEnum = require('@bluedot-innovation/enums').StateEnum
|
|
7
|
+
let mongoose = require('mongoose')
|
|
8
|
+
let patcher = require('mongoose-json-patch')
|
|
9
|
+
const helpers = require('../helpers')
|
|
10
|
+
|
|
11
|
+
let UserSchema = new mongoose.Schema({
|
|
12
|
+
username: {
|
|
13
|
+
type: String,
|
|
14
|
+
required: true,
|
|
15
|
+
maxlength: 100,
|
|
16
|
+
unique: true
|
|
17
|
+
},
|
|
18
|
+
emailAddress: {
|
|
19
|
+
type: String,
|
|
20
|
+
required: true,
|
|
21
|
+
validate: {
|
|
22
|
+
validator: helpers.validateEmail,
|
|
23
|
+
message: '{VALUE} is not a valid email'
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
password: {type: String, required: true},
|
|
27
|
+
firstName: {type: String, required: true},
|
|
28
|
+
lastName: {type: String, required: true},
|
|
29
|
+
phoneNumber: {type: String, maxlength: 20},
|
|
30
|
+
state: {type: String, default: StateEnum.active},
|
|
31
|
+
creationTime: {type: Date, default: Date.now},
|
|
32
|
+
lastUpdateTime: {type: Date, default: Date.now},
|
|
33
|
+
isAdmin: {type: Boolean, required: true},
|
|
34
|
+
secret: String,
|
|
35
|
+
projectPermissions: Array,
|
|
36
|
+
accountId: {
|
|
37
|
+
type: String,
|
|
38
|
+
required: true,
|
|
39
|
+
validator: helpers.validateUUIDv4
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
{collection: 'user'})
|
|
43
|
+
|
|
44
|
+
UserSchema.plugin(patcher)
|
|
45
|
+
|
|
46
|
+
// optional mongoose
|
|
47
|
+
let model = (mongooseInstance) => {
|
|
48
|
+
let User
|
|
49
|
+
if (mongooseInstance) {
|
|
50
|
+
User = mongooseInstance.model('User', UserSchema)
|
|
51
|
+
} else {
|
|
52
|
+
User = mongoose.model('User', UserSchema)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return User
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
|
|
59
|
+
module.exports = { Model: model, Schema: UserSchema }
|
package/models/Zone.js
CHANGED
|
@@ -4,284 +4,96 @@
|
|
|
4
4
|
* Owner :
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
let mongoose
|
|
8
|
-
|
|
9
|
-
let StateEnum
|
|
10
|
-
let
|
|
11
|
-
let
|
|
12
|
-
let
|
|
13
|
-
let
|
|
14
|
-
let
|
|
15
|
-
let
|
|
16
|
-
let
|
|
17
|
-
let
|
|
18
|
-
let
|
|
19
|
-
let
|
|
20
|
-
let
|
|
21
|
-
let
|
|
22
|
-
let
|
|
7
|
+
let mongoose = require('mongoose')
|
|
8
|
+
let Schema = mongoose.Schema
|
|
9
|
+
let StateEnum = require('@bluedot-innovation/enums').StateEnum
|
|
10
|
+
let messageActionSchema = require('./MessageAction').messageActionSchema
|
|
11
|
+
let urlActionSchema = require('./UrlAction').urlActionSchema
|
|
12
|
+
let circleSchema = require('./Circle').circleSchema
|
|
13
|
+
let boundingBoxSchema = require('./BoundingBox').boundingBoxSchema
|
|
14
|
+
let polylineSchema = require('./Polyline').polylineSchema
|
|
15
|
+
let polygonSchema = require('./Polygon').polygonSchema
|
|
16
|
+
let beaconSchema = require('./Beacon').beaconSchema
|
|
17
|
+
let speedFilterSchema = require('./SpeedFilter').speedFilterSchema
|
|
18
|
+
let bearingFilterSchema = require('./BearingFilter').bearingFilterSchema
|
|
19
|
+
let timeOfDayRangeFilterSchema = require('./TimeOfDayRangeFilter').timeOfDayRangeFilterSchema
|
|
20
|
+
let calendarDateRangeFilterSchema = require('./CalendarDateRangeFilter').calendarDateRangeFilterSchema
|
|
21
|
+
let percentageCrossedFilterSchema = require('./PercentageCrossedFilter').percentageCrossedFilterSchema
|
|
22
|
+
let uuidv4 = require('uuid/v4')
|
|
23
|
+
let patcher = require('mongoose-json-patch')
|
|
24
|
+
|
|
25
|
+
// ////// //
|
|
26
|
+
// Schema //
|
|
27
|
+
// ////// //
|
|
28
|
+
|
|
29
|
+
let actionSchema = new Schema({},
|
|
30
|
+
{ discriminatorKey: 'type', _id: false })
|
|
31
|
+
|
|
32
|
+
let filterSchema = new Schema({},
|
|
33
|
+
{ discriminatorKey: 'type', _id: false })
|
|
34
|
+
|
|
35
|
+
let geofeatureSchema = new Schema({},
|
|
36
|
+
{ discriminatorKey: 'type', _id: false })
|
|
23
37
|
|
|
24
38
|
let ZoneSchema = new Schema({
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
},
|
|
36
|
-
filter : { type : [],
|
|
37
|
-
validate : {
|
|
38
|
-
validator: validateFilters
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
actions : { type : [],
|
|
42
|
-
validate : {
|
|
43
|
-
validator: validateActions
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
|
-
geofeatures : { type : [],
|
|
47
|
-
validate : {
|
|
48
|
-
validator: validateGeofeatures
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
|
-
customData : [{ type : Schema.Types.Mixed }],
|
|
52
|
-
description : { type : String, default: '' },
|
|
53
|
-
creationTime : { type : Date, default: Date.now },
|
|
54
|
-
lastUpdateTime : { type : Date, default: Date.now },
|
|
55
|
-
applicationId : { type : String, required: [true, 'applicationId is required'] },
|
|
56
|
-
state : { type : String, default : StateEnum.active, select: false }
|
|
57
|
-
},
|
|
58
|
-
{ collection : 'zone' });
|
|
59
|
-
|
|
60
|
-
function validateFilters(filters){
|
|
61
|
-
let errorList = '';
|
|
62
|
-
|
|
63
|
-
filters.forEach(filter => {
|
|
64
|
-
switch(filter.type) {
|
|
65
|
-
case 'speed': {
|
|
66
|
-
let speedFilter = new SpeedFilter(filter);
|
|
67
|
-
let speedFilterErrors = speedFilter.validateSync();
|
|
68
|
-
if(speedFilterErrors) {
|
|
69
|
-
for (let key of Object.keys(speedFilterErrors.errors)) {
|
|
70
|
-
console.log(speedFilterErrors.errors[key].message);
|
|
71
|
-
errorList = errorList + speedFilterErrors.errors[key].message;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
break;
|
|
76
|
-
}
|
|
77
|
-
case 'bearing': {
|
|
78
|
-
let bearingFilter = new BearingFilter(filter);
|
|
79
|
-
let bearingFilterErrors = bearingFilter.validateSync();
|
|
80
|
-
if(bearingFilterErrors) {
|
|
81
|
-
for (let key of Object.keys(bearingFilterErrors.errors)) {
|
|
82
|
-
console.log(bearingFilterErrors.errors[key].message);
|
|
83
|
-
errorList = errorList + bearingFilterErrors.errors[key].message;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
break;
|
|
88
|
-
}
|
|
89
|
-
case 'percentageCrossed': {
|
|
90
|
-
let percentageCrossedFilter = new PercentageCrossedFilter(filter);
|
|
91
|
-
let percentageCrossedFilterErrors = percentageCrossedFilter.validateSync();
|
|
92
|
-
if(percentageCrossedFilterErrors) {
|
|
93
|
-
for (let key of Object.keys(percentageCrossedFilterErrors.errors)) {
|
|
94
|
-
console.log(percentageCrossedFilterErrors.errors[key].message);
|
|
95
|
-
errorList = errorList + percentageCrossedFilterErrors.errors[key].message;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
break;
|
|
100
|
-
}
|
|
101
|
-
case 'timeOfDayRange': {
|
|
102
|
-
let timeOfDayRangeFilter = new TimeOfDayRangeFilter(filter);
|
|
103
|
-
let timeOfDayRangeFilterErrors = timeOfDayRangeFilter.validateSync();
|
|
104
|
-
if(timeOfDayRangeFilterErrors) {
|
|
105
|
-
for (let key of Object.keys(timeOfDayRangeFilterErrors.errors)) {
|
|
106
|
-
console.log(timeOfDayRangeFilterErrors.errors[key].message);
|
|
107
|
-
errorList = errorList + timeOfDayRangeFilterErrors.errors[key].message;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
break;
|
|
112
|
-
}
|
|
113
|
-
case 'calendarDateRange': {
|
|
114
|
-
let calendarDateRangeFilter = new CalendarDateRangeFilter(filter);
|
|
115
|
-
let calendarDateRangeFilterErrors = calendarDateRangeFilter.validateSync();
|
|
116
|
-
if(calendarDateRangeFilterErrors) {
|
|
117
|
-
for (let key of Object.keys(calendarDateRangeFilterErrors.errors)) {
|
|
118
|
-
console.log(calendarDateRangeFilterErrors.errors[key].message);
|
|
119
|
-
errorList = errorList + calendarDateRangeFilterErrors.errors[key].message;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
break;
|
|
124
|
-
}
|
|
125
|
-
default: {
|
|
126
|
-
console.log("Please enter a valid filter type.");
|
|
127
|
-
errorList = errorList + "Please enter a valid filter type. ";
|
|
128
|
-
|
|
129
|
-
break;
|
|
130
|
-
}
|
|
39
|
+
_id: {type: String, default: uuidv4},
|
|
40
|
+
name: {type: String, required: [true, 'name is required']},
|
|
41
|
+
minimumRetriggerTime: {
|
|
42
|
+
type: Number,
|
|
43
|
+
required: [true, 'minimumRetriggerTime is required'],
|
|
44
|
+
min: 60,
|
|
45
|
+
max: 3599940,
|
|
46
|
+
validate: {
|
|
47
|
+
validator: Number.isInteger,
|
|
48
|
+
message: '{VALUE} is not a number'
|
|
131
49
|
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
if(errorList != '')
|
|
178
|
-
throw new Error(errorList);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
function validateGeofeatures(features) {
|
|
183
|
-
if(features.length == 0) {
|
|
184
|
-
throw new Error("Geofeatures cannot be empty.");
|
|
50
|
+
},
|
|
51
|
+
filters: {
|
|
52
|
+
type: [filterSchema]
|
|
53
|
+
},
|
|
54
|
+
actions: {
|
|
55
|
+
type: [actionSchema]
|
|
56
|
+
},
|
|
57
|
+
geofeatures: {
|
|
58
|
+
type: [geofeatureSchema],
|
|
59
|
+
required: true
|
|
60
|
+
},
|
|
61
|
+
customData: [{type: Schema.Types.Mixed}],
|
|
62
|
+
description: {type: String, default: ''},
|
|
63
|
+
creationTime: {type: Date, required: [true, 'creationTime is required'], select: false},
|
|
64
|
+
lastUpdateTime: {type: Date, required: [true, 'lastUpdateTime is required'], select: false},
|
|
65
|
+
projectId: {type: String, required: [true, 'projectId is required']},
|
|
66
|
+
state: {type: String, default: StateEnum.active, select: false}
|
|
67
|
+
}, {collection: 'zone'})
|
|
68
|
+
|
|
69
|
+
// TODO: Test patcher and include for other schemas if required
|
|
70
|
+
ZoneSchema.plugin(patcher)
|
|
71
|
+
|
|
72
|
+
ZoneSchema.path('actions').discriminator('url', new Schema(urlActionSchema))
|
|
73
|
+
ZoneSchema.path('actions').discriminator('message', new Schema(messageActionSchema))
|
|
74
|
+
|
|
75
|
+
ZoneSchema.path('filters').discriminator('bearing', new Schema(bearingFilterSchema))
|
|
76
|
+
ZoneSchema.path('filters').discriminator('calendarDateRange', new Schema(calendarDateRangeFilterSchema))
|
|
77
|
+
ZoneSchema.path('filters').discriminator('percentageCrossed', new Schema(percentageCrossedFilterSchema))
|
|
78
|
+
ZoneSchema.path('filters').discriminator('speed', new Schema(speedFilterSchema))
|
|
79
|
+
ZoneSchema.path('filters').discriminator('timeOfDayRange', new Schema(timeOfDayRangeFilterSchema))
|
|
80
|
+
|
|
81
|
+
ZoneSchema.path('geofeatures').discriminator('circle', new Schema(circleSchema))
|
|
82
|
+
ZoneSchema.path('geofeatures').discriminator('beacon', new Schema(beaconSchema))
|
|
83
|
+
ZoneSchema.path('geofeatures').discriminator('polygon', new Schema(polygonSchema))
|
|
84
|
+
ZoneSchema.path('geofeatures').discriminator('polyline', new Schema(polylineSchema))
|
|
85
|
+
ZoneSchema.path('geofeatures').discriminator('boundingBox', new Schema(boundingBoxSchema))
|
|
86
|
+
|
|
87
|
+
// optional mongoose
|
|
88
|
+
const model = (mongooseInstance) => {
|
|
89
|
+
let Zone
|
|
90
|
+
if (mongooseInstance) {
|
|
91
|
+
Zone = mongooseInstance.model('Zone', ZoneSchema)
|
|
185
92
|
} else {
|
|
186
|
-
|
|
187
|
-
features.forEach(geofeature => {
|
|
188
|
-
switch(geofeature.type) {
|
|
189
|
-
case 'circle': {
|
|
190
|
-
let circle = new Circle(geofeature);
|
|
191
|
-
let circleErrors = circle.validateSync();
|
|
192
|
-
|
|
193
|
-
if(circleErrors) {
|
|
194
|
-
for (let key of Object.keys(circleErrors.errors)) {
|
|
195
|
-
console.log(circleErrors.errors[key].message);
|
|
196
|
-
errorList = errorList + circleErrors.errors[key].message;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
break;
|
|
201
|
-
}
|
|
202
|
-
case 'boundingBox': {
|
|
203
|
-
let boundingBox = new BoundingBox(geofeature);
|
|
204
|
-
let boundingBoxErrors = boundingBox.validateSync();
|
|
205
|
-
|
|
206
|
-
if(boundingBoxErrors) {
|
|
207
|
-
for (let key of Object.keys(boundingBoxErrors.errors)) {
|
|
208
|
-
console.log(boundingBoxErrors.errors[key].message);
|
|
209
|
-
errorList = errorList + boundingBoxErrors.errors[key].message;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
break;
|
|
214
|
-
}
|
|
215
|
-
case 'polygon': {
|
|
216
|
-
let polygon = new Polygon(geofeature);
|
|
217
|
-
let polygonErrors = polygon.validateSync();
|
|
218
|
-
|
|
219
|
-
if(polygonErrors) {
|
|
220
|
-
for (let key of Object.keys(polygonErrors.errors)) {
|
|
221
|
-
console.log(polygonErrors.errors[key].message);
|
|
222
|
-
errorList = errorList + polygonErrors.errors[key].message;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
break;
|
|
227
|
-
}
|
|
228
|
-
case 'polyline': {
|
|
229
|
-
let polyline = new Polyline(geofeature);
|
|
230
|
-
let polylineErrors = polyline.validateSync();
|
|
231
|
-
|
|
232
|
-
if(polylineErrors) {
|
|
233
|
-
for (let key of Object.keys(polylineErrors.errors)) {
|
|
234
|
-
console.log(polylineErrors.errors[key].message);
|
|
235
|
-
errorList = errorList + polylineErrors.errors[key].message;
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
break;
|
|
240
|
-
}
|
|
241
|
-
case 'beacon': {
|
|
242
|
-
|
|
243
|
-
let beacon = new Beacon(geofeature);
|
|
244
|
-
let beaconErrors = beacon.validateSync();
|
|
245
|
-
|
|
246
|
-
if(beaconErrors) {
|
|
247
|
-
for (let key of Object.keys(beaconErrors.errors)) {
|
|
248
|
-
console.log(beaconErrors.errors[key].message);
|
|
249
|
-
errorList = errorList + beaconErrors.errors[key].message;
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
break;
|
|
254
|
-
}
|
|
255
|
-
default: {
|
|
256
|
-
errorList = "Please enter a proper geofeature type. ";
|
|
257
|
-
break;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
if(errorList != '')
|
|
263
|
-
throw new Error(errorList);
|
|
93
|
+
Zone = mongoose.model('Zone', ZoneSchema)
|
|
264
94
|
}
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
function checkPoint(point, name1, name2){
|
|
268
|
-
let pointErrors = '';
|
|
269
95
|
|
|
270
|
-
|
|
271
|
-
pointErrors = pointErrors + name1 + " " +name2 + " should have a latitude field. ";
|
|
272
|
-
} else if(point.latitude < -90 || point.latitude > 90) {
|
|
273
|
-
pointErrors = pointErrors + name1 + " " + name2 + " latitude should be within -90 and 90. ";
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
if(!point.longitude) {
|
|
277
|
-
pointErrors = pointErrors + name1 + " " +name2 + " should have a longitude field. ";
|
|
278
|
-
} else if(point.longitude < -180 || point.longitude > 180) {
|
|
279
|
-
pointErrors = pointErrors + name1 + " " + name2 + " longitude should be within -180 and 180. ";
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
return pointErrors;
|
|
96
|
+
return Zone
|
|
283
97
|
}
|
|
284
98
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
module.exports = Zone;
|
|
99
|
+
module.exports = { Model: model, Schema: ZoneSchema }
|
package/models/ZoneUIState.js
CHANGED
|
@@ -3,23 +3,23 @@
|
|
|
3
3
|
* Copyright : Bluedot Innovations.
|
|
4
4
|
* Owner :
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
let mongoose = require('mongoose')
|
|
7
|
+
let Schema = mongoose.Schema
|
|
8
|
+
let StateEnum = require('@bluedot-innovation/enums').StateEnum
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
)
|
|
10
|
+
let ZoneUIStateSchema = new mongoose.Schema({
|
|
11
|
+
_id: {type: String},
|
|
12
|
+
signature: {type: String},
|
|
13
|
+
center: Schema.Types.Mixed,
|
|
14
|
+
dataSource: {type: String, select: false, default: 'openApi'},
|
|
15
|
+
zoom: {type: Number, default: 4},
|
|
16
|
+
lastUpdateTime: {type: Date, default: Date.now},
|
|
17
|
+
creationTime: {type: Date, default: Date.now},
|
|
18
|
+
state: {type: String, default: StateEnum.active, select: false},
|
|
19
|
+
zoneId: String
|
|
20
|
+
},
|
|
21
|
+
{collection: 'zoneUIState'}
|
|
22
|
+
)
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
module.exports = ZoneUIState
|
|
24
|
+
let ZoneUIState = mongoose.model('ZoneUIState', ZoneUIStateSchema)
|
|
25
|
+
module.exports = ZoneUIState
|
package/package.json
CHANGED
|
@@ -1,24 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bluedot-innovation/models",
|
|
3
|
-
"version": "2.0.0-
|
|
3
|
+
"version": "2.0.0-beta.10",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "Models.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"
|
|
7
|
+
"lint": "./node_modules/.bin/eslint -c .eslintrc.js ./models/*.js ./__tests__/**/*.js ./__tests__/**/**/*.js ./schemas/*.js",
|
|
8
|
+
"test": "mocha __tests__/**/*.spec.js __tests__/**/**/*.spec.js",
|
|
9
|
+
"test:coverage": "nyc mocha __tests__/**/*.spec.js __tests__/**/**/*.spec.js",
|
|
10
|
+
"test:coverage-check": "nyc check-coverage --lines 90 --functions 90 --branches 70",
|
|
11
|
+
"test:ci": "npm run lint && npm run test:coverage-check && npm test"
|
|
8
12
|
},
|
|
9
13
|
"author": "",
|
|
10
14
|
"license": "UNLICENSED",
|
|
11
15
|
"devDependencies": {
|
|
12
|
-
"assert": "^1.4.1",
|
|
13
16
|
"chai": "^4.1.2",
|
|
14
17
|
"describe": "*",
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
+
"eslint": "^4.12.0",
|
|
19
|
+
"eslint-config-standard": "^10.2.1",
|
|
20
|
+
"eslint-plugin-import": "^2.8.0",
|
|
21
|
+
"eslint-plugin-node": "^5.2.1",
|
|
22
|
+
"eslint-plugin-promise": "^3.6.0",
|
|
23
|
+
"eslint-plugin-standard": "^3.0.1",
|
|
24
|
+
"mocha": "^4.0.1",
|
|
25
|
+
"mockgoose": "^7.3.3",
|
|
26
|
+
"nyc": "^11.3.0",
|
|
27
|
+
"sinon": "^4.1.2"
|
|
18
28
|
},
|
|
19
29
|
"dependencies": {
|
|
20
|
-
"@bluedot-innovation/enums": "
|
|
21
|
-
"mongoose": "4.
|
|
30
|
+
"@bluedot-innovation/enums": "^1.0.2",
|
|
31
|
+
"mongoose": "^4.13.9",
|
|
32
|
+
"mongoose-error-helper": "0.0.2",
|
|
33
|
+
"mongoose-json-patch": "^1.1.1",
|
|
22
34
|
"uuid": "^3.1.0"
|
|
23
35
|
}
|
|
24
36
|
}
|
package/schemas/Point.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
let mongoose
|
|
1
|
+
let mongoose = require('mongoose')
|
|
2
2
|
|
|
3
3
|
let PointSchema = new mongoose.Schema({
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
);
|
|
4
|
+
type: {type: String},
|
|
5
|
+
latitude: {type: Number, required: [true, 'latitude is required. '], min: -90, max: 90},
|
|
6
|
+
longitude: {type: Number, required: [true, 'longitude is required. '], min: -180, max: 180}
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
_id: false,
|
|
10
|
+
__v: false
|
|
11
|
+
})
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
module.exports = PointSchema;
|
|
13
|
+
module.exports = PointSchema
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
let mongoose = require('mongoose')
|
|
2
|
+
|
|
3
|
+
let typeEnum = {
|
|
4
|
+
values: ['trigger', 'configurationChanged'],
|
|
5
|
+
message: 'enum validator failed for path `{PATH}` with value `{VALUE}`'
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
let WebhookSchema = new mongoose.Schema({
|
|
9
|
+
type: {type: String, enum: typeEnum, required: [true, 'webhook type is required']}, // configurationChanged, trigger
|
|
10
|
+
url: {type: String, required: true, validate: {isAsync: false, validator: validateUrl, msg: 'default error message'}},
|
|
11
|
+
enabled: {type: Boolean, required: [true, 'enabled is required']},
|
|
12
|
+
headers: {type: mongoose.Schema.Types.Mixed, default: null}
|
|
13
|
+
}, {
|
|
14
|
+
_id: false
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
function validateUrl (url) {
|
|
18
|
+
const expression = 'https?:\\/\\/(www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{2,256}\\.[a-z]{2,4}\\b([-a-zA-Z0-9@:%_\\+.~#?&//=]*)'
|
|
19
|
+
const regex = new RegExp(expression, 'i')
|
|
20
|
+
return regex.test(url)
|
|
21
|
+
}
|
|
22
|
+
module.exports = WebhookSchema
|