@bluedot-innovation/models 3.1.1 → 4.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.
Files changed (160) hide show
  1. package/Models.js +10 -55
  2. package/models/AdminPortalUser.js +11 -10
  3. package/models/AdminUser.js +10 -0
  4. package/models/Application.js +38 -0
  5. package/models/ApplicationNotificationAction.js +30 -0
  6. package/models/ApplicationUsage.js +11 -0
  7. package/models/Beacon.js +32 -84
  8. package/models/BeaconFilter.js +23 -0
  9. package/models/BearingFilter.js +19 -0
  10. package/models/BoundingBox.js +17 -0
  11. package/models/Circle.js +21 -0
  12. package/models/ConfigurationParameters.js +20 -0
  13. package/models/Contract.js +38 -37
  14. package/models/Customer.js +38 -0
  15. package/models/CustomerLogin.js +10 -9
  16. package/models/DBEvent.js +14 -13
  17. package/models/DailyStats.js +7 -7
  18. package/models/DateRangeFilter.js +20 -0
  19. package/models/DeviceRulesRequest.js +28 -27
  20. package/models/Fence.js +21 -0
  21. package/models/FormattedBeacon.js +16 -0
  22. package/models/FormattedCircle.js +12 -0
  23. package/models/FormattedConditions.js +11 -0
  24. package/models/FormattedDateRange.js +11 -0
  25. package/models/FormattedPercentageCrossed.js +12 -0
  26. package/models/FormattedPoint.js +10 -0
  27. package/models/FormattedPolygon.js +11 -0
  28. package/models/FormattedPolyline.js +11 -0
  29. package/models/FormattedRectangle.js +12 -0
  30. package/models/FormattedTimeActive.js +17 -0
  31. package/models/FormattedZone.js +28 -0
  32. package/models/GeoFence.js +23 -0
  33. package/models/Geofeature.js +26 -0
  34. package/models/MessageAction.js +26 -28
  35. package/models/MonthlyStats.js +19 -35
  36. package/models/NotificationLogEntry.js +8 -7
  37. package/models/POILocation.js +7 -6
  38. package/models/POILookup.js +9 -8
  39. package/models/POIResult.js +8 -7
  40. package/models/PartnerCustomer.js +13 -12
  41. package/models/PartnerPasswordReset.js +9 -8
  42. package/models/PartnerUser.js +11 -10
  43. package/models/Partners.js +12 -11
  44. package/models/PercentageCrossedFilter.js +19 -0
  45. package/models/Point.js +20 -0
  46. package/models/Polygon.js +18 -0
  47. package/models/Polyline.js +18 -0
  48. package/models/PropertyMapping.js +17 -0
  49. package/models/Reference.js +19 -0
  50. package/models/RuleRequestAggregation.js +17 -33
  51. package/models/SequenceFilter.js +18 -0
  52. package/models/SimpleCheckInZone.js +29 -0
  53. package/models/SingleUseToken.js +8 -7
  54. package/models/SoundAction.js +28 -0
  55. package/models/SpeedFilter.js +19 -0
  56. package/models/TestDevice.js +12 -11
  57. package/models/TestDeviceCluster.js +10 -9
  58. package/models/TestInstance.js +10 -9
  59. package/models/TestScenario.js +10 -9
  60. package/models/TimeOfDayRange.js +16 -16
  61. package/models/TimeOfDayRangeFilter.js +19 -0
  62. package/models/URLAction.js +31 -0
  63. package/models/VibrationAction.js +28 -0
  64. package/models/ZoneUIState.js +18 -18
  65. package/models/property.js +25 -0
  66. package/package-lock.json.bak +170 -0
  67. package/package.json +6 -30
  68. package/.eslintrc.js +0 -42
  69. package/.gitlab-ci.yml +0 -43
  70. package/CHANGELOG.md +0 -152
  71. package/README.MD +0 -36
  72. package/__tests__/account/account.data.json +0 -12
  73. package/__tests__/account/account.rules.js +0 -8
  74. package/__tests__/account/account.spec.js +0 -83
  75. package/__tests__/action/message/messageAction.data.json +0 -5
  76. package/__tests__/action/message/messageAction.rules.json +0 -3
  77. package/__tests__/action/message/messageAction.spec.js +0 -61
  78. package/__tests__/action/url/urlAction.data.json +0 -4
  79. package/__tests__/action/url/urlAction.rules.json +0 -3
  80. package/__tests__/action/url/urlAction.spec.js +0 -74
  81. package/__tests__/beacon/beacon.data.json +0 -15
  82. package/__tests__/beacon/beacon.rules.json +0 -13
  83. package/__tests__/beacon/beacon.spec.js +0 -104
  84. package/__tests__/condition/beacon/beaconFilter.data.json +0 -1
  85. package/__tests__/condition/beacon/beaconFilter.rules.json +0 -3
  86. package/__tests__/condition/beacon/beaconFilter.spec.js +0 -1
  87. package/__tests__/condition/dayRange/dayRange.data.json +0 -5
  88. package/__tests__/condition/dayRange/dayRange.rules.json +0 -3
  89. package/__tests__/condition/dayRange/dayRange.spec.js +0 -74
  90. package/__tests__/condition/percentageCrossed/travelPath.data.json +0 -5
  91. package/__tests__/condition/percentageCrossed/travelPath.rules.json +0 -3
  92. package/__tests__/condition/percentageCrossed/travelPath.spec.js +0 -62
  93. package/__tests__/condition/speed/speed.data.json +0 -5
  94. package/__tests__/condition/speed/speed.rules.json +0 -3
  95. package/__tests__/condition/speed/speed.spec.js +0 -73
  96. package/__tests__/condition/timeActive/timeActive.data.json +0 -5
  97. package/__tests__/condition/timeActive/timeActive.rules.json +0 -7
  98. package/__tests__/condition/timeActive/timeActive.spec.js +0 -94
  99. package/__tests__/condition/travelDirection/travelDirection.data.json +0 -5
  100. package/__tests__/condition/travelDirection/travelDirection.rules.json +0 -3
  101. package/__tests__/condition/travelDirection/travelDirection.spec.js +0 -132
  102. package/__tests__/dailyStats/checkDailyStats.js +0 -31
  103. package/__tests__/geofeature/boundingBox/boundingBox.data.json +0 -12
  104. package/__tests__/geofeature/boundingBox/boundingBox.rules.json +0 -3
  105. package/__tests__/geofeature/boundingBox/boundingBox.spec.js +0 -78
  106. package/__tests__/geofeature/circle/circle.data.json +0 -9
  107. package/__tests__/geofeature/circle/circle.rules.json +0 -3
  108. package/__tests__/geofeature/circle/circle.spec.js +0 -71
  109. package/__tests__/geofeature/geoline/geoline.data.json +0 -46
  110. package/__tests__/geofeature/geoline/geoline.rules.json +0 -3
  111. package/__tests__/geofeature/geoline/geoline.spec.js +0 -70
  112. package/__tests__/geofeature/polygon/polygon.data.json +0 -46
  113. package/__tests__/geofeature/polygon/polygon.rules.json +0 -3
  114. package/__tests__/geofeature/polygon/polygon.spec.js +0 -127
  115. package/__tests__/geofeature/zoneBeacon/zoneBeacon.data.json +0 -16
  116. package/__tests__/geofeature/zoneBeacon/zoneBeacon.rules.json +0 -13
  117. package/__tests__/geofeature/zoneBeacon/zoneBeacon.spec.js +0 -62
  118. package/__tests__/monthlyStats/monthlyStats.data.json +0 -29
  119. package/__tests__/monthlyStats/monthlyStats.spec.js +0 -66
  120. package/__tests__/project/project.data.json +0 -18
  121. package/__tests__/project/project.rules.json +0 -9
  122. package/__tests__/project/project.spec.js +0 -81
  123. package/__tests__/ruleRequestAggregation/ruleRequestAggregation.data.json +0 -8
  124. package/__tests__/ruleRequestAggregation/ruleRequestAggregation.spec.js +0 -69
  125. package/__tests__/setup.js +0 -7
  126. package/__tests__/user/user.data.js +0 -19
  127. package/__tests__/user/user.rules.js +0 -8
  128. package/__tests__/user/user.spec.js +0 -130
  129. package/__tests__/utils/utils.spec.js +0 -24
  130. package/__tests__/zone/zone.action.spec.js +0 -50
  131. package/__tests__/zone/zone.condition.spec.js +0 -76
  132. package/__tests__/zone/zone.data.json +0 -157
  133. package/__tests__/zone/zone.geofeatures.spec.js +0 -75
  134. package/__tests__/zone/zone.spec.js +0 -134
  135. package/constants/errorMessages.js +0 -2
  136. package/helpers.js +0 -102
  137. package/models/Account.js +0 -50
  138. package/models/Project.js +0 -55
  139. package/models/UrlAction.js +0 -46
  140. package/models/User.js +0 -61
  141. package/models/Zone.js +0 -123
  142. package/models/conditions/DayRange.js +0 -52
  143. package/models/conditions/Speed.js +0 -42
  144. package/models/conditions/TimeActive.js +0 -50
  145. package/models/conditions/TravelDirection.js +0 -67
  146. package/models/conditions/TravelPath.js +0 -36
  147. package/models/geofeatures/BoundingBox.js +0 -44
  148. package/models/geofeatures/Circle.js +0 -39
  149. package/models/geofeatures/Geoline.js +0 -34
  150. package/models/geofeatures/Polygon.js +0 -45
  151. package/models/geofeatures/ZoneBeacon.js +0 -28
  152. package/schemas/MultiLineStringGeometry.js +0 -14
  153. package/schemas/Point.js +0 -13
  154. package/schemas/PointGeometry.js +0 -14
  155. package/schemas/PolygonGeometry.js +0 -14
  156. package/schemas/ProjectPermission.js +0 -21
  157. package/schemas/Webhook.js +0 -22
  158. package/utils/index.js +0 -39
  159. package/validators/checkDistanceBetweenVertices.js +0 -21
  160. package/yarn.lock +0 -2796
package/models/Zone.js DELETED
@@ -1,123 +0,0 @@
1
- /**
2
- * Created by Andrew on 17/10/2017.
3
- * Copyright : Bluedot Innovations.
4
- * Owner :
5
- */
6
-
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('./geofeatures/Circle').circleSchema
13
- let boundingBoxSchema = require('./geofeatures/BoundingBox').boundingBoxSchema
14
- let geolineSchema = require('./geofeatures/Geoline').geolineSchema
15
- let polygonSchema = require('./geofeatures/Polygon').polygonSchema
16
- let beaconSchema = require('./geofeatures/ZoneBeacon').beaconSchema
17
-
18
- // Conditions
19
- let speedRawSchema = require('./conditions/Speed').rawSchema
20
- let dayRangeRawSchema = require('./conditions/DayRange').rawSchema
21
- let travelDirectionRawSchema = require('./conditions/TravelDirection').rawSchema
22
- let travelPathRawSchema = require('./conditions/TravelPath').rawSchema
23
- let timeActiveRawSchema = require('./conditions/TimeActive').rawSchema
24
-
25
- let uuidv4 = require('uuid/v4')
26
- let patcher = require('mongoose-json-patch')
27
- let helpers = require('../helpers')
28
-
29
- // ////// //
30
- // Schema //
31
- // ////// //
32
-
33
- let customDataValidators = [
34
- {validator: helpers.validateCustomData, msg: 'CustomData key should have alpha numeric and _ characters only'},
35
- {validator: helpers.checkDuplicateKeys, msg: 'CustomData key should be unique'},
36
- ];
37
-
38
- let actionSchema = new Schema({},
39
- { discriminatorKey: 'type', _id: false })
40
-
41
- let conditionSchema = new Schema({},
42
- { discriminatorKey: 'type', _id: false })
43
-
44
- let geofeatureSchema = new Schema({},
45
- { discriminatorKey: 'type', _id: false })
46
-
47
- let zoneSchema = new Schema({
48
- _id: {type: String, default: uuidv4},
49
- name: {type: String, required: true},
50
- minimumRetriggerTime: {
51
- type: Number,
52
- required: true,
53
- min: 60,
54
- max: 359940,
55
- validate: {
56
- validator: Number.isInteger,
57
- message: '{VALUE} is not a number'
58
- }
59
- },
60
- tags: {type: [String]},
61
- conditions: {
62
- type: [conditionSchema]
63
- },
64
- actions: {
65
- type: [actionSchema]
66
- },
67
- geofeatures: {
68
- type: [geofeatureSchema],
69
- required: true
70
- },
71
- triggerOnExit: {type: Boolean, default: false},
72
- customData: {type: Schema.Types.Mixed, validate: customDataValidators},
73
- creationTime: {type: Date, default: Date.now},
74
- lastUpdateTime: {type: Date, default: Date.now},
75
- projectId: {type: String, required: [true, 'projectId is required']},
76
- state: {type: String, default: StateEnum.active, select: false},
77
- accountId: {type: String, required: true, validate: {isAsync: false, validator: helpers.validateUUIDv4, msg: 'default error message'}}
78
- }, {collection: 'zone'})
79
-
80
- // TODO: Test patcher and include for other schemas if required
81
- zoneSchema.plugin(patcher)
82
-
83
- zoneSchema.path('actions').discriminator('url', new Schema(urlActionSchema, {_id: false}))
84
- zoneSchema.path('actions').discriminator('message', new Schema(messageActionSchema, {_id: false}))
85
-
86
- zoneSchema.path('conditions').discriminator('dayRange', new Schema(dayRangeRawSchema, {_id: false}))
87
- zoneSchema.path('conditions').discriminator('speed', new Schema(speedRawSchema, {_id: false}))
88
- zoneSchema.path('conditions').discriminator('timeActive', new Schema(timeActiveRawSchema, {_id: false}))
89
- zoneSchema.path('conditions').discriminator('travelDirection', new Schema(travelDirectionRawSchema, {_id: false}))
90
- zoneSchema.path('conditions').discriminator('travelPath', new Schema(travelPathRawSchema, {_id: false}))
91
-
92
- zoneSchema.path('geofeatures').discriminator('beacon', new Schema(beaconSchema))
93
- zoneSchema.path('geofeatures').discriminator('circle', new Schema(circleSchema))
94
- zoneSchema.path('geofeatures').discriminator('polygon', new Schema(polygonSchema))
95
- zoneSchema.path('geofeatures').discriminator('geoline', new Schema(geolineSchema))
96
- zoneSchema.path('geofeatures').discriminator('boundingBox', new Schema(boundingBoxSchema))
97
-
98
- zoneSchema.pre('validate', function(next) {
99
- Promise.all([
100
- new Promise((resolve, reject) => helpers.checkConditionsSuitableForBeacon(this, resolve)),
101
- new Promise((resolve, reject) => helpers.checkMinimumGeofeaturesValidForZone(this, resolve))
102
- ]).then(results => {
103
- for( let result of results ) {
104
- if( result )
105
- return next(result)
106
- }
107
- next()
108
- });
109
- })
110
-
111
- // optional mongoose
112
- const model = (mongooseInstance) => {
113
- let Zone
114
- if (mongooseInstance) {
115
- Zone = mongooseInstance.model('Zone', zoneSchema)
116
- } else {
117
- Zone = mongoose.model('Zone', zoneSchema)
118
- }
119
-
120
- return Zone
121
- }
122
-
123
- module.exports = { Model: model, Schema: zoneSchema }
@@ -1,52 +0,0 @@
1
- let mongoose = require('mongoose')
2
- let uuidv4 = require('uuid/v4')
3
-
4
- let schema = {
5
- startDate: {type: Date},
6
- endDate: {type: Date}
7
- }
8
-
9
- let DayRangeConditionSchema = new mongoose.Schema(schema, {
10
- _id: false,
11
- versionKey: false
12
- })
13
-
14
- DayRangeConditionSchema.add({
15
- type: {type: String, required: true, validate: {isAsync: true, validator: validateDateRange}}
16
- })
17
-
18
- function validateDateRange (type, callback) {
19
- let startDate = this.startDate;
20
- let endDate = this.endDate;
21
-
22
- if (!startDate && !endDate) {
23
- return callback(false, `Must have a startDate, endDate, or both.`)
24
- }
25
-
26
- if (this.startDate) {
27
- startDate = new Date(this.startDate)
28
- }
29
-
30
- if (endDate) {
31
- endDate = new Date(endDate)
32
- }
33
-
34
- if (startDate && endDate && endDate < startDate) {
35
- return callback(false, `startDate has to be less than endDate.`)
36
- }
37
- callback(true)
38
- }
39
-
40
- // optional mongoose
41
- let model = (mongooseInstance) => {
42
- let DayRangeCondition
43
- if (mongooseInstance) {
44
- DayRangeCondition = mongooseInstance.model('DayRangeCondition', DayRangeConditionSchema)
45
- } else {
46
- DayRangeCondition = mongoose.model('DayRangeCondition', DayRangeConditionSchema)
47
- }
48
-
49
- return DayRangeCondition
50
- }
51
- // Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
52
- module.exports = { Model: model, Schema: DayRangeConditionSchema, rawSchema: schema }
@@ -1,42 +0,0 @@
1
- let mongoose = require('mongoose')
2
- let uuidv4 = require('uuid/v4')
3
-
4
- let schema = {
5
- minimumSpeed: {type: Number, required: [true, 'minimumSpeed is required. '], min: 0},
6
- maximumSpeed: {type: Number, required: true, validate: {isAsync: true, validator: validateMaxSpeed, msg: 'default error message'}}
7
- }
8
- let SpeedConditionSchema = new mongoose.Schema(schema, {
9
- _id: false,
10
- versionKey: false
11
- })
12
-
13
- SpeedConditionSchema.add({
14
- type: {type: String, required: true}
15
- })
16
-
17
- function validateMaxSpeed (v, magicCallback) {
18
- let minSpeed = this.minimumSpeed
19
- let maxSpeed = v
20
- let speedDifference = maxSpeed - minSpeed
21
-
22
- if (maxSpeed < 5) {
23
- magicCallback(false, 'Maximum speed has to be at least 5 m/s')
24
- } else if (speedDifference < 5) {
25
- magicCallback(false, 'Maximum speed has to be at least 5 m/s greater than minimum speed')
26
- }
27
- magicCallback(true)
28
- }
29
-
30
- // optional mongoose
31
- let model = (mongooseInstance) => {
32
- let SpeedCondition
33
- if (mongooseInstance) {
34
- SpeedCondition = mongooseInstance.model('SpeedCondition', SpeedConditionSchema)
35
- } else {
36
- SpeedCondition = mongoose.model('SpeedCondition', SpeedConditionSchema)
37
- }
38
-
39
- return SpeedCondition
40
- }
41
- // Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
42
- module.exports = { Model: model, Schema: SpeedConditionSchema, rawSchema: schema }
@@ -1,50 +0,0 @@
1
- let mongoose = require('mongoose')
2
- let uuidv4 = require('uuid/v4')
3
-
4
- let schema = {
5
- fromTime: {type: String, required: [true, 'time is required. '], validate: {isAsync: true, validator: validateTimeHHmmssFormat}},
6
- toTime: {type: String, required: true, validate: [{isAsync: true, validator: validateTime}, {isAsync: true, validator: validateTimeHHmmssFormat}]}
7
- }
8
- let TimeActiveConditionSchema = new mongoose.Schema(schema, {
9
- _id: false,
10
- versionKey: false
11
- })
12
-
13
- TimeActiveConditionSchema.add({
14
- type: {type: String, required: true}
15
- })
16
-
17
- function validateTime (toTime, magicCallback) {
18
- let fromTime = this.fromTime
19
-
20
- if (fromTime === toTime) {
21
- return magicCallback(false, 'fromTime and toTime cannot be the same')
22
- }
23
- return magicCallback(true)
24
- }
25
-
26
- function validateTimeHHmmssFormat(time, magicCallback) {
27
- const expression = `^(2[0-3]|[01]?[0-9]):([0-5]?[0-9]):([0-5]?[0-9])$`
28
- const regex = new RegExp(expression, 'i')
29
-
30
- if(!regex.test(time)){
31
- return magicCallback(false, 'time format must be hh:mm:ss')
32
- }
33
-
34
- return magicCallback(true)
35
- }
36
-
37
- // optional mongoose
38
- let model = (mongooseInstance) => {
39
- let TimeActiveCondition
40
- if (mongooseInstance) {
41
- TimeActiveCondition = mongooseInstance.model('TimeActiveCondition', TimeActiveConditionSchema)
42
- } else {
43
- TimeActiveCondition = mongoose.model('TimeActiveCondition', TimeActiveConditionSchema)
44
- }
45
-
46
- return TimeActiveCondition
47
- }
48
-
49
- // Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
50
- module.exports = { Model: model, Schema: TimeActiveConditionSchema, rawSchema: schema }
@@ -1,67 +0,0 @@
1
- let mongoose = require('mongoose')
2
- let uuidv4 = require('uuid/v4')
3
-
4
- const schema = {
5
- fromAngle: {type: Number, required: [true, 'fromAngle is required. '], min: 0, max: 359},
6
- toAngle: {type: Number, required: true, min: 0, max: 359, validate: {isAsync: true, validator: validateAngles, msg: 'default error message'}}
7
- }
8
-
9
- const TravelDirectionConditionSchema = new mongoose.Schema(schema, {
10
- _id: false,
11
- versionKey: false
12
- })
13
-
14
- // For discriminator key
15
- TravelDirectionConditionSchema.add({
16
- type: {type: String, required: true}
17
- })
18
-
19
- function validateAngles (toAngle, callback) {
20
- let fromAngle = this.fromAngle
21
-
22
- if (toAngle === undefined) {
23
- return callback(false, 'toAngle is required')
24
- }
25
-
26
- if (fromAngle === undefined) {
27
- return callback(false, 'fromAngle is required')
28
- }
29
-
30
- if (!isMinimumNinetyApart(fromAngle, toAngle)) {
31
- return callback(false, 'From Angle and To Angle must be separated by at least 90 degrees in either direction')
32
- }
33
-
34
- callback(true)
35
- }
36
-
37
- function isMinimumNinetyApart (fromAngle, toAngle) {
38
- const fromAngleWrapped = parseInt(fromAngle) + 360
39
- const toAngleWrapped = parseInt(toAngle) + 360
40
- const lessThan90 = Math.abs(fromAngle - toAngle) < 90
41
- const fromAngleLarger = fromAngle > toAngle
42
- const lessThan90Wrapped = fromAngleLarger
43
- ? (toAngleWrapped - fromAngle) < 90
44
- : (fromAngleWrapped - toAngle) < 90
45
-
46
- if (lessThan90 || lessThan90Wrapped) { return false }
47
- return true
48
- }
49
-
50
- // optional mongoose
51
- let model = (mongooseInstance) => {
52
- let TravelDirectionCondition
53
- if (mongooseInstance) {
54
- TravelDirectionCondition = mongooseInstance.model('TravelDirectionCondition', TravelDirectionConditionSchema)
55
- } else {
56
- TravelDirectionCondition = mongoose.model('TravelDirectionCondition', TravelDirectionConditionSchema)
57
- }
58
-
59
- return TravelDirectionCondition
60
- }
61
- // Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
62
- module.exports = {
63
- Model: model,
64
- Schema: TravelDirectionConditionSchema,
65
- rawSchema: schema,
66
- isMinimumNinetyApart
67
- }
@@ -1,36 +0,0 @@
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 }
@@ -1,44 +0,0 @@
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 }
@@ -1,39 +0,0 @@
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 }
@@ -1,34 +0,0 @@
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 }
@@ -1,45 +0,0 @@
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 }
@@ -1,28 +0,0 @@
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 }
@@ -1,14 +0,0 @@
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 DELETED
@@ -1,13 +0,0 @@
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
@@ -1,14 +0,0 @@
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
@@ -1,14 +0,0 @@
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
@@ -1,21 +0,0 @@
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
@@ -1,22 +0,0 @@
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
- enabled: {type: Boolean, required: [true, 'enabled is required']},
12
- headers: {type: mongoose.Schema.Types.Mixed}
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