@bluedot-innovation/models 2.0.0-alpha.5 → 2.0.0-alpha.7
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/.gitlab-ci.yml +4 -2
- package/.nyc_output/.gitkeep +0 -0
- package/README.MD +10 -6
- 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__/{zone → geofeature/beacon}/beacon.spec.js +3 -3
- package/__tests__/{zone → geofeature/boundingBox}/boundingBox.spec.js +3 -3
- package/__tests__/geofeature/circle/circle.data.json +9 -0
- package/__tests__/{zone → geofeature/circle}/circle.spec.js +15 -24
- package/__tests__/{zone → geofeature/polygon}/polygon.spec.js +3 -3
- package/__tests__/{zone → geofeature/polyline}/polyline.spec.js +3 -3
- package/__tests__/zone/zone.action.spec.js +50 -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 +5 -8
- package/models/Beacon.js +9 -13
- package/models/BeaconFilter.js +25 -6
- package/models/BearingFilter.js +14 -7
- package/models/BoundingBox.js +14 -7
- package/models/CalendarDateRangeFilter.js +13 -7
- package/models/Circle.js +14 -7
- package/models/MessageAction.js +13 -7
- package/models/PercentageCrossedFilter.js +13 -7
- package/models/Polygon.js +13 -6
- package/models/Polyline.js +15 -6
- package/models/SpeedFilter.js +13 -6
- package/models/TimeOfDayRangeFilter.js +13 -6
- package/models/UrlAction.js +13 -7
- package/models/Zone.js +45 -160
- package/package.json +8 -5
- package/__tests__/zone/checkAppId.js +0 -39
- package/__tests__/zone/checkBeacon.js +0 -44
- package/__tests__/zone/checkMRT.js +0 -44
- package/__tests__/zone/data/zone-with-invalid-circle.json +0 -34
- /package/__tests__/{zone/data → geofeature/beacon}/beacon.data.json +0 -0
- /package/__tests__/{zone/rules → geofeature/beacon}/beacon.rules.json +0 -0
- /package/__tests__/{zone/data → geofeature/boundingBox}/boundingBox.data.json +0 -0
- /package/__tests__/{zone/rules → geofeature/boundingBox}/boundingBox.rules.json +0 -0
- /package/__tests__/{zone/rules → geofeature/circle}/circle.rules.json +0 -0
- /package/__tests__/{zone/data → geofeature/polygon}/polygon.data.json +0 -0
- /package/__tests__/{zone/rules → geofeature/polygon}/polygon.rules.json +0 -0
- /package/__tests__/{zone/data → geofeature/polyline}/polyline.data.json +0 -0
- /package/__tests__/{zone/rules → geofeature/polyline}/polyline.rules.json +0 -0
- /package/__tests__/zone/{data/zone.data.json → zone.data.json} +0 -0
package/models/Circle.js
CHANGED
|
@@ -3,21 +3,27 @@ let StateEnum = require('@bluedot-innovation/enums').StateEnum
|
|
|
3
3
|
let Point = require('../schemas/Point')
|
|
4
4
|
let uuidv4 = require('uuid/v4')
|
|
5
5
|
|
|
6
|
-
let
|
|
6
|
+
let schema = {
|
|
7
7
|
guid: {type: String, default: uuidv4},
|
|
8
|
-
type: {type: String, default: 'MultiLineString'},
|
|
9
8
|
name: {type: String, required: [true, 'name is required. ']},
|
|
10
9
|
radius: {type: Number, required: [true, 'radius is required. '], min: 5},
|
|
11
10
|
center: {type: Point, required: [true, 'center is required. ']},
|
|
12
11
|
creationTime: {type: Date, default: Date.now},
|
|
13
12
|
lastUpdateTime: {type: Date, default: Date.now},
|
|
14
13
|
state: {type: String, default: StateEnum.active, select: false}
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
_id: false,
|
|
18
|
-
__v: false
|
|
19
14
|
}
|
|
20
|
-
|
|
15
|
+
|
|
16
|
+
let CircleSchema = new mongoose.Schema(
|
|
17
|
+
schema,
|
|
18
|
+
{
|
|
19
|
+
_id: false,
|
|
20
|
+
__v: false
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
CircleSchema.add({
|
|
24
|
+
type:
|
|
25
|
+
{type: String, required: true}
|
|
26
|
+
})
|
|
21
27
|
|
|
22
28
|
// optional mongoose
|
|
23
29
|
module.exports = (mongooseInstance) => {
|
|
@@ -30,3 +36,4 @@ module.exports = (mongooseInstance) => {
|
|
|
30
36
|
|
|
31
37
|
return Circle
|
|
32
38
|
}
|
|
39
|
+
module.exports.circleSchema = schema
|
package/models/MessageAction.js
CHANGED
|
@@ -2,20 +2,25 @@ let mongoose = require('mongoose')
|
|
|
2
2
|
let StateEnum = require('@bluedot-innovation/enums').StateEnum
|
|
3
3
|
let uuidv4 = require('uuid/v4')
|
|
4
4
|
|
|
5
|
-
let
|
|
5
|
+
let schema = {
|
|
6
6
|
guid: {type: String, default: uuidv4},
|
|
7
|
-
type: {type: String},
|
|
8
7
|
title: {type: String, required: [true, 'title is required. ']},
|
|
9
8
|
message: {type: String, required: [true, 'message is required. ']},
|
|
10
9
|
creationTime: {type: Date, default: Date.now},
|
|
11
10
|
lastUpdateTime: {type: Date, default: Date.now},
|
|
12
11
|
state: {type: String, default: StateEnum.active, select: false}
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
_id: false,
|
|
16
|
-
__v: false
|
|
17
12
|
}
|
|
18
|
-
|
|
13
|
+
|
|
14
|
+
let MessageActionSchema = new mongoose.Schema(schema,
|
|
15
|
+
{
|
|
16
|
+
_id: false,
|
|
17
|
+
__v: false
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
MessageActionSchema.add({
|
|
21
|
+
type:
|
|
22
|
+
{type: String, required: true}
|
|
23
|
+
})
|
|
19
24
|
|
|
20
25
|
// optional mongoose
|
|
21
26
|
module.exports = (mongooseInstance) => {
|
|
@@ -28,3 +33,4 @@ module.exports = (mongooseInstance) => {
|
|
|
28
33
|
|
|
29
34
|
return MessageAction
|
|
30
35
|
}
|
|
36
|
+
module.exports.messageActionSchema = schema
|
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
let mongoose = require('mongoose')
|
|
2
2
|
let uuidv4 = require('uuid/v4')
|
|
3
3
|
|
|
4
|
-
let
|
|
4
|
+
let schema = {
|
|
5
5
|
guid: {type: String, default: uuidv4},
|
|
6
|
-
type: {type: String},
|
|
7
6
|
percentage: {type: Number, required: [true, 'percentage is required. '], min: 1, max: 100},
|
|
8
7
|
timeOutSeconds: {type: Number, required: [true, 'timeOutSeconds is required. '], min: 60, max: 86400},
|
|
9
8
|
sequential: {type: Boolean, default: false}
|
|
10
|
-
},
|
|
11
|
-
{
|
|
12
|
-
_id: false,
|
|
13
|
-
versionKey: false
|
|
14
9
|
}
|
|
15
|
-
|
|
10
|
+
let PercentageCrossedFilterSchema = new mongoose.Schema(
|
|
11
|
+
schema,
|
|
12
|
+
{
|
|
13
|
+
_id: false,
|
|
14
|
+
versionKey: false
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
PercentageCrossedFilterSchema.add({
|
|
18
|
+
type:
|
|
19
|
+
{type: String, required: true}
|
|
20
|
+
})
|
|
16
21
|
|
|
17
22
|
// optional mongoose
|
|
18
23
|
module.exports = (mongooseInstance) => {
|
|
@@ -25,3 +30,4 @@ module.exports = (mongooseInstance) => {
|
|
|
25
30
|
|
|
26
31
|
return PercentageCrossedFilter
|
|
27
32
|
}
|
|
33
|
+
module.exports.percentageCrossedFilterSchema = schema
|
package/models/Polygon.js
CHANGED
|
@@ -3,18 +3,24 @@ let StateEnum = require('@bluedot-innovation/enums').StateEnum
|
|
|
3
3
|
let Point = require('../schemas/Point')
|
|
4
4
|
let uuidv4 = require('uuid/v4')
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
const schema = {
|
|
7
7
|
guid: {type: String, default: uuidv4},
|
|
8
|
-
type: {type: String, required: true},
|
|
9
8
|
name: {type: String, required: [true, 'name is required. ']},
|
|
10
9
|
vertices: {type: [Point], required: [true, 'vertices is required. ']},
|
|
11
10
|
creationTime: {type: Date, default: Date.now},
|
|
12
11
|
lastUpdateTime: {type: Date, default: Date.now},
|
|
13
12
|
state: {type: String, default: StateEnum.active, select: false}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
}
|
|
14
|
+
const PolygonSchema = new mongoose.Schema(
|
|
15
|
+
schema,
|
|
16
|
+
{
|
|
17
|
+
_id: false,
|
|
18
|
+
versionKey: false
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
PolygonSchema.add({
|
|
22
|
+
type:
|
|
23
|
+
{type: String, required: true}
|
|
18
24
|
})
|
|
19
25
|
|
|
20
26
|
// optional mongoose
|
|
@@ -28,3 +34,4 @@ module.exports = (mongooseInstance) => {
|
|
|
28
34
|
|
|
29
35
|
return Polygon
|
|
30
36
|
}
|
|
37
|
+
module.exports.polygonSchema = schema
|
package/models/Polyline.js
CHANGED
|
@@ -3,19 +3,27 @@ let StateEnum = require('@bluedot-innovation/enums').StateEnum
|
|
|
3
3
|
let Point = require('../schemas/Point')
|
|
4
4
|
let uuidv4 = require('uuid/v4')
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
const schema = {
|
|
7
7
|
guid: {type: String, default: uuidv4},
|
|
8
|
-
type: {type: String, required: true},
|
|
9
8
|
name: {type: String, required: [true, 'name is required. ']},
|
|
10
9
|
vertices: {type: [Point], required: [true, 'vertices is required. ']},
|
|
11
10
|
creationTime: {type: Date, default: Date.now},
|
|
12
11
|
lastUpdateTime: {type: Date, default: Date.now},
|
|
13
12
|
state: {type: String, default: StateEnum.active, select: false}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const PolylineSchema = new mongoose.Schema(
|
|
16
|
+
schema,
|
|
17
|
+
{
|
|
18
|
+
_id: false,
|
|
19
|
+
versionKey: false
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
PolylineSchema.add({
|
|
23
|
+
type:
|
|
24
|
+
{type: String, required: true}
|
|
18
25
|
})
|
|
26
|
+
|
|
19
27
|
// optional mongoose
|
|
20
28
|
module.exports = (mongooseInstance) => {
|
|
21
29
|
let Polyline
|
|
@@ -27,3 +35,4 @@ module.exports = (mongooseInstance) => {
|
|
|
27
35
|
|
|
28
36
|
return Polyline
|
|
29
37
|
}
|
|
38
|
+
module.exports.polylineSchema = schema
|
package/models/SpeedFilter.js
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
let mongoose = require('mongoose')
|
|
2
2
|
let uuidv4 = require('uuid/v4')
|
|
3
3
|
|
|
4
|
-
let
|
|
4
|
+
let schema = {
|
|
5
5
|
guid: {type: String, default: uuidv4},
|
|
6
|
-
type: {type: String},
|
|
7
6
|
minimumSpeed: {type: Number, required: [true, 'minimumSpeed is required. '], min: 0},
|
|
8
7
|
maximumSpeed: {type: Number, required: true, validate: {validator: validateMaxSpeed, msg: 'default error message'}}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
}
|
|
9
|
+
let SpeedFilterSchema = new mongoose.Schema(
|
|
10
|
+
schema,
|
|
11
|
+
{
|
|
12
|
+
_id: false,
|
|
13
|
+
versionKey: false
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
SpeedFilterSchema.add({
|
|
17
|
+
type:
|
|
18
|
+
{type: String, required: true}
|
|
13
19
|
})
|
|
14
20
|
|
|
15
21
|
function validateMaxSpeed (v, cb) {
|
|
@@ -37,3 +43,4 @@ module.exports = (mongooseInstance) => {
|
|
|
37
43
|
|
|
38
44
|
return SpeedFilter
|
|
39
45
|
}
|
|
46
|
+
module.exports.speedFilterSchema = schema
|
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
let mongoose = require('mongoose')
|
|
2
2
|
let uuidv4 = require('uuid/v4')
|
|
3
3
|
|
|
4
|
-
let
|
|
4
|
+
let schema = {
|
|
5
5
|
guid: {type: String, default: uuidv4},
|
|
6
|
-
type: {type: String},
|
|
7
6
|
fromTime: {type: Number, required: [true, 'time is required. '], min: 0, max: 86400},
|
|
8
7
|
toTime: {type: Number, required: true, min: 0, max: 86400, validate: validateTime}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
}
|
|
9
|
+
let TimeOfDayRangeFilterSchema = new mongoose.Schema(
|
|
10
|
+
schema,
|
|
11
|
+
{
|
|
12
|
+
_id: false,
|
|
13
|
+
versionKey: false
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
TimeOfDayRangeFilterSchema.add({
|
|
17
|
+
type:
|
|
18
|
+
{type: String, required: true}
|
|
13
19
|
})
|
|
14
20
|
|
|
15
21
|
function validateTime (toTime, cb) {
|
|
@@ -33,3 +39,4 @@ module.exports = (mongooseInstance) => {
|
|
|
33
39
|
|
|
34
40
|
return TimeOfDayRangeFilter
|
|
35
41
|
}
|
|
42
|
+
module.exports.timeOfDayRangeFilterSchema = schema
|
package/models/UrlAction.js
CHANGED
|
@@ -2,9 +2,8 @@ let mongoose = require('mongoose')
|
|
|
2
2
|
let StateEnum = require('@bluedot-innovation/enums').StateEnum
|
|
3
3
|
let uuidv4 = require('uuid/v4')
|
|
4
4
|
|
|
5
|
-
let
|
|
5
|
+
let schema = {
|
|
6
6
|
guid: {type: String, default: uuidv4},
|
|
7
|
-
type: {type: String},
|
|
8
7
|
url: {
|
|
9
8
|
type: String,
|
|
10
9
|
required: [true, 'url is required. '],
|
|
@@ -16,12 +15,18 @@ let URLActionSchema = new mongoose.Schema({
|
|
|
16
15
|
creationTime: {type: Date, default: Date.now},
|
|
17
16
|
lastUpdateTime: {type: Date, default: Date.now},
|
|
18
17
|
state: {type: String, default: StateEnum.active, select: false}
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
_id: false,
|
|
22
|
-
__v: false
|
|
23
18
|
}
|
|
24
|
-
|
|
19
|
+
|
|
20
|
+
let URLActionSchema = new mongoose.Schema(schema,
|
|
21
|
+
{
|
|
22
|
+
_id: false,
|
|
23
|
+
__v: false
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
URLActionSchema.add({
|
|
27
|
+
type:
|
|
28
|
+
{type: String, required: true}
|
|
29
|
+
})
|
|
25
30
|
|
|
26
31
|
function validateURL (url, cb) {
|
|
27
32
|
let magicCallback = cb
|
|
@@ -43,3 +48,4 @@ module.exports = (mongooseInstance) => {
|
|
|
43
48
|
|
|
44
49
|
return Urlaction
|
|
45
50
|
}
|
|
51
|
+
module.exports.urlActionSchema = schema
|
package/models/Zone.js
CHANGED
|
@@ -7,151 +7,34 @@
|
|
|
7
7
|
let mongoose = require('mongoose')
|
|
8
8
|
let Schema = mongoose.Schema
|
|
9
9
|
let StateEnum = require('@bluedot-innovation/enums').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
|
|
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').calendarDateRangeSchema
|
|
21
|
+
let percentageCrossedFilterSchema = require('./PercentageCrossedFilter').percentageCrossedFilterSchema
|
|
22
22
|
let uuidv4 = require('uuid/v4')
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
// utility
|
|
26
|
-
const utilityFactory = {
|
|
27
|
-
mapping: {
|
|
28
|
-
circle: Circle,
|
|
29
|
-
beacon: Beacon,
|
|
30
|
-
boundingBox: BoundingBox,
|
|
31
|
-
polyline: Polyline,
|
|
32
|
-
polygon: Polygon,
|
|
33
|
-
message: MessageAction,
|
|
34
|
-
url: URLAction,
|
|
35
|
-
calendarDateRange: CalendarDateRangeFilter,
|
|
36
|
-
speedFilter: SpeedFilter,
|
|
37
|
-
bearingFilter: BearingFilter,
|
|
38
|
-
timeOfDayRangeFilter: TimeOfDayRangeFilter,
|
|
39
|
-
percentageCrossedFilter: PercentageCrossedFilter
|
|
40
|
-
},
|
|
41
|
-
create (feature) {
|
|
42
|
-
let Cls = this.mapping[feature.type]
|
|
43
|
-
return new Cls(feature)
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// todo Refactor fns: validate___Async & validate___
|
|
48
|
-
async function validateGeofeatureAsync (features) {
|
|
49
|
-
let errorList = {}
|
|
50
|
-
await Promise.all(features.map(async (feature) => {
|
|
51
|
-
let featureModel = utilityFactory.create(feature)
|
|
52
|
-
try {
|
|
53
|
-
await util.promisify(featureModel.validate)()
|
|
54
|
-
} catch (e) {
|
|
55
|
-
errorList[feature.type] = errorList[feature.type] || {}
|
|
56
|
-
Object.assign(errorList[feature.type], errorList[feature.type], e.errors)
|
|
57
|
-
}
|
|
58
|
-
}))
|
|
59
|
-
// if errors (object not empty)
|
|
60
|
-
if (Object.keys(errorList).length !== 0 && errorList.constructor === Object) {
|
|
61
|
-
this.customGeofeatureErrors = this.customGeofeatureErrors || {}
|
|
62
|
-
Object.assign(this.customGeofeatureErrors, this.customGeofeatureErrors || {}, errorList || {})
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
async function validateActionAsync (features) {
|
|
66
|
-
let errorList = {}
|
|
67
|
-
await Promise.all(features.map(async (feature) => {
|
|
68
|
-
let featureModel = utilityFactory.create(feature)
|
|
69
|
-
try {
|
|
70
|
-
await util.promisify(featureModel.validate)()
|
|
71
|
-
} catch (e) {
|
|
72
|
-
errorList[feature.type] = errorList[feature.type] || {}
|
|
73
|
-
Object.assign(errorList[feature.type], errorList[feature.type], e.errors)
|
|
74
|
-
}
|
|
75
|
-
}))
|
|
76
|
-
// if errors (object not empty)
|
|
77
|
-
if (Object.keys(errorList).length !== 0 && errorList.constructor === Object) {
|
|
78
|
-
this.customActionErrors = this.customActionErrors || {}
|
|
79
|
-
Object.assign(this.customActionErrors, this.customActionErrors || {}, errorList || {})
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
async function validateFilterAsync (features) {
|
|
83
|
-
let errorList = {}
|
|
84
|
-
await Promise.all(features.map(async (feature) => {
|
|
85
|
-
let featureModel = utilityFactory.create(feature)
|
|
86
|
-
try {
|
|
87
|
-
await util.promisify(featureModel.validate)()
|
|
88
|
-
} catch (e) {
|
|
89
|
-
errorList[feature.type] = errorList[feature.type] || {}
|
|
90
|
-
Object.assign(errorList[feature.type], errorList[feature.type], e.errors)
|
|
91
|
-
}
|
|
92
|
-
}))
|
|
93
|
-
// if errors (object not empty)
|
|
94
|
-
if (Object.keys(errorList).length !== 0 && errorList.constructor === Object) {
|
|
95
|
-
this.customFilterErrors = this.customFilterErrors || {}
|
|
96
|
-
Object.assign(this.customFilterErrors, this.customFilterErrors || {}, errorList || {})
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
async function validateGeofeatures (features, cb) {
|
|
100
|
-
// mongoose magic callback for async validation
|
|
101
|
-
let magicCallback = cb
|
|
102
|
-
try {
|
|
103
|
-
await validateGeofeatureAsync.call(this, features)
|
|
104
|
-
} catch (e) {
|
|
105
|
-
// todo handle error
|
|
106
|
-
console.error('ERROR', e)
|
|
107
|
-
}
|
|
108
|
-
if (!this.customGeofeatureErrors) {
|
|
109
|
-
magicCallback(true)
|
|
110
|
-
} else {
|
|
111
|
-
// callback false = has validation errors, true = no validation errors
|
|
112
|
-
return magicCallback(!(Object.keys(this.customGeofeatureErrors).length !== 0 && this.customGeofeatureErrors.constructor === Object))
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
async function validateActions (features, cb) {
|
|
116
|
-
// mongoose magic callback for async validation
|
|
117
|
-
let magicCallback = cb
|
|
118
|
-
try {
|
|
119
|
-
await validateActionAsync.call(this, features)
|
|
120
|
-
} catch (e) {
|
|
121
|
-
// todo handle error
|
|
122
|
-
console.error('ERROR', e)
|
|
123
|
-
}
|
|
124
|
-
if (!this.customActionErrors) {
|
|
125
|
-
return magicCallback(true)
|
|
126
|
-
} else {
|
|
127
|
-
// callback false = has validation errors, true = no validation errors
|
|
128
|
-
magicCallback(!(Object.keys(this.customActionErrors).length !== 0 && this.customActionErrors.constructor === Object))
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
async function validateFilters (features, cb) {
|
|
132
|
-
// mongoose magic callback for async validation
|
|
133
|
-
let magicCallback = cb
|
|
134
|
-
try {
|
|
135
|
-
await validateFilterAsync.call(this, features)
|
|
136
|
-
} catch (e) {
|
|
137
|
-
// todo handle error
|
|
138
|
-
console.error('ERROR', e)
|
|
139
|
-
}
|
|
140
|
-
if (!this.customFilterErrors) {
|
|
141
|
-
return magicCallback(true)
|
|
142
|
-
} else {
|
|
143
|
-
// callback false = has validation errors, true = no validation errors
|
|
144
|
-
magicCallback(!(Object.keys(this.customFilterErrors).length !== 0 && this.customFilterErrors.constructor === Object))
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
function validateNullGeofeatures (features) {
|
|
149
|
-
return features.length !== 0
|
|
150
|
-
}
|
|
23
|
+
let patcher = require('mongoose-json-patch')
|
|
151
24
|
|
|
152
25
|
// ////// //
|
|
153
26
|
// Schema //
|
|
154
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 })
|
|
37
|
+
|
|
155
38
|
let ZoneSchema = new Schema({
|
|
156
39
|
_id: {type: String, default: uuidv4},
|
|
157
40
|
name: {type: String, required: [true, 'name is required']},
|
|
@@ -166,23 +49,14 @@ let ZoneSchema = new Schema({
|
|
|
166
49
|
}
|
|
167
50
|
},
|
|
168
51
|
filters: {
|
|
169
|
-
type: []
|
|
170
|
-
validate: {
|
|
171
|
-
validator: validateFilters, msg: 'Filter validation error'
|
|
172
|
-
}
|
|
52
|
+
type: [filterSchema]
|
|
173
53
|
},
|
|
174
54
|
actions: {
|
|
175
|
-
type: []
|
|
176
|
-
validate: {
|
|
177
|
-
validator: validateActions, msg: 'Action validation error'
|
|
178
|
-
}
|
|
55
|
+
type: [actionSchema]
|
|
179
56
|
},
|
|
180
57
|
geofeatures: {
|
|
181
|
-
type: [],
|
|
182
|
-
|
|
183
|
-
{validator: validateNullGeofeatures, msg: 'Geofeatures cannot be empty'},
|
|
184
|
-
{validator: validateGeofeatures, msg: 'Geofeature validation error'}
|
|
185
|
-
]
|
|
58
|
+
type: [geofeatureSchema],
|
|
59
|
+
required: true
|
|
186
60
|
},
|
|
187
61
|
customData: [{type: Schema.Types.Mixed}],
|
|
188
62
|
description: {type: String, default: ''},
|
|
@@ -190,14 +64,25 @@ let ZoneSchema = new Schema({
|
|
|
190
64
|
lastUpdateTime: {type: Date, default: Date.now},
|
|
191
65
|
applicationId: {type: String, required: [true, 'applicationId is required']},
|
|
192
66
|
state: {type: String, default: StateEnum.active, select: false}
|
|
193
|
-
},
|
|
194
|
-
|
|
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))
|
|
195
80
|
|
|
196
|
-
|
|
197
|
-
ZoneSchema.
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
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))
|
|
201
86
|
|
|
202
87
|
// optional mongoose
|
|
203
88
|
module.exports = (mongooseInstance) => {
|
package/package.json
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bluedot-innovation/models",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.7",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "Models.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"test": "nyc mocha __tests__/**/*.spec.js __tests__/**/**/*.spec.js",
|
|
8
7
|
"lint": "./node_modules/.bin/eslint -c .eslintrc.js ./models/*.js ./__tests__/**/**/*.js ./schemas/*.js",
|
|
9
|
-
"
|
|
10
|
-
"
|
|
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",
|
|
12
|
+
"postversion": "git push --follow-tags"
|
|
11
13
|
},
|
|
12
14
|
"author": "",
|
|
13
15
|
"license": "UNLICENSED",
|
|
@@ -27,8 +29,9 @@
|
|
|
27
29
|
},
|
|
28
30
|
"dependencies": {
|
|
29
31
|
"@bluedot-innovation/enums": "*",
|
|
30
|
-
"mongoose": "4.
|
|
32
|
+
"mongoose": "^4.13.6",
|
|
31
33
|
"mongoose-error-helper": "0.0.2",
|
|
34
|
+
"mongoose-json-patch": "^1.1.1",
|
|
32
35
|
"uuid": "^3.1.0"
|
|
33
36
|
}
|
|
34
37
|
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
let assert = require('assert');
|
|
2
|
-
let Zone = require('../../models/Zone');
|
|
3
|
-
|
|
4
|
-
let zone = {
|
|
5
|
-
"name": "TDD zone",
|
|
6
|
-
"minimumRetriggerTime": "60",
|
|
7
|
-
"applicationId": 'c7058934-f1e6-4176-8730-a0bd28e8e0a9',
|
|
8
|
-
"checkout": true,
|
|
9
|
-
"actions": [],
|
|
10
|
-
"geofeatures": [{
|
|
11
|
-
"type":"circle",
|
|
12
|
-
"name":"circle with 15m radius",
|
|
13
|
-
"center": {
|
|
14
|
-
"latitude": -37.8186454,
|
|
15
|
-
"longitude": 144.979882
|
|
16
|
-
},
|
|
17
|
-
"radius": 15
|
|
18
|
-
}]
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
describe('Creating Zone ', () => {
|
|
22
|
-
it('check ApplicationId ', (done) => {
|
|
23
|
-
|
|
24
|
-
let createZone = new Zone(zone);
|
|
25
|
-
createZone.validate()
|
|
26
|
-
.then((output) => {
|
|
27
|
-
console.log("validate ApplicationId");
|
|
28
|
-
assert(true);
|
|
29
|
-
done();
|
|
30
|
-
}).catch(err => {
|
|
31
|
-
console.log("Errors found:");
|
|
32
|
-
for( let key of Object.keys(err.errors) ) {
|
|
33
|
-
console.log(err.errors[key].message);
|
|
34
|
-
}
|
|
35
|
-
assert(false);
|
|
36
|
-
done(err);
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
});
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
let assert = require('assert');
|
|
2
|
-
let Zone = require('../../models/Zone');
|
|
3
|
-
|
|
4
|
-
let zone = {
|
|
5
|
-
"name": "TDD zone",
|
|
6
|
-
"minimumRetriggerTime": "60",
|
|
7
|
-
"checkout": true,
|
|
8
|
-
"applicationId": 'c7058934-f1e6-4176-8730-a0bd28e8e0a9',
|
|
9
|
-
"actions": [],
|
|
10
|
-
"geofeatures": [{
|
|
11
|
-
"type": "beacon",
|
|
12
|
-
"name": "create beacon",
|
|
13
|
-
"proximityUUID": "23a01af0-232a-4518-9c0e-323fb773f5ef",
|
|
14
|
-
"location": {
|
|
15
|
-
"latitude": -37.8159544565362,
|
|
16
|
-
"longitude": 144.9723565578461
|
|
17
|
-
},
|
|
18
|
-
"beaconType": "both",
|
|
19
|
-
"major": 2321,
|
|
20
|
-
"minor": 6466,
|
|
21
|
-
"txPower": -77,
|
|
22
|
-
"macAddress": "01:17:c5:31:84:19"
|
|
23
|
-
}]
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
describe('Creating Zone ', () => {
|
|
27
|
-
it('validate Beacon', (done) => {
|
|
28
|
-
|
|
29
|
-
let createZone = new Zone(zone);
|
|
30
|
-
createZone.validate()
|
|
31
|
-
.then((output) => {
|
|
32
|
-
console.log("validate Beacon");
|
|
33
|
-
assert(true);
|
|
34
|
-
done();
|
|
35
|
-
}).catch(err => {
|
|
36
|
-
console.log("Errors found:");
|
|
37
|
-
for( let key of Object.keys(err.errors) ) {
|
|
38
|
-
console.log(err.errors[key].message);
|
|
39
|
-
}
|
|
40
|
-
assert(false);
|
|
41
|
-
done(err);
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
});
|