@bluedot-innovation/models 4.0.0 → 5.0.0
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 +43 -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 +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__/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 +74 -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 +62 -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 +73 -0
- package/__tests__/condition/timeActive/timeActive.data.json +5 -0
- package/__tests__/condition/timeActive/timeActive.rules.json +7 -0
- package/__tests__/condition/timeActive/timeActive.spec.js +94 -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 +132 -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 +78 -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 +127 -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 +62 -0
- package/__tests__/monthlyStats/monthlyStats.data.json +29 -0
- package/__tests__/monthlyStats/monthlyStats.spec.js +66 -0
- package/__tests__/project/project.data.json +18 -0
- package/__tests__/project/project.rules.json +9 -0
- package/__tests__/project/project.spec.js +92 -0
- package/__tests__/ruleRequestAggregation/ruleRequestAggregation.data.json +8 -0
- package/__tests__/ruleRequestAggregation/ruleRequestAggregation.spec.js +69 -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 +24 -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 +134 -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 +28 -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 +55 -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 +46 -0
- package/models/User.js +61 -0
- package/models/Zone.js +126 -0
- package/models/ZoneUIState.js +18 -18
- package/models/conditions/DayRange.js +52 -0
- package/models/conditions/Speed.js +42 -0
- package/models/conditions/TimeActive.js +50 -0
- package/models/conditions/TravelDirection.js +67 -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/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/Webhook.js +27 -0
- package/utils/index.js +39 -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
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// In V2 this is becoming "Travel Path" condition
|
|
2
|
+
let mongoose = require('mongoose')
|
|
3
|
+
let uuidv4 = require('uuid/v4')
|
|
4
|
+
|
|
5
|
+
let schema = {
|
|
6
|
+
minimumGeofeaturesCrossed: {
|
|
7
|
+
type: Number,
|
|
8
|
+
required: [true, 'minimumGeofeaturesCrossed is required.'],
|
|
9
|
+
min: 2
|
|
10
|
+
},
|
|
11
|
+
timeOutSeconds: {type: Number, required: [true, 'timeOutSeconds is required. '], min: 60, max: 86400},
|
|
12
|
+
sequential: {type: Boolean, default: false}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
let TravelPathConditionSchema = new mongoose.Schema(schema, {
|
|
16
|
+
_id: false,
|
|
17
|
+
versionKey: false
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
TravelPathConditionSchema.add({
|
|
21
|
+
type: {type: String, required: true}
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
// optional mongoose
|
|
25
|
+
let model = (mongooseInstance) => {
|
|
26
|
+
let TravelPathCondition
|
|
27
|
+
if (mongooseInstance) {
|
|
28
|
+
TravelPathCondition = mongooseInstance.model('TravelPathCondition', TravelPathConditionSchema)
|
|
29
|
+
} else {
|
|
30
|
+
TravelPathCondition = mongoose.model('TravelPathCondition', TravelPathConditionSchema)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return TravelPathCondition
|
|
34
|
+
}
|
|
35
|
+
// Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
|
|
36
|
+
module.exports = { Model: model, Schema: TravelPathConditionSchema, rawSchema: schema }
|
|
@@ -0,0 +1,44 @@
|
|
|
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
|
+
let helpers = require('../../helpers')
|
|
6
|
+
|
|
7
|
+
const schema = {
|
|
8
|
+
_id: {type: String, default: uuidv4},
|
|
9
|
+
geometry: {type: {}},
|
|
10
|
+
name: {type: String, required: [true, 'name is required.']},
|
|
11
|
+
color: String,
|
|
12
|
+
northEast: {type: Point, required: [true, 'northEast is required.']},
|
|
13
|
+
southWest: {
|
|
14
|
+
type: Point, required: [true, 'southWest is required.'],
|
|
15
|
+
validate: {
|
|
16
|
+
isAsync: true,
|
|
17
|
+
validator: helpers.checkIsDifferent('northEast'),
|
|
18
|
+
message: 'northEast and southWest cannot be the same'
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const BoundingBoxSchema = new mongoose.Schema(schema, {
|
|
24
|
+
_id: false,
|
|
25
|
+
versionKey: false
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
BoundingBoxSchema.add({
|
|
29
|
+
type: {type: String, required: true}
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
// optional mongoose
|
|
33
|
+
let model = (mongooseInstance) => {
|
|
34
|
+
let BoundingBox
|
|
35
|
+
if (mongooseInstance) {
|
|
36
|
+
BoundingBox = mongooseInstance.model('BoundingBox', BoundingBoxSchema)
|
|
37
|
+
} else {
|
|
38
|
+
BoundingBox = mongoose.model('BoundingBox', BoundingBoxSchema)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return BoundingBox
|
|
42
|
+
}
|
|
43
|
+
// Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
|
|
44
|
+
module.exports = { Model: model, Schema: BoundingBoxSchema, boundingBoxSchema: schema }
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
let mongoose = require('mongoose')
|
|
2
|
+
let StateEnum = require('@bluedot-innovation/enums').StateEnum
|
|
3
|
+
let Point = require('../../schemas/Point')
|
|
4
|
+
let uuidv4 = require('uuid/v4')
|
|
5
|
+
|
|
6
|
+
let schema = {
|
|
7
|
+
_id: {type: String, default: uuidv4},
|
|
8
|
+
geometry: {type: {}},
|
|
9
|
+
name: {type: String, required: [true, 'name is required. ']},
|
|
10
|
+
color: String,
|
|
11
|
+
radius: {type: Number, required: [true, 'radius is required. '], min: 5},
|
|
12
|
+
center: {type: Point, required: [true, 'center is required. ']}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
let CircleSchema = new mongoose.Schema(
|
|
16
|
+
schema,
|
|
17
|
+
{
|
|
18
|
+
_id: false,
|
|
19
|
+
__v: false
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
CircleSchema.add({
|
|
23
|
+
type:
|
|
24
|
+
{type: String, required: true}
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
// optional mongoose
|
|
28
|
+
let model = (mongooseInstance) => {
|
|
29
|
+
let Circle
|
|
30
|
+
if (mongooseInstance) {
|
|
31
|
+
Circle = mongooseInstance.model('Circle', CircleSchema)
|
|
32
|
+
} else {
|
|
33
|
+
Circle = mongoose.model('Circle', CircleSchema)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return Circle
|
|
37
|
+
}
|
|
38
|
+
// Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
|
|
39
|
+
module.exports = { Model: model, Schema: CircleSchema, circleSchema: schema }
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
let mongoose = require('mongoose')
|
|
2
|
+
let StateEnum = require('@bluedot-innovation/enums').StateEnum
|
|
3
|
+
let Point = require('../../schemas/Point')
|
|
4
|
+
let uuidv4 = require('uuid/v4')
|
|
5
|
+
|
|
6
|
+
const schema = {
|
|
7
|
+
_id: {type: String, default: uuidv4},
|
|
8
|
+
geometry: {type: {}},
|
|
9
|
+
name: {type: String, required: [true, 'name is required. ']},
|
|
10
|
+
vertices: {type: [Point], required: [true, 'vertices are required. ']}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const GeolineSchema = new mongoose.Schema(schema, {
|
|
14
|
+
_id: false,
|
|
15
|
+
versionKey: false
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
GeolineSchema.add({
|
|
19
|
+
type: {type: String, required: true}
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
// optional mongoose
|
|
23
|
+
let model = (mongooseInstance) => {
|
|
24
|
+
let Geoline
|
|
25
|
+
if (mongooseInstance) {
|
|
26
|
+
Geoline = mongooseInstance.model('Geoline', GeolineSchema)
|
|
27
|
+
} else {
|
|
28
|
+
Geoline = mongoose.model('Geoline', GeolineSchema)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return Geoline
|
|
32
|
+
}
|
|
33
|
+
// Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
|
|
34
|
+
module.exports = { Model: model, Schema: GeolineSchema, geolineSchema: schema }
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const mongoose = require('mongoose')
|
|
2
|
+
const StateEnum = require('@bluedot-innovation/enums').StateEnum
|
|
3
|
+
const Point = require('../../schemas/Point')
|
|
4
|
+
const uuidv4 = require('uuid/v4')
|
|
5
|
+
const checkDistanceBetweenVertices = require('../../validators/checkDistanceBetweenVertices')
|
|
6
|
+
const { VERTICES_TOO_CLOSE, CANT_HAVE_THREE_OR_MORE_VERTICES } = require('../../constants/errorMessages')
|
|
7
|
+
const helpers = require('../../helpers')
|
|
8
|
+
|
|
9
|
+
const schema = {
|
|
10
|
+
_id: {type: String, default: uuidv4},
|
|
11
|
+
geometry: {type: {}},
|
|
12
|
+
name: {type: String, required: [true, 'name is required.']},
|
|
13
|
+
color: String,
|
|
14
|
+
vertices: {
|
|
15
|
+
type: [Point], required: [true, 'vertices is required.'],
|
|
16
|
+
validate: [{
|
|
17
|
+
validator: helpers.threeOrMoreVertices,
|
|
18
|
+
msg: CANT_HAVE_THREE_OR_MORE_VERTICES
|
|
19
|
+
}, {
|
|
20
|
+
validator: checkDistanceBetweenVertices,
|
|
21
|
+
msg: VERTICES_TOO_CLOSE
|
|
22
|
+
}]
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const PolygonSchema = new mongoose.Schema(schema, {
|
|
27
|
+
_id: false,
|
|
28
|
+
versionKey: false
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
PolygonSchema.add({type: {type: String, required: true}})
|
|
32
|
+
|
|
33
|
+
// optional mongoose
|
|
34
|
+
let model = (mongooseInstance) => {
|
|
35
|
+
let Polygon
|
|
36
|
+
if (mongooseInstance) {
|
|
37
|
+
Polygon = mongooseInstance.model('Polygon', PolygonSchema)
|
|
38
|
+
} else {
|
|
39
|
+
Polygon = mongoose.model('Polygon', PolygonSchema)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return Polygon
|
|
43
|
+
}
|
|
44
|
+
// Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
|
|
45
|
+
module.exports = { Model: model, Schema: PolygonSchema, polygonSchema: schema }
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const cloneDeep = require('lodash.clonedeep')
|
|
2
|
+
const mongoose = require('mongoose')
|
|
3
|
+
const beaconSchema = require('../Beacon').beaconSchema
|
|
4
|
+
const BeaconProximityEnum = require('@bluedot-innovation/enums').BeaconProximityEnum
|
|
5
|
+
|
|
6
|
+
const schema = cloneDeep(beaconSchema)
|
|
7
|
+
|
|
8
|
+
delete schema.state
|
|
9
|
+
delete schema.creationTime
|
|
10
|
+
delete schema.lastUpdateTime
|
|
11
|
+
delete schema.__v
|
|
12
|
+
|
|
13
|
+
schema.proximity = {
|
|
14
|
+
type: String,
|
|
15
|
+
default: BeaconProximityEnum.FAR,
|
|
16
|
+
enum: [BeaconProximityEnum.NEAR, BeaconProximityEnum.IMMEDIATE, BeaconProximityEnum.FAR]
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const ZoneBeaconSchema = new mongoose.Schema(schema)
|
|
20
|
+
|
|
21
|
+
// optional mongoose
|
|
22
|
+
let model = (mongooseInstance) => {
|
|
23
|
+
const instance = mongooseInstance || mongoose
|
|
24
|
+
return instance.model('ZoneBeacon', ZoneBeaconSchema)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
|
|
28
|
+
module.exports = { Model: model, Schema: ZoneBeaconSchema, beaconSchema: schema }
|
package/package.json
CHANGED
|
@@ -1,15 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bluedot-innovation/models",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "",
|
|
3
|
+
"version": "5.0.0",
|
|
5
4
|
"main": "Models.js",
|
|
6
5
|
"scripts": {
|
|
7
|
-
"
|
|
6
|
+
"lint": "./node_modules/.bin/eslint -c .eslintrc.js ./models/*.js ./__tests__/**/*.js ./__tests__/**/**/*.js ./schemas/*.js",
|
|
7
|
+
"test": "mocha --require __tests__/setup __tests__/**/*.spec.js __tests__/**/**/*.spec.js",
|
|
8
|
+
"test:coverage": "nyc mocha --require __tests__/setup __tests__/**/*.spec.js __tests__/**/**/*.spec.js",
|
|
9
|
+
"test:coverage-check": "nyc check-coverage --lines 90 --functions 90 --branches 70",
|
|
10
|
+
"test:ci": "npm run lint && npm run test:coverage-check && npm test"
|
|
8
11
|
},
|
|
9
|
-
"author": "",
|
|
10
12
|
"license": "UNLICENSED",
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"babel-eslint": "^8.2.3",
|
|
15
|
+
"chai": "^4.1.2",
|
|
16
|
+
"describe": "*",
|
|
17
|
+
"eslint": "^4.12.0",
|
|
18
|
+
"eslint-config-prettier": "^2.9.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-prettier": "^2.6.0",
|
|
23
|
+
"eslint-plugin-promise": "^3.6.0",
|
|
24
|
+
"eslint-plugin-standard": "^3.0.1",
|
|
25
|
+
"mocha": "^4.0.1",
|
|
26
|
+
"nyc": "^11.3.0",
|
|
27
|
+
"prettier": "^1.13.5",
|
|
28
|
+
"sinon": "^4.1.2"
|
|
29
|
+
},
|
|
11
30
|
"dependencies": {
|
|
12
|
-
"
|
|
13
|
-
"
|
|
31
|
+
"@bluedot-innovation/enums": "2.1.1",
|
|
32
|
+
"deep-equal": "^1.0.1",
|
|
33
|
+
"fast-deep-equal": "^2.0.1",
|
|
34
|
+
"lodash.clonedeep": "4.5.0",
|
|
35
|
+
"mongoose": "^4.13.9",
|
|
36
|
+
"mongoose-json-patch": "^1.1.1",
|
|
37
|
+
"uuid": "^3.1.0"
|
|
14
38
|
}
|
|
15
39
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
let mongoose = require('mongoose')
|
|
2
|
+
|
|
3
|
+
let MultiLineStringSchema = new mongoose.Schema(
|
|
4
|
+
{
|
|
5
|
+
type: {type: String, match: /MultiLineString/},
|
|
6
|
+
coordinates: [[[{type: Number, required: [true, 'longitude is required. '], min: -180, max: 180},
|
|
7
|
+
{type: Number, required: [true, 'latitude is required. '], min: -90, max: 90}]]]
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
_id: false,
|
|
11
|
+
__v: false
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
module.exports = MultiLineStringSchema
|
package/schemas/Point.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
let mongoose = require('mongoose')
|
|
2
|
+
|
|
3
|
+
let PointSchema = new mongoose.Schema({
|
|
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
|
+
})
|
|
12
|
+
|
|
13
|
+
module.exports = PointSchema
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
let mongoose = require('mongoose')
|
|
2
|
+
|
|
3
|
+
let PointGeometrySchema = new mongoose.Schema(
|
|
4
|
+
{
|
|
5
|
+
type: {type: String, match: /Point/},
|
|
6
|
+
coordinates: [{type: Number, required: [true, 'longitude is required. '], min: -180, max: 180},
|
|
7
|
+
{type: Number, required: [true, 'latitude is required. '], min: -90, max: 90}]
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
_id: false,
|
|
11
|
+
__v: false
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
module.exports = PointGeometrySchema
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
let mongoose = require('mongoose')
|
|
2
|
+
|
|
3
|
+
let PolygonGeometrySchema = new mongoose.Schema(
|
|
4
|
+
{
|
|
5
|
+
type: {type: String, match: /Polygon/},
|
|
6
|
+
coordinates: [[[{type: Number, required: [true, 'longitude is required. '], min: -180, max: 180},
|
|
7
|
+
{type: Number, required: [true, 'latitude is required. '], min: -90, max: 90}]]]
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
_id: false,
|
|
11
|
+
__v: false
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
module.exports = PolygonGeometrySchema
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const mongoose = require('mongoose')
|
|
2
|
+
const helpers = require('../helpers')
|
|
3
|
+
const PermissionsEnum = require('@bluedot-innovation/enums').PermissionsEnum
|
|
4
|
+
|
|
5
|
+
const ProjectPermissionSchema = new mongoose.Schema({
|
|
6
|
+
permissionLevel: {
|
|
7
|
+
type: String,
|
|
8
|
+
required: true,
|
|
9
|
+
enum: [PermissionsEnum.READ_WRITE, PermissionsEnum.READ]
|
|
10
|
+
},
|
|
11
|
+
projectId: {
|
|
12
|
+
type: String,
|
|
13
|
+
required: true,
|
|
14
|
+
validate: {isAsync: false, validator: helpers.validateUUIDv4, msg: 'projectId not in UUID v4 format'}
|
|
15
|
+
}
|
|
16
|
+
}, {
|
|
17
|
+
_id: false,
|
|
18
|
+
__v: false
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
module.exports = ProjectPermissionSchema
|
|
@@ -0,0 +1,27 @@
|
|
|
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, 'URL is required'], validate: {isAsync: false, validator: validateUrl, msg: 'Please enter a valid URL'}},
|
|
11
|
+
headers: {type: mongoose.Schema.Types.Mixed, validate: { isAsync: false, validator: validateHeaderlength, msg: 'Header object can only have 1 key <-> value pair' }}
|
|
12
|
+
}, {
|
|
13
|
+
_id: false
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
function validateUrl (url) {
|
|
17
|
+
const expression = 'https?:\\/\\/(www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{2,256}\\.[a-z]{2,4}\\b([-a-zA-Z0-9@:%_\\+.~#?&//=]*)'
|
|
18
|
+
const regex = new RegExp(expression, 'i')
|
|
19
|
+
return regex.test(url)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// https://bluedotinnovation.atlassian.net/browse/BP-1500 -- Limiting headers to 1
|
|
23
|
+
function validateHeaderlength (headers) {
|
|
24
|
+
return Object.keys(headers).length <= 1
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
module.exports = WebhookSchema
|
package/utils/index.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
var equal = require('deep-equal');
|
|
2
|
+
|
|
3
|
+
// Used for converting a mongoose object to a javascript object
|
|
4
|
+
const clean = (item) => {
|
|
5
|
+
return item && JSON.parse(JSON.stringify(item))
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// Reduces decimals to `n`
|
|
9
|
+
// e.g. reduceDecimals(1.2345, 2)
|
|
10
|
+
// returns 1.23
|
|
11
|
+
const trimDecimals = (num, n) => {
|
|
12
|
+
const scaleFactor = Math.pow(10, n)
|
|
13
|
+
return Math.floor(num * scaleFactor)/scaleFactor
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const notSameThreeInARow = function(list) {
|
|
17
|
+
const cleanList = clean(list)
|
|
18
|
+
let hasSame = false;
|
|
19
|
+
|
|
20
|
+
for (var i = 0; i < cleanList.length; i++) {
|
|
21
|
+
const itemA = cleanList[i]
|
|
22
|
+
const itemB = cleanList[i - 1]
|
|
23
|
+
const itemC = cleanList[i - 2]
|
|
24
|
+
|
|
25
|
+
if (equal(itemA, itemB)) {
|
|
26
|
+
hasSame = true;
|
|
27
|
+
}
|
|
28
|
+
if (equal(itemA, itemC)) {
|
|
29
|
+
hasSame = true;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return !hasSame;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
module.exports = {
|
|
36
|
+
clean,
|
|
37
|
+
trimDecimals,
|
|
38
|
+
notSameThreeInARow,
|
|
39
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
var equal = require('deep-equal');
|
|
2
|
+
const { notSameThreeInARow, trimDecimals } = require('../utils');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* checkDistanceBetweenVertices -
|
|
6
|
+
* Returns boolean signalling whether or not enough space between points in
|
|
7
|
+
* polygons and geolines. Checks closeness by checking if the same when trimmed
|
|
8
|
+
* to 6 decimal places
|
|
9
|
+
*/
|
|
10
|
+
const checkDistanceBetweenVertices = function(vertices) {
|
|
11
|
+
const trimmedVertices = vertices.map(({latitude, longitude}) => {
|
|
12
|
+
return {
|
|
13
|
+
latitude: trimDecimals(latitude, 6),
|
|
14
|
+
longitude: trimDecimals(longitude, 6)
|
|
15
|
+
}
|
|
16
|
+
})
|
|
17
|
+
return notSameThreeInARow(trimmedVertices)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
module.exports = checkDistanceBetweenVertices;
|