@bluedot-innovation/models 4.0.0 → 5.0.1

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