@bluedot-innovation/models 2.0.0-alpha.9 → 2.0.0-alpha1

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 (109) hide show
  1. package/Models.js +8 -8
  2. package/__tests__/zone/checkActions.js +64 -0
  3. package/__tests__/zone/checkAppId.js +41 -0
  4. package/__tests__/zone/checkBeacon.js +46 -0
  5. package/__tests__/zone/checkBearingFitler.js +48 -0
  6. package/__tests__/zone/checkBoundingBox.js +44 -0
  7. package/__tests__/zone/checkCalendarDateRangeFilterFitler.js +48 -0
  8. package/__tests__/zone/checkCircle.js +41 -0
  9. package/__tests__/zone/checkMRT.js +46 -0
  10. package/__tests__/zone/checkPercentageCrossedFitler.js +48 -0
  11. package/__tests__/zone/checkPolygon.js +78 -0
  12. package/__tests__/zone/checkPolyline.js +78 -0
  13. package/__tests__/zone/checkSpeedFitler.js +48 -0
  14. package/__tests__/zone/checkTimeOfDayRangeFitler.js +48 -0
  15. package/models/AdminPortalUser.js +11 -10
  16. package/models/AdminUser.js +5 -6
  17. package/models/Application.js +30 -31
  18. package/models/Beacon.js +78 -91
  19. package/models/BeaconFilter.js +12 -30
  20. package/models/BearingFilter.js +23 -45
  21. package/models/BoundingBox.js +20 -35
  22. package/models/CalendarDateRangeFilter.js +19 -33
  23. package/models/Circle.js +18 -32
  24. package/models/Contract.js +38 -37
  25. package/models/Customer.js +31 -31
  26. package/models/CustomerLogin.js +10 -9
  27. package/models/DBEvent.js +14 -13
  28. package/models/DeviceRulesRequest.js +28 -27
  29. package/models/Fence.js +13 -12
  30. package/models/GeoFence.js +14 -12
  31. package/models/Geofeature.js +18 -16
  32. package/models/MessageAction.js +16 -30
  33. package/models/NotificationLogEntry.js +8 -7
  34. package/models/POILocation.js +7 -6
  35. package/models/POILookup.js +9 -8
  36. package/models/POIResult.js +8 -7
  37. package/models/PartnerCustomer.js +13 -12
  38. package/models/PartnerPasswordReset.js +9 -8
  39. package/models/PartnerUser.js +11 -10
  40. package/models/Partners.js +12 -11
  41. package/models/PercentageCrossedFilter.js +15 -29
  42. package/models/Polygon.js +19 -33
  43. package/models/Polyline.js +19 -34
  44. package/models/RuleRequestAggregation.js +15 -14
  45. package/models/SimpleCheckInZone.js +21 -21
  46. package/models/SingleUseToken.js +8 -7
  47. package/models/SpeedFilter.js +19 -38
  48. package/models/TestDevice.js +12 -11
  49. package/models/TestDeviceCluster.js +10 -9
  50. package/models/TestInstance.js +10 -9
  51. package/models/TestScenario.js +10 -9
  52. package/models/TimeOfDayRange.js +16 -16
  53. package/models/TimeOfDayRangeFilter.js +18 -34
  54. package/models/URLAction.js +34 -0
  55. package/models/Zone.js +274 -84
  56. package/models/ZoneUIState.js +18 -18
  57. package/package.json +7 -20
  58. package/schemas/Point.js +13 -10
  59. package/.eslintrc.js +0 -6
  60. package/.gitlab-ci.yml +0 -43
  61. package/.nyc_output/.gitkeep +0 -0
  62. package/README.MD +0 -36
  63. package/__tests__/action/message/messageAction.data.json +0 -5
  64. package/__tests__/action/message/messageAction.rules.json +0 -3
  65. package/__tests__/action/message/messageAction.spec.js +0 -61
  66. package/__tests__/action/url/urlAction.data.json +0 -4
  67. package/__tests__/action/url/urlAction.rules.json +0 -3
  68. package/__tests__/action/url/urlAction.spec.js +0 -62
  69. package/__tests__/dailyStats/checkDailyStats.js +0 -30
  70. package/__tests__/filter/beacon/beaconFilter.data.json +0 -1
  71. package/__tests__/filter/beacon/beaconFilter.rules.json +0 -3
  72. package/__tests__/filter/beacon/beaconFilter.spec.js +0 -1
  73. package/__tests__/filter/bearing/bearingFilter.data.json +0 -5
  74. package/__tests__/filter/bearing/bearingFilter.rules.json +0 -3
  75. package/__tests__/filter/bearing/bearingFilter.spec.js +0 -95
  76. package/__tests__/filter/calendarDateRange/calendarDateRangeFilter.data.json +0 -5
  77. package/__tests__/filter/calendarDateRange/calendarDateRangeFilter.rules.json +0 -3
  78. package/__tests__/filter/calendarDateRange/calendarDateRangeFilter.spec.js +0 -62
  79. package/__tests__/filter/percentageCrossed/percentageCrossedFilter.data.json +0 -5
  80. package/__tests__/filter/percentageCrossed/percentageCrossedFilter.rules.json +0 -3
  81. package/__tests__/filter/percentageCrossed/percentageCrossedFilter.spec.js +0 -62
  82. package/__tests__/filter/speed/speedFilter.data.json +0 -5
  83. package/__tests__/filter/speed/speedFilter.rules.json +0 -3
  84. package/__tests__/filter/speed/speedFilter.spec.js +0 -73
  85. package/__tests__/filter/timeOfDayRange/timeOfDayRange.data.json +0 -5
  86. package/__tests__/filter/timeOfDayRange/timeOfDayRange.rules.json +0 -3
  87. package/__tests__/filter/timeOfDayRange/timeOfDayRange.spec.js +0 -73
  88. package/__tests__/geofeature/beacon/beacon.data.json +0 -12
  89. package/__tests__/geofeature/beacon/beacon.rules.json +0 -13
  90. package/__tests__/geofeature/beacon/beacon.spec.js +0 -95
  91. package/__tests__/geofeature/boundingBox/boundingBox.data.json +0 -12
  92. package/__tests__/geofeature/boundingBox/boundingBox.rules.json +0 -3
  93. package/__tests__/geofeature/boundingBox/boundingBox.spec.js +0 -61
  94. package/__tests__/geofeature/circle/circle.data.json +0 -9
  95. package/__tests__/geofeature/circle/circle.rules.json +0 -3
  96. package/__tests__/geofeature/circle/circle.spec.js +0 -62
  97. package/__tests__/geofeature/polygon/polygon.data.json +0 -46
  98. package/__tests__/geofeature/polygon/polygon.rules.json +0 -3
  99. package/__tests__/geofeature/polygon/polygon.spec.js +0 -61
  100. package/__tests__/geofeature/polyline/polyline.data.json +0 -46
  101. package/__tests__/geofeature/polyline/polyline.rules.json +0 -3
  102. package/__tests__/geofeature/polyline/polyline.spec.js +0 -61
  103. package/__tests__/zone/zone.action.spec.js +0 -50
  104. package/__tests__/zone/zone.data.json +0 -154
  105. package/__tests__/zone/zone.filter.spec.js +0 -50
  106. package/__tests__/zone/zone.geofeatures.spec.js +0 -74
  107. package/__tests__/zone/zone.spec.js +0 -98
  108. package/models/DailyStats.js +0 -28
  109. package/models/UrlAction.js +0 -51
@@ -0,0 +1,48 @@
1
+ let assert = require('assert');
2
+ let Zone = require('../../models/Zone');
3
+ let uuidv1 = require('uuid/v1');
4
+
5
+ let zone = {
6
+ "_id": uuidv1,
7
+ "name": "TDD zone",
8
+ "minimumRetriggerTime": "60",
9
+ "checkout": true,
10
+ "applicationId": 'c7058934-f1e6-4176-8730-a0bd28e8e0a9',
11
+ "filter": [
12
+ {
13
+ "type" : "timeOfDayRange",
14
+ "fromTime" : 112,
15
+ "toTime" : 552
16
+ }
17
+ ],
18
+ "actions": [],
19
+ "geofeatures": [{
20
+ "type":"circle",
21
+ "name":"circle with 15m radius",
22
+ "center": {
23
+ "latitude": -37.8186454,
24
+ "longitude": 144.979882
25
+ },
26
+ "radius": 15
27
+ }]
28
+ };
29
+
30
+ describe('Creating Zone ', () => {
31
+ it('validate TimeOfDayRangeFilter', (done) => {
32
+
33
+ let createZone = new Zone(zone);
34
+ createZone.validate()
35
+ .then((output) => {
36
+ console.log("validate TimeOfDayRangeFilter: ");
37
+ assert(true);
38
+ done();
39
+ }).catch(err => {
40
+ console.log("Errors found:");
41
+ for( let key of Object.keys(err.errors) ) {
42
+ console.log(err.errors[key].message);
43
+ }
44
+ assert(false);
45
+ done(err);
46
+ });
47
+ });
48
+ });
@@ -2,24 +2,25 @@
2
2
  * Copyright : Bluedot Innovations.
3
3
  */
4
4
 
5
- let mongoose = require('mongoose')
6
- let Enums = require('@bluedot-innovation/enums')
5
+ var mongoose = require('mongoose');
6
+ var Enums = require('@bluedot-innovation/enums');
7
7
 
8
- let AdminPortalUser = mongoose.model('AdminPortalUser', new mongoose.Schema(
8
+ var 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
- )
21
+ collection : 'adminPortalUser'
22
+ }
23
+ )
24
+ );
24
25
 
25
- module.exports = AdminPortalUser
26
+ module.exports = AdminPortalUser;
@@ -3,9 +3,8 @@
3
3
  * Copyright : Bluedot Innovations.
4
4
  * Owner :
5
5
  */
6
- let mongoose = require('mongoose')
7
- let AdminUser = mongoose.model('AdminUser', new mongoose.Schema({},
8
- { collection: 'AdminUser' }
9
- ))
10
-
11
- module.exports = AdminUser
6
+ var mongoose = require('mongoose');
7
+ var AdminUser = mongoose.model('AdminUser', new mongoose.Schema({},
8
+ { collection : 'AdminUser' }
9
+ ));
10
+ module.exports = AdminUser;
@@ -3,37 +3,36 @@
3
3
  * Copyright : Bluedot Innovations.
4
4
  * Owner :
5
5
  */
6
+ var mongoose = require('mongoose');
7
+ var Enums = require('@bluedot-innovation/enums');
8
+ Schema = mongoose.Schema;
6
9
 
7
- let mongoose = require('mongoose')
8
- let Enums = require('@bluedot-innovation/enums')
9
- let Schema = mongoose.Schema
10
-
11
- let ApplicationSchema = new mongoose.Schema({
12
- _id: {type: String},
13
- _class: {type: String, default: 'au.com.bluedot.application.model.client.Application'},
14
- state: {type: String, default: Enums.StateEnum.active, select: false},
15
- nextRuleUpdateInterval: {type: Number, select: false},
16
- nextRuleUpdateIntervalFormatted: {type: String, required: true},
17
- lastUpdateTime: {type: Date, select: false},
18
- creationTime: {type: Date, select: false},
19
- 'administrator': {type: String, select: false},
20
- enableDataAnonymisation: {type: Boolean, select: false},
21
- apiKey: String,
22
- dataSource: {type: String, select: false, default: 'openApi'},
23
- name: {type: String},
24
- packageName: {type: String},
25
- customerId: String,
26
- firebaseApiKey: String,
27
- lastPushSync: Date,
28
- webhook: {
29
- url: String,
30
- enabled: Boolean,
31
- params: {}
10
+ var ApplicationSchema = new mongoose.Schema({
11
+ _id : {type: String},
12
+ _class : {type: String, default:"au.com.bluedot.application.model.client.Application"},
13
+ state : {type: String, default : Enums.StateEnum.active, select: false},
14
+ nextRuleUpdateInterval: {type: Number, select: false},
15
+ nextRuleUpdateIntervalFormatted: {type:String, required: true},
16
+ lastUpdateTime: {type: Date, select: false},
17
+ creationTime: {type: Date, select: false},
18
+ "administrator" : {type: String, select: false},
19
+ enableDataAnonymisation: {type: Boolean, select: false},
20
+ apiKey: String,
21
+ dataSource: {type:String, select: false, default : 'openApi'},
22
+ name: {type: String},
23
+ packageName: {type: String},
24
+ customerId : String,
25
+ firebaseApiKey: String,
26
+ lastPushSync: Date,
27
+ webhook : {
28
+ url: String,
29
+ enabled: Boolean,
30
+ params: {}
31
+ },
32
+ configurationParameters:{type: Schema.Types.Mixed, default: null}
32
33
  },
33
- configurationParameters: {type: Schema.Types.Mixed, default: null}
34
- },
35
- {collection: 'application'})
36
-
37
- let Application = mongoose.model('Application', ApplicationSchema)
34
+ { collection : 'application' }
35
+ );
36
+ var Application = mongoose.model('Application', ApplicationSchema);
38
37
 
39
- module.exports = Application
38
+ module.exports = Application;
package/models/Beacon.js CHANGED
@@ -1,106 +1,93 @@
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')
1
+ let mongoose = require('mongoose');
2
+ let StateEnum = require('@bluedot-innovation/enums').StateEnum;
3
+ let uuidv1 = require('uuid/v1');
4
+ let Point = require('../schemas/Point');
5
5
 
6
- let schema = {
7
- guid: {type: String, default: uuidv4},
8
- name: {type: String, required: [true, 'name is required. ']},
9
- longitude: {
10
- type: Number,
11
- required: true,
12
- validate: [{validator: validateLongitude, msg: 'Longitude is required (insert format here)'}]
6
+ let BeaconSchema = new mongoose.Schema({
7
+ guid : { type: String, default: uuidv1 },
8
+ type : { type: String },
9
+ name : { type: String, required: [true, 'name is required. '] },
10
+ description : { type: String, default: '' },
11
+ creationTime : { type: Date, default: Date.now },
12
+ lastUpdateTime : { type: Date, default: Date.now },
13
+ state : { type: String, default : StateEnum.active, select: false },
14
+ major : { type: Number },
15
+ minor : { type: Number },
16
+ txPower : { type: Number, default: 1 },
17
+ macAddress : { type: String },
18
+ proximityUUID : { type: String },
19
+ beaconType : { type: String },
20
+ location : { type: Point },
21
+ proximity : { type: String, default: 'Far', validate: validateBeacons }
13
22
  },
14
- latitude: {
15
- type: Number,
16
- required: true,
17
- validate: [{validator: validateLatitude, msg: 'Latitude is required (insert format here)'}]
18
- },
19
- description: {type: String, default: ''},
20
- lastUpdateTime: {type: Date},
21
- state: {type: String, default: StateEnum.active},
22
- major: {type: Number, validate: [{validator: validateMajorMinor, msg: 'Major needs to be within range(1-65535)'}]},
23
- minor: {type: Number, validate: [{validator: validateMajorMinor, msg: 'Minor needs to be within range(1-65535)'}]},
24
- txPower: {type: Number},
25
- macAddress: {type: String},
26
- proximityUUID: {type: String},
27
- beaconType: {
28
- type: String,
29
- required: true,
30
- validate: {
31
- isAsync: true,
32
- validator: validateBeaconType,
33
- msg: 'Async validation. Not used'
34
- }
35
- },
36
- location: {type: Point},
37
- proximity: {type: String, default: 'Far'}
38
- }
23
+ {
24
+ _id : false,
25
+ versionKey : false
26
+ }
27
+ );
39
28
 
40
- let BeaconSchema = new mongoose.Schema(schema)
29
+ function validateBeacons() {
30
+ let beaconType = this.beaconType;
31
+ let major = this.major;
32
+ let minor = this.minor;
33
+ let macAddress = this.macAddress;
34
+ let proximityUUID = this.proximityUUID;
35
+ //let proximity = this.proximity;
41
36
 
42
- BeaconSchema.add({
43
- type:
44
- {type: String, required: true}
45
- })
37
+ let errorList = '';
46
38
 
47
- // mongoose validator helper plugin
48
- BeaconSchema.post('validate', function (doc) {
49
- console.debug('Beacon Schema post validate hook')
50
- this.lastUpdateTime = Date.now()
51
- Object.assign(this.errors || {}, this.errors || {}, this.customErrors)
52
- })
39
+ if(!beaconType) {
40
+ errorList = errorList + "Beacon should have a beaconType field. ";
41
+ } else {
42
+ if(beaconType == 'iOS' || beaconType == 'both') {
43
+ if(!proximityUUID) {
44
+ errorList = errorList + "Beacon should have a proximityUUID field. ";
45
+ }
53
46
 
54
- function validateMajorMinor (v) {
55
- 'use strict'
56
- return v >= 1 && v <= 65535
57
- }
47
+ if(!proximityUUID) {
48
+ errorList = errorList + "Beacon should have a proximityUUID field. ";
49
+ } else {
50
+ let proximityRegex = new RegExp("^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$");
51
+ if(!proximityRegex.test(proximityUUID)) {
52
+ errorList = errorList + proximityUUID + ' is not a valid ID.';
53
+ }
54
+ }
58
55
 
59
- function validateLatitude (longitude) {
60
- 'use strict'
61
- let regex = new RegExp(/^[-+]?([1-8]?\d(\.\d+)?|90(\.0+)?)$/gi)
62
- return regex.test(longitude)
63
- }
56
+ if(!major) {
57
+ errorList = errorList + "Beacon should have a major field. ";
58
+ } else if (major < 0 || major > 65535) {
59
+ errorList = errorList + "Beacon major should be within the range 0 to 65535. ";
60
+ }
64
61
 
65
- function validateLongitude (latitude) {
66
- 'use strict'
67
- let regex = new RegExp(/^[-+]?(180(\.0+)?|((1[0-7]\d)|([1-9]?\d))(\.\d+)?)$/gi)
68
- return regex.test(latitude)
69
- }
62
+ if(!minor) {
63
+ errorList = errorList + "Beacon should have a minor field. ";
64
+ } else if (minor < 0 || minor > 65535) {
65
+ errorList = errorList + "Beacon minor should be within the range 0 to 65535. ";
66
+ }
67
+ }
70
68
 
71
- function validateBeaconType (v, cb) {
72
- 'use strict'
73
- let magicCallback = cb
74
- const beaconType = v
75
- const minor = this.minor
76
- const major = this.major
77
- const macAddress = this.macAddress
78
- const txPower = this.txPower
69
+ if(beaconType == 'android' || beaconType == 'both') {
70
+ if(!macAddress) {
71
+ errorList = errorList + "Beacon should have macAddress field. ";
72
+ } else {
73
+ let macAddressRegex = new RegExp(/^([0-9a-f]{1,2}[\.:-]){5}([0-9a-f]{1,2})$/i);
74
+ if(!macAddressRegex.test(macAddress)) {
75
+ errorList = errorList + macAddress + ' is not a valid macAddress. ';
76
+ }
77
+ }
78
+ }
79
+ }
79
80
 
80
- let androidRegex = new RegExp(/(android)/ig)
81
- let iosRegex = new RegExp(/(ios)/ig)
82
- let bothRegex = new RegExp(/(both)/ig)
81
+ /*if(proximity != 'Far' && proximity != 'Near' || proximity != 'Immediate'){
82
+ errorList = errorList + "";
83
+ }*/
83
84
 
84
- if (androidRegex.test(beaconType)) {
85
- magicCallback((!!macAddress && !!txPower), 'Beacon type "Android" must have both mac address and tx power values')
86
- } else if (iosRegex.test(beaconType)) {
87
- magicCallback((!!minor && !!major), 'Beacon type "IOS" must have both minor and major values')
88
- } else if (bothRegex.test(beaconType)) {
89
- magicCallback((!!minor && !!major && !!txPower && !!macAddress), 'Beacon type "Both" must have all of minor, major, tx power, and mac address values')
90
- } else {
91
- magicCallback(true)
85
+ if(errorList != '') {
86
+ console.log(errorList);
87
+ throw new Error(errorList);
92
88
  }
93
89
  }
94
90
 
95
- // optional mongoose
96
- module.exports = (mongooseInstance) => {
97
- let Beacon
98
- if (mongooseInstance) {
99
- Beacon = mongooseInstance.model('Beacon', BeaconSchema)
100
- } else {
101
- Beacon = mongoose.model('Beacon', BeaconSchema)
102
- }
91
+ let Beacon = mongoose.model('Beacon', BeaconSchema);
103
92
 
104
- return Beacon
105
- }
106
- module.exports.beaconSchema = schema
93
+ module.exports = Beacon;
@@ -3,39 +3,21 @@
3
3
  * Copyright : Bluedot Innovations.
4
4
  * Owner :
5
5
  */
6
- let mongoose = require('mongoose')
6
+ var mongoose = require('mongoose');
7
+ Schema = mongoose.Schema;
7
8
 
8
- let schema = {
9
- '_class': {type: String, default: 'au.com.bluedot.application.spring.filter.spatial.BeaconFilter'},
10
- 'beacon': {},
11
- 'guid': String,
12
- 'type': {type: String, default: 'beacon'}
13
- }
14
-
15
- let BeaconFilterSchema = new mongoose.Schema(
16
- schema,
9
+ var BeaconFilterSchema = new mongoose.Schema(
10
+ {
11
+ "_class" : {type:String, default : "au.com.bluedot.application.spring.filter.spatial.BeaconFilter"},
12
+ "beacon" : {},
13
+ "guid" : String,
14
+ "type" : {type:String, default: "beacon"}
15
+ },
17
16
  {
18
17
  _id: false
19
18
  }
20
- )
21
-
22
- BeaconFilterSchema.add({
23
- type:
24
- {type: String, required: true}
25
- })
19
+ );
26
20
 
27
- let BeaconFilter = mongoose.model('BeaconFilter', BeaconFilterSchema)
28
-
29
- // optional mongoose
30
- module.exports = (mongooseInstance) => {
31
- let BeaconFilter
32
- if (mongooseInstance) {
33
- BeaconFilter = mongooseInstance.model('BeaconFilter', BeaconFilterSchema)
34
- } else {
35
- BeaconFilter = mongoose.model('BeaconFilter', BeaconFilterSchema)
36
- }
21
+ var BeaconFilter = mongoose.model('BeaconFilter', BeaconFilterSchema);
37
22
 
38
- return BeaconFilter
39
- }
40
- module.exports = BeaconFilter
41
- module.exports.beaconFilterChema = schema
23
+ module.exports = BeaconFilter;
@@ -1,58 +1,36 @@
1
- let mongoose = require('mongoose')
2
- let uuidv4 = require('uuid/v4')
3
-
4
- const schema = {
5
- guid: {type: String, default: uuidv4},
6
- fromAngle: {type: Number, required: [true, 'fromAngle is required. '], min: 0, max: 359},
7
- toAngle: {type: Number, required: true, min: 0, max: 359, validate: {validator: validateAngles, msg: 'default error message'}}
8
- }
9
-
10
- const BearingFilterSchema = new mongoose.Schema(
11
- schema,
1
+ let mongoose = require('mongoose');
2
+ let uuidv1 = require('uuid/v1');
3
+
4
+ let BearingSchema = new mongoose.Schema({
5
+ guid : { type: String, default: uuidv1 },
6
+ type : { type: String, required: true, default: "bearingFilter" },
7
+ fromAngle : { type: Number, required: [true, 'fromAngle is required. '], min: 0, max: 359 },
8
+ toAngle : { type: Number, required: [true, 'fromAngle is required. '], min: 0, max: 359, validate: validateAngles }
9
+ },
12
10
  {
13
- _id: false,
14
- versionKey: false
15
- })
16
-
17
- BearingFilterSchema.add({
18
- type:
19
- {type: String, required: true}
20
- })
21
-
22
- function validateAngles (toAngle, cb) {
23
- let magicCallback = cb
24
- let fromAngle = this.fromAngle
25
-
26
- if (!toAngle && toAngle !== 0) {
27
- return magicCallback(false, 'toAngle is required')
11
+ _id : false,
12
+ versionKey : false
28
13
  }
14
+ );
29
15
 
30
- if (toAngle === fromAngle) {
31
- return magicCallback(false, 'fromAngle and toAngle cannot be the same')
32
- }
16
+ function validateAngles(toAngle){
17
+ let fromAngle = this.fromAngle;
33
18
 
34
19
  if (fromAngle > toAngle) {
35
20
  if ((fromAngle - toAngle) <= 270) {
36
- return magicCallback(false, 'From Angle and To Angle must best separated by at least 90 degrees in both directions')
21
+ throw new Error("From Angle and To Angle must best separated by at least 90 degrees in both directions. ");
37
22
  }
38
- }
39
- if (toAngle > fromAngle) {
23
+ } else if (toAngle > fromAngle) {
40
24
  if (((toAngle - fromAngle) < 90) || (((toAngle - fromAngle) > 270))) {
41
- return magicCallback(false, 'From Angle and To Angle must best separated by at least 90 degrees in both directions')
25
+ throw new Error("From Angle and To Angle must best separated by at least 90 degrees in both directions. ");
42
26
  }
43
- }
44
- magicCallback(true)
45
- }
46
-
47
- // optional mongoose
48
- module.exports = (mongooseInstance) => {
49
- let BearingFilter
50
- if (mongooseInstance) {
51
- BearingFilter = mongooseInstance.model('BearingFilter', BearingFilterSchema)
52
27
  } else {
53
- BearingFilter = mongoose.model('BearingFilter', BearingFilterSchema)
28
+ throw new Error("fromAngle and toAngle cannot be same. ");
54
29
  }
55
30
 
56
- return BearingFilter
57
31
  }
58
- module.exports.bearingFilterSchema = schema
32
+
33
+
34
+ let Bearing = mongoose.model('Bearing', BearingSchema);
35
+
36
+ module.exports = Bearing;
@@ -1,39 +1,24 @@
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')
1
+ let mongoose = require('mongoose');
2
+ let StateEnum = require('@bluedot-innovation/enums').StateEnum;
3
+ let uuidv1 = require('uuid/v1');
4
+ let Point = require('../schemas/Point');
5
5
 
6
- const schema = {
7
- guid: {type: String, default: uuidv4},
8
- name: {type: String, required: [true, 'name is required. ']},
9
- northEast: {type: Point, required: [true, 'northEast is required. ']},
10
- southWest: {type: Point, required: [true, 'southWest is required. ']},
11
- creationTime: {type: Date, default: Date.now},
12
- lastUpdateTime: {type: Date, default: Date.now},
13
- state: {type: String, default: StateEnum.active, select: false}
14
- }
15
-
16
- const BoundingBoxSchema = new mongoose.Schema(
17
- schema,
6
+ let BoundingBoxSchema = new mongoose.Schema({
7
+ guid : { type: String, default: uuidv1 },
8
+ type : { type: String, default: "MultiLineString" },
9
+ name : { type: String, required: [true, 'name is required. '] },
10
+ northEast : { type: Point, required: [true, 'northEast is required. '] },
11
+ southWest : { type: Point, required: [true, 'southWest is required. '] },
12
+ creationTime : { type: Date, default: Date.now },
13
+ lastUpdateTime : { type: Date, default: Date.now },
14
+ state : { type: String, default : StateEnum.active, select: false }
15
+ },
18
16
  {
19
- _id: false,
20
- versionKey: false
21
- })
22
-
23
- BoundingBoxSchema.add({
24
- type:
25
- {type: String, required: true}
26
- })
27
-
28
- // optional mongoose
29
- module.exports = (mongooseInstance) => {
30
- let BoundingBox
31
- if (mongooseInstance) {
32
- BoundingBox = mongooseInstance.model('BoundingBox', BoundingBoxSchema)
33
- } else {
34
- BoundingBox = mongoose.model('BoundingBox', BoundingBox)
17
+ _id : false,
18
+ versionKey : false
35
19
  }
20
+ );
21
+
22
+ let BoundingBox = mongoose.model('BoundingBox', BoundingBoxSchema);
36
23
 
37
- return BoundingBox
38
- }
39
- module.exports.boundingBoxSchema = schema
24
+ module.exports = BoundingBox;
@@ -1,41 +1,27 @@
1
- let mongoose = require('mongoose')
2
- let uuidv4 = require('uuid/v4')
1
+ let mongoose = require('mongoose');
2
+ let uuidv1 = require('uuid/v1');
3
3
 
4
- let schema = {
5
- guid: {type: String, default: uuidv4},
6
- startDate: {type: Date, required: [true, 'startDate is required. ']},
7
- endDate: {type: Date, required: [true, 'endDate is required. '], validate: validateDateRange}
8
- }
9
- let CalendarDateRangeSchema = new mongoose.Schema(
10
- schema,
4
+ let DateFilterSchema = new mongoose.Schema({
5
+ guid : { type: String, default: uuidv1 },
6
+ type : { type: String, required: true, default: "dateFilter" },
7
+ startDate : { type: Date, required: [true, 'startDate is required. '] },
8
+ endDate : { type: Date, required: [true, 'endDate is required. '], validate: validateDateRange }
9
+ },
11
10
  {
12
- _id: false,
13
- versionKey: false
14
- })
15
-
16
- CalendarDateRangeSchema.add({
17
- type:
18
- {type: String, required: true}
19
- })
11
+ _id : false,
12
+ versionKey : false
13
+ }
14
+ );
20
15
 
21
- function validateDateRange (endDate) {
22
- let startDate = new Date(this.startDate)
23
- endDate = new Date(endDate)
16
+ function validateDateRange(endDate){
17
+ let startDate = new Date(this.startDate);
18
+ endDate = new Date(endDate);
24
19
 
25
- if (endDate < startDate) {
26
- throw new Error('startDate has to be less than endDate. ')
20
+ if(endDate < startDate) {
21
+ throw new Error("startDate has to be less than endDate. ");
27
22
  }
28
23
  }
29
24
 
30
- // optional mongoose
31
- module.exports = (mongooseInstance) => {
32
- let CalendarDateRange
33
- if (mongooseInstance) {
34
- CalendarDateRange = mongooseInstance.model('CalendarDateRange', CalendarDateRangeSchema)
35
- } else {
36
- CalendarDateRange = mongoose.model('CalendarDateRange', CalendarDateRangeSchema)
37
- }
25
+ let DateFilter = mongoose.model('DateFilter', DateFilterSchema);
38
26
 
39
- return CalendarDateRange
40
- }
41
- module.exports.calendarDateRangeSchema = schema
27
+ module.exports = DateFilter;