@bluedot-innovation/models 2.0.0-alpha.5 → 2.0.0-alpha.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/.gitlab-ci.yml +4 -2
  2. package/.nyc_output/.gitkeep +0 -0
  3. package/README.MD +10 -6
  4. package/__tests__/filter/beacon/beaconFilter.data.json +1 -0
  5. package/__tests__/filter/beacon/beaconFilter.rules.json +3 -0
  6. package/__tests__/filter/beacon/beaconFilter.spec.js +1 -0
  7. package/__tests__/{zone → geofeature/beacon}/beacon.spec.js +3 -3
  8. package/__tests__/{zone → geofeature/boundingBox}/boundingBox.spec.js +3 -3
  9. package/__tests__/geofeature/circle/circle.data.json +9 -0
  10. package/__tests__/{zone → geofeature/circle}/circle.spec.js +15 -24
  11. package/__tests__/{zone → geofeature/polygon}/polygon.spec.js +3 -3
  12. package/__tests__/{zone → geofeature/polyline}/polyline.spec.js +3 -3
  13. package/__tests__/zone/zone.action.spec.js +50 -0
  14. package/__tests__/zone/zone.filter.spec.js +50 -0
  15. package/__tests__/zone/zone.geofeatures.spec.js +74 -0
  16. package/__tests__/zone/zone.spec.js +5 -8
  17. package/models/Beacon.js +9 -13
  18. package/models/BeaconFilter.js +25 -6
  19. package/models/BearingFilter.js +14 -7
  20. package/models/BoundingBox.js +14 -7
  21. package/models/CalendarDateRangeFilter.js +13 -7
  22. package/models/Circle.js +14 -7
  23. package/models/MessageAction.js +13 -7
  24. package/models/PercentageCrossedFilter.js +13 -7
  25. package/models/Polygon.js +13 -6
  26. package/models/Polyline.js +15 -6
  27. package/models/SpeedFilter.js +13 -6
  28. package/models/TimeOfDayRangeFilter.js +13 -6
  29. package/models/UrlAction.js +13 -7
  30. package/models/Zone.js +45 -160
  31. package/package.json +8 -5
  32. package/__tests__/zone/checkAppId.js +0 -39
  33. package/__tests__/zone/checkBeacon.js +0 -44
  34. package/__tests__/zone/checkMRT.js +0 -44
  35. package/__tests__/zone/data/zone-with-invalid-circle.json +0 -34
  36. /package/__tests__/{zone/data → geofeature/beacon}/beacon.data.json +0 -0
  37. /package/__tests__/{zone/rules → geofeature/beacon}/beacon.rules.json +0 -0
  38. /package/__tests__/{zone/data → geofeature/boundingBox}/boundingBox.data.json +0 -0
  39. /package/__tests__/{zone/rules → geofeature/boundingBox}/boundingBox.rules.json +0 -0
  40. /package/__tests__/{zone/rules → geofeature/circle}/circle.rules.json +0 -0
  41. /package/__tests__/{zone/data → geofeature/polygon}/polygon.data.json +0 -0
  42. /package/__tests__/{zone/rules → geofeature/polygon}/polygon.rules.json +0 -0
  43. /package/__tests__/{zone/data → geofeature/polyline}/polyline.data.json +0 -0
  44. /package/__tests__/{zone/rules → geofeature/polyline}/polyline.rules.json +0 -0
  45. /package/__tests__/zone/{data/zone.data.json → zone.data.json} +0 -0
package/.gitlab-ci.yml CHANGED
@@ -25,7 +25,7 @@ test:node:8:
25
25
  tags:
26
26
  - xcode9
27
27
  script:
28
- - npm run coverage && npm test
28
+ - npm run test:coverage-check && npm test
29
29
 
30
30
  # Publish tagged versions to npm
31
31
  publish:
@@ -35,7 +35,9 @@ publish:
35
35
  only:
36
36
  - tags
37
37
  - triggers
38
- - master
38
+ #gitlab open issue: https://gitlab.com/gitlab-org/gitlab-ce/issues/27818
39
+ except:
40
+ - /^(?!.*(master)$).*$/
39
41
  script:
40
42
  - echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}'>.npmrc
41
43
  - npm publish
File without changes
package/README.MD CHANGED
@@ -15,7 +15,7 @@ Minimum test coverage enforced:
15
15
 
16
16
  To check test coverage:
17
17
 
18
- run `npm test`
18
+ run `npm test:coverage`
19
19
 
20
20
  To lint:
21
21
 
@@ -23,10 +23,14 @@ run `npm run lint`
23
23
 
24
24
  To check if your code will pass CI pipeline:
25
25
 
26
- run `npm run ci-test`
27
-
26
+ run `npm run test:ci`
27
+ aws apigateway put-integration \
28
+ --rest-api-id api-id \
29
+ --resource-id resource-id \
30
+ --http-method POST \
31
+ --type AWS \
32
+ --integration-http-method POST \
33
+ --uri arn:aws:apigateway:aws-region:lambda:path/2015-03-31/functions/arn:aws:lambda:aws-region:aws-acct-id:function:your-lambda-function-name/invocations
28
34
  To publish:
29
35
 
30
- run `npm version x.x.x`
31
-
32
- run `git push --follow-tags`
36
+ run `npm version x.x.x`
@@ -0,0 +1,3 @@
1
+ {
2
+ "requiredFields":[]
3
+ }
@@ -0,0 +1 @@
1
+ // not implemented. not sure if required
@@ -2,7 +2,7 @@ let mongoose = require('mongoose')
2
2
 
3
3
  mongoose.Promise = global.Promise
4
4
 
5
- let BeaconModel = require('../../models/Beacon')(mongoose)
5
+ let BeaconModel = require('../../../models/Beacon')(mongoose)
6
6
  let testCase = require('mocha').describe
7
7
  let assertions = require('mocha').it
8
8
  let chai = require('chai')
@@ -11,12 +11,12 @@ let assert = chai.assert
11
11
  let mocha = require('mocha')
12
12
  let beforeEach = mocha.beforeEach
13
13
 
14
- let rules = require('./rules/beacon.rules.json')
14
+ let rules = require('./beacon.rules.json')
15
15
 
16
16
  let beacon
17
17
 
18
18
  beforeEach(() => {
19
- beacon = JSON.parse(JSON.stringify(require('./data/beacon.data.json')))
19
+ beacon = JSON.parse(JSON.stringify(require('./beacon.data.json')))
20
20
  })
21
21
 
22
22
  testCase('Beacon', () => {
@@ -2,7 +2,7 @@ let mongoose = require('mongoose')
2
2
 
3
3
  mongoose.Promise = global.Promise
4
4
 
5
- let BoundingBoxModel = require('../../models/BoundingBox')(mongoose)
5
+ let BoundingBoxModel = require('../../../models/BoundingBox')(mongoose)
6
6
  let testCase = require('mocha').describe
7
7
  let assertions = require('mocha').it
8
8
  let chai = require('chai')
@@ -11,12 +11,12 @@ let assert = chai.assert
11
11
  let mocha = require('mocha')
12
12
  let beforeEach = mocha.beforeEach
13
13
 
14
- let rules = require('./rules/boundingBox.rules.json')
14
+ let rules = require('./boundingBox.rules.json')
15
15
 
16
16
  let boundingBox
17
17
 
18
18
  beforeEach(() => {
19
- boundingBox = JSON.parse(JSON.stringify(require('./data/boundingBox.data.json')))
19
+ boundingBox = JSON.parse(JSON.stringify(require('./boundingBox.data.json')))
20
20
  })
21
21
  testCase('BoundingBox', () => {
22
22
  testCase('Valid BoundingBox', () => {
@@ -0,0 +1,9 @@
1
+ {
2
+ "type": "circle",
3
+ "name": "Test Circle",
4
+ "radius": 10,
5
+ "center": {
6
+ "latitude": -37.8159544565362,
7
+ "longitude": 144.9723565578461
8
+ }
9
+ }
@@ -2,29 +2,27 @@ let mongoose = require('mongoose')
2
2
 
3
3
  mongoose.Promise = global.Promise
4
4
 
5
- let ZoneModel = require('../../models/Zone')(mongoose)
5
+ let CircleModel = require('../../../models/Circle')(mongoose)
6
6
  let testCase = require('mocha').describe
7
7
  let assertions = require('mocha').it
8
8
  let chai = require('chai')
9
9
 
10
10
  let assert = chai.assert
11
- let mocha = require('mocha')
12
- let beforeEach = mocha.beforeEach
11
+ let beforeEach = require('mocha').beforeEach
13
12
 
14
- let rules = require('./rules/circle.rules.json')
13
+ let rules = require('./circle.rules.json')
15
14
 
16
- let zone
17
- let invalidZone
15
+ let circle
18
16
 
19
17
  beforeEach(() => {
20
- zone = JSON.parse(JSON.stringify(require('./data/zone.data.json')))
21
- invalidZone = JSON.parse(JSON.stringify(require('./data/zone-with-invalid-circle.json')))
18
+ circle = JSON.parse(JSON.stringify(require('./circle.data.json')))
22
19
  })
20
+
23
21
  testCase('Circle', () => {
24
22
  testCase('Valid Circle', () => {
25
23
  assertions('should validate zone with Circle ', (done) => {
26
- let Zone = new ZoneModel(zone)
27
- Zone.validate((err, res) => {
24
+ let Circle = new CircleModel(circle)
25
+ Circle.validate((err, res) => {
28
26
  assert.notExists(res)
29
27
  assert(err === null, 'err should equals null')
30
28
  done()
@@ -33,17 +31,10 @@ testCase('Circle', () => {
33
31
  })
34
32
 
35
33
  testCase('Invalid Circle', () => {
36
- assertions('should not validate a zone with invalid Circle', (done) => {
37
- let Zone = new ZoneModel(invalidZone)
38
- Zone.validate((err, res) => {
39
- assert.exists(err, 'err object should exist')
40
- assert.isObject(err)
41
- done()
42
- })
43
- })
44
34
  assertions('should not validate a Circle with no radius', (done) => {
45
- let Zone = new ZoneModel(invalidZone)
46
- Zone.validate((err, res) => {
35
+ delete circle.radius
36
+ let Circle = new CircleModel(circle)
37
+ Circle.validate((err, res) => {
47
38
  assert.exists(err, 'err object should exist')
48
39
  assert.isObject(err)
49
40
  done()
@@ -55,13 +46,13 @@ testCase('Circle', () => {
55
46
  requiredFields.map((i) => {
56
47
  assertions(`should throw an error with property '${i}' if '${i}' is not present`, (done) => {
57
48
  // delete i from geofeatures' circle child
58
- delete zone.geofeatures[(zone.geofeatures.findIndex(x => x.type.toLowerCase() === 'circle'))][i]
59
- let Zone = new ZoneModel(zone)
60
- Zone.validate((err, res) => {
49
+ delete circle[i]
50
+ let Circle = new CircleModel(circle)
51
+ Circle.validate((err, res) => {
61
52
  assert.notExists(res)
62
53
  assert.exists(err, 'err object should exist')
63
54
  assert.isObject(err)
64
- assert.nestedProperty(err, `errors.circle.${i}`, 'error should have a radius property')
55
+ assert.nestedProperty(err, `errors.${i}`, 'error should have a radius property')
65
56
  done()
66
57
  })
67
58
  })
@@ -2,7 +2,7 @@ let mongoose = require('mongoose')
2
2
 
3
3
  mongoose.Promise = global.Promise
4
4
 
5
- let PolygonModel = require('../../models/Polygon')(mongoose)
5
+ let PolygonModel = require('../../../models/Polygon')(mongoose)
6
6
  let testCase = require('mocha').describe
7
7
  let assertions = require('mocha').it
8
8
  let chai = require('chai')
@@ -11,12 +11,12 @@ let assert = chai.assert
11
11
  let mocha = require('mocha')
12
12
  let beforeEach = mocha.beforeEach
13
13
 
14
- let rules = require('./rules/polygon.rules.json')
14
+ let rules = require('./polygon.rules.json')
15
15
 
16
16
  let polygon
17
17
 
18
18
  beforeEach(() => {
19
- polygon = JSON.parse(JSON.stringify(require('./data/polygon.data.json')))
19
+ polygon = JSON.parse(JSON.stringify(require('./polygon.data.json')))
20
20
  })
21
21
  testCase('Polygon', () => {
22
22
  testCase('Valid Polygon', () => {
@@ -2,7 +2,7 @@ let mongoose = require('mongoose')
2
2
 
3
3
  mongoose.Promise = global.Promise
4
4
 
5
- let PolylineModel = require('../../models/Polyline')(mongoose)
5
+ let PolylineModel = require('../../../models/Polyline')(mongoose)
6
6
  let testCase = require('mocha').describe
7
7
  let assertions = require('mocha').it
8
8
  let chai = require('chai')
@@ -11,12 +11,12 @@ let assert = chai.assert
11
11
  let mocha = require('mocha')
12
12
  let beforeEach = mocha.beforeEach
13
13
 
14
- let rules = require('./rules/polyline.rules.json')
14
+ let rules = require('./polyline.rules.json')
15
15
 
16
16
  let polyline
17
17
 
18
18
  beforeEach(() => {
19
- polyline = JSON.parse(JSON.stringify(require('./data/polyline.data.json')))
19
+ polyline = JSON.parse(JSON.stringify(require('./polyline.data.json')))
20
20
  })
21
21
  testCase('Polyline', () => {
22
22
  testCase('Valid Polyline', () => {
@@ -0,0 +1,50 @@
1
+ let mongoose = require('mongoose')
2
+
3
+ mongoose.Promise = global.Promise
4
+
5
+ let ZoneModel = require('../../models/Zone')(mongoose)
6
+ let testCase = require('mocha').describe
7
+ let assertions = require('mocha').it
8
+ let chai = require('chai')
9
+ let assert = chai.assert
10
+ let mocha = require('mocha')
11
+ let beforeEach = mocha.beforeEach
12
+
13
+ let zone
14
+
15
+ beforeEach(() => {
16
+ zone = JSON.parse(JSON.stringify(require('./zone.data.json')))
17
+ // remove filters as it's not tested
18
+ delete zone.filters
19
+ // remove all but 1 geofeatures as geofeatures are required
20
+ zone.geofeatures = zone.geofeatures.filter(x => x.type.match(/circle/i))
21
+ // remove customData
22
+ delete zone.customData
23
+ })
24
+
25
+ testCase('Zone - Action', () => {
26
+ testCase('Valid Zone - Action', () => {
27
+ assertions('should not throw an error when a valid action is instantiated within a zone', (done) => {
28
+ let Zone = new ZoneModel(zone)
29
+ Zone.validate((err, res) => {
30
+ assert.notExists(res)
31
+ assert(err === null, 'err equals null')
32
+ done()
33
+ })
34
+ })
35
+ })
36
+
37
+ testCase('Invalid Zone - Action', () => {
38
+ assertions('should throw an error when an invalid action is instantiated within a zone', (done) => {
39
+ delete zone.actions[1].url
40
+ let Zone = new ZoneModel(zone)
41
+ Zone.validate((err, res) => {
42
+ assert.exists(err, 'err object should exist')
43
+ assert.isObject(err)
44
+ assert('actions.1.url' in err.errors)
45
+ assert.notNestedProperty(err, `errors.geofeatures`, 'error should have a url property')
46
+ done()
47
+ })
48
+ })
49
+ })
50
+ })
@@ -0,0 +1,50 @@
1
+ let mongoose = require('mongoose')
2
+
3
+ mongoose.Promise = global.Promise
4
+
5
+ let ZoneModel = require('../../models/Zone')(mongoose)
6
+ let testCase = require('mocha').describe
7
+ let assertions = require('mocha').it
8
+ let chai = require('chai')
9
+ let assert = chai.assert
10
+ let mocha = require('mocha')
11
+ let beforeEach = mocha.beforeEach
12
+
13
+ let zone
14
+
15
+ beforeEach(() => {
16
+ zone = JSON.parse(JSON.stringify(require('./zone.data.json')))
17
+ // remove actions as it's not tested
18
+ delete zone.actions
19
+ // remove all but 1 geofeatures as geofeatures are required
20
+ zone.geofeatures = zone.geofeatures.filter(x => x.type.match(/circle/i))
21
+ // remove customData
22
+ delete zone.customData
23
+ })
24
+
25
+ testCase('Zone - Filter', () => {
26
+ testCase('Valid Zone - Filter', () => {
27
+ assertions('should not throw an error when a valid filter is instantiated within a zone', (done) => {
28
+ let Zone = new ZoneModel(zone)
29
+ Zone.validate((err, res) => {
30
+ assert.notExists(res)
31
+ assert(err === null, 'err equals null')
32
+ done()
33
+ })
34
+ })
35
+ })
36
+
37
+ testCase('Invalid Zone - Filter', () => {
38
+ assertions('should throw an error when an invalid filter is instantiated within a zone', (done) => {
39
+ delete zone.filters[0].startDate
40
+ let Zone = new ZoneModel(zone)
41
+ Zone.validate((err, res) => {
42
+ assert.exists(err, 'err object should exist')
43
+ assert.isObject(err)
44
+ assert('filters.0.startDate' in err.errors)
45
+ assert.notNestedProperty(err, `errors.geofeatures`, 'error should have a url property')
46
+ done()
47
+ })
48
+ })
49
+ })
50
+ })
@@ -0,0 +1,74 @@
1
+ let mongoose = require('mongoose')
2
+
3
+ mongoose.Promise = global.Promise
4
+
5
+ let ZoneModel = require('../../models/Zone')(mongoose)
6
+ let testCase = require('mocha').describe
7
+ let assertions = require('mocha').it
8
+ let chai = require('chai')
9
+ let assert = chai.assert
10
+ let mocha = require('mocha')
11
+ let beforeEach = mocha.beforeEach
12
+
13
+ let zone
14
+
15
+ beforeEach(() => {
16
+ zone = JSON.parse(JSON.stringify(require('./zone.data.json')))
17
+ // remove filters as it's not tested
18
+ delete zone.filters
19
+
20
+ // geofeatures are tested individually so we only need to try one in Zones' test
21
+ zone.geofeatures = zone.geofeatures.filter(x => x.type.match(/beacon/i))
22
+
23
+ // remove customData
24
+ delete zone.customData
25
+
26
+ // remove actions
27
+ delete zone.actions
28
+ })
29
+
30
+ testCase('Zone - Action', () => {
31
+ testCase('Valid Zone - Action', () => {
32
+ assertions('should not throw an error when a valid geofeature is instantiated within a zone', (done) => {
33
+ let Zone = new ZoneModel(zone)
34
+ Zone.validate((err, res) => {
35
+ assert.notExists(res)
36
+ assert(err === null, 'err equals null')
37
+ done()
38
+ })
39
+ })
40
+ })
41
+
42
+ testCase('Invalid Zone - Action', () => {
43
+ assertions('should throw an error when an invalid geofeature is instantiated within a zone', (done) => {
44
+ delete zone.geofeatures[0].name
45
+ let Zone = new ZoneModel(zone)
46
+ Zone.validate((err, res) => {
47
+ assert.exists(err, 'err object should exist')
48
+ assert.isObject(err)
49
+ assert('geofeatures.0.name' in err.errors)
50
+ done()
51
+ })
52
+ })
53
+ assertions('should throw an error when an invalid geofeature (complex validation) is instantiated within a zone', (done) => {
54
+ delete zone.geofeatures[0].minor
55
+ let Zone = new ZoneModel(zone)
56
+ Zone.validate((err, res) => {
57
+ assert.exists(err, 'err object should exist')
58
+ assert.isObject(err)
59
+ assert('geofeatures.0.beaconType' in err.errors)
60
+ done()
61
+ })
62
+ })
63
+ assertions('should throw an error when an no geofeature is instantiated within a zone', (done) => {
64
+ zone.geofeatures = []
65
+ let Zone = new ZoneModel(zone)
66
+ Zone.validate((err, res) => {
67
+ assert.exists(err, 'err object should exist')
68
+ assert.isObject(err)
69
+ assert('geofeatures' in err.errors)
70
+ done()
71
+ })
72
+ })
73
+ })
74
+ })
@@ -11,11 +11,9 @@ let mocha = require('mocha')
11
11
  let beforeEach = mocha.beforeEach
12
12
 
13
13
  let zone
14
- let invalidZone
15
14
 
16
15
  beforeEach(() => {
17
- zone = JSON.parse(JSON.stringify(require('./data/zone.data.json')))
18
- invalidZone = JSON.parse(JSON.stringify(require('./data/zone-with-invalid-circle.json')))
16
+ zone = JSON.parse(JSON.stringify(require('./zone.data.json')))
19
17
  })
20
18
 
21
19
  testCase('Zone', () => {
@@ -68,7 +66,8 @@ testCase('Zone', () => {
68
66
 
69
67
  testCase('Invalid Zone ', () => {
70
68
  assertions('should throw an error when validating an invalid zone ', (done) => {
71
- let Zone = new ZoneModel(invalidZone)
69
+ delete zone.name
70
+ let Zone = new ZoneModel(zone)
72
71
  Zone.validate((err, res) => {
73
72
  assert.exists(err, 'err object should exist')
74
73
  assert.isObject(err)
@@ -81,8 +80,7 @@ testCase('Zone', () => {
81
80
  Zone.validate((err, res) => {
82
81
  assert.exists(err, 'err object should exist')
83
82
  assert.isObject(err)
84
- assert.nestedProperty(err, `errors.url`, 'error should have a url property')
85
- assert.notNestedProperty(err, `errors.geofeatures`, 'error should have a url property')
83
+ assert('actions.1.url' in err.errors, `errors should have a 'actions.1.url' property`)
86
84
  done()
87
85
  })
88
86
  })
@@ -92,8 +90,7 @@ testCase('Zone', () => {
92
90
  Zone.validate((err, res) => {
93
91
  assert.exists(err, 'err object should exist')
94
92
  assert.isObject(err)
95
- assert.nestedProperty(err, `errors.calendarDateRange`, 'error should have a url property')
96
- assert.notNestedProperty(err, `errors.geofeatures`, 'error should have a url property')
93
+ assert('filters.0.startDate' in err.errors, `errors should have a 'filters.0.startDate' property`)
97
94
  done()
98
95
  })
99
96
  })
package/models/Beacon.js CHANGED
@@ -1,13 +1,8 @@
1
1
  let mongoose = require('mongoose')
2
2
  let StateEnum = require('@bluedot-innovation/enums').StateEnum
3
- let uuidv4 = require('uuid/v4')
4
3
  let Point = require('../schemas/Point')
5
4
 
6
- let BeaconSchema = new mongoose.Schema({
7
- customerApiKey: {type: String, validate: [{validator: validateKey, msg: 'Customer API Key is required'}]},
8
- apiKey: {type: String, validate: [{validator: validateKey, msg: 'API Key is required'}]},
9
- guid: {type: String, default: uuidv4},
10
- type: {type: String},
5
+ let schema = {
11
6
  name: {type: String, required: [true, 'name is required. ']},
12
7
  longitude: {
13
8
  type: Number,
@@ -38,6 +33,13 @@ let BeaconSchema = new mongoose.Schema({
38
33
  },
39
34
  location: {type: Point},
40
35
  proximity: {type: String, default: 'Far'}
36
+ }
37
+
38
+ let BeaconSchema = new mongoose.Schema(schema)
39
+
40
+ BeaconSchema.add({
41
+ type:
42
+ {type: String, required: true}
41
43
  })
42
44
 
43
45
  // mongoose validator helper plugin
@@ -88,13 +90,6 @@ function validateBeaconType (v, cb) {
88
90
  }
89
91
  }
90
92
 
91
- function validateKey (apiKey) {
92
- // todo beacon can be added via zone or individually. so decide whether we need to validate apikey/ customerapikey, or log in function will solve that
93
- 'use strict'
94
- let regex = 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}$/i)
95
- return !!regex.test(apiKey)
96
- }
97
-
98
93
  // optional mongoose
99
94
  module.exports = (mongooseInstance) => {
100
95
  let Beacon
@@ -106,3 +101,4 @@ module.exports = (mongooseInstance) => {
106
101
 
107
102
  return Beacon
108
103
  }
104
+ module.exports.beaconSchema = schema
@@ -5,18 +5,37 @@
5
5
  */
6
6
  let mongoose = require('mongoose')
7
7
 
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
+
8
15
  let BeaconFilterSchema = new mongoose.Schema(
9
- {
10
- '_class': {type: String, default: 'au.com.bluedot.application.spring.filter.spatial.BeaconFilter'},
11
- 'beacon': {},
12
- 'guid': String,
13
- 'type': {type: String, default: 'beacon'}
14
- },
16
+ schema,
15
17
  {
16
18
  _id: false
17
19
  }
18
20
  )
19
21
 
22
+ BeaconFilterSchema.add({
23
+ type:
24
+ {type: String, required: true}
25
+ })
26
+
20
27
  let BeaconFilter = mongoose.model('BeaconFilter', BeaconFilterSchema)
21
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
+ }
37
+
38
+ return BeaconFilter
39
+ }
22
40
  module.exports = BeaconFilter
41
+ module.exports.beaconFilterChema = schema
@@ -1,17 +1,23 @@
1
1
  let mongoose = require('mongoose')
2
2
  let uuidv4 = require('uuid/v4')
3
3
 
4
- let BearingFilterSchema = new mongoose.Schema({
4
+ const schema = {
5
5
  guid: {type: String, default: uuidv4},
6
- type: {type: String, required: true},
7
6
  fromAngle: {type: Number, required: [true, 'fromAngle is required. '], min: 0, max: 359},
8
7
  toAngle: {type: Number, required: true, min: 0, max: 359, validate: {validator: validateAngles, msg: 'default error message'}}
9
- },
10
- {
11
- _id: false,
12
- versionKey: false
13
8
  }
14
- )
9
+
10
+ const BearingFilterSchema = new mongoose.Schema(
11
+ schema,
12
+ {
13
+ _id: false,
14
+ versionKey: false
15
+ })
16
+
17
+ BearingFilterSchema.add({
18
+ type:
19
+ {type: String, required: true}
20
+ })
15
21
 
16
22
  function validateAngles (toAngle, cb) {
17
23
  let magicCallback = cb
@@ -49,3 +55,4 @@ module.exports = (mongooseInstance) => {
49
55
 
50
56
  return BearingFilter
51
57
  }
58
+ module.exports.bearingFilterSchema = schema
@@ -3,21 +3,27 @@ let StateEnum = require('@bluedot-innovation/enums').StateEnum
3
3
  let uuidv4 = require('uuid/v4')
4
4
  let Point = require('../schemas/Point')
5
5
 
6
- let BoundingBoxSchema = new mongoose.Schema({
6
+ const schema = {
7
7
  guid: {type: String, default: uuidv4},
8
- type: {type: String, default: 'MultiLineString'},
9
8
  name: {type: String, required: [true, 'name is required. ']},
10
9
  northEast: {type: Point, required: [true, 'northEast is required. ']},
11
10
  southWest: {type: Point, required: [true, 'southWest is required. ']},
12
11
  creationTime: {type: Date, default: Date.now},
13
12
  lastUpdateTime: {type: Date, default: Date.now},
14
13
  state: {type: String, default: StateEnum.active, select: false}
15
- },
16
- {
17
- _id: false,
18
- versionKey: false
19
14
  }
20
- )
15
+
16
+ const BoundingBoxSchema = new mongoose.Schema(
17
+ schema,
18
+ {
19
+ _id: false,
20
+ versionKey: false
21
+ })
22
+
23
+ BoundingBoxSchema.add({
24
+ type:
25
+ {type: String, required: true}
26
+ })
21
27
 
22
28
  // optional mongoose
23
29
  module.exports = (mongooseInstance) => {
@@ -30,3 +36,4 @@ module.exports = (mongooseInstance) => {
30
36
 
31
37
  return BoundingBox
32
38
  }
39
+ module.exports.boundingBoxSchema = schema
@@ -1,17 +1,22 @@
1
1
  let mongoose = require('mongoose')
2
2
  let uuidv4 = require('uuid/v4')
3
3
 
4
- let CalendarDateRangeSchema = new mongoose.Schema({
4
+ let schema = {
5
5
  guid: {type: String, default: uuidv4},
6
- type: {type: String, required: true},
7
6
  startDate: {type: Date, required: [true, 'startDate is required. ']},
8
7
  endDate: {type: Date, required: [true, 'endDate is required. '], validate: validateDateRange}
9
- },
10
- {
11
- _id: false,
12
- versionKey: false
13
8
  }
14
- )
9
+ let CalendarDateRangeSchema = new mongoose.Schema(
10
+ schema,
11
+ {
12
+ _id: false,
13
+ versionKey: false
14
+ })
15
+
16
+ CalendarDateRangeSchema.add({
17
+ type:
18
+ {type: String, required: true}
19
+ })
15
20
 
16
21
  function validateDateRange (endDate) {
17
22
  let startDate = new Date(this.startDate)
@@ -33,3 +38,4 @@ module.exports = (mongooseInstance) => {
33
38
 
34
39
  return CalendarDateRange
35
40
  }
41
+ module.exports.calendarDateRangeSchema = schema