@bluedot-innovation/models 2.0.19-alpha.9 → 2.0.20-alpha.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
+ ## 2.0.20
2
+ - Validation: Polygon needs 3 or more vertices
3
+
1
4
  ## 2.0.19
2
- - Mask `State`, `creationTime`, `lastUpdateTime`, `geofeatures.geometry`, `secret` from API responses
5
+ - Added validations for keys in customData
3
6
 
4
7
  ## 2.0.18
5
8
  - `password` on `user` model no longer required. We will rely on cognito to throw an error
package/Models.js CHANGED
@@ -5,17 +5,17 @@
5
5
  let Models = {}
6
6
 
7
7
  Models.Account = require('./models/Account').Model
8
- Models.Beacon = require('./models/geofeatures/Beacon').Model
8
+ Models.Beacon = require('./models/Beacon').Model
9
9
  Models.BeaconFilter = require('./models/BeaconFilter').Model
10
10
  Models.BearingFilter = require('./models/BearingFilter').Model
11
- Models.BoundingBox = require('./models/geofeatures/BoundingBox').Model
11
+ Models.BoundingBox = require('./models/BoundingBox').Model
12
12
  Models.CalendarDateRangeFilter = require('./models/CalendarDateRangeFilter').Model
13
- Models.Circle = require('./models/geofeatures/Circle').Model
13
+ Models.Circle = require('./models/Circle').Model
14
14
  Models.MessageAction = require('./models/MessageAction').Model
15
15
  Models.MonthlyStat = require('./models/MonthlyStats').Model
16
16
  Models.PercentageCrossedFilter = require('./models/PercentageCrossedFilter').Model
17
- Models.Polygon = require('./models/geofeatures/Polygon').Model
18
- Models.Polyline = require('./models/geofeatures/Polyline').Model
17
+ Models.Polygon = require('./models/Polygon').Model
18
+ Models.Polyline = require('./models/Polyline').Model
19
19
  Models.Project = require('./models/Project').Model
20
20
  Models.RuleRequestAggregation = require('./models/RuleRequestAggregation').Model
21
21
  Models.SpeedFilter = require('./models/SpeedFilter').Model
@@ -28,17 +28,17 @@ Models.ZoneBeacon = require('./models/ZoneBeacon').Model
28
28
  let Schemas = {}
29
29
 
30
30
  Schemas.Account = require('./models/Account').Schema
31
- Schemas.Beacon = require('./models/geofeatures/Beacon').Schema
31
+ Schemas.Beacon = require('./models/Beacon').Schema
32
32
  Schemas.BeaconFilter = require('./models/BeaconFilter').Schema
33
33
  Schemas.BearingFilter = require('./models/BearingFilter').Schema
34
- Schemas.BoundingBox = require('./models/geofeatures/BoundingBox').Schema
34
+ Schemas.BoundingBox = require('./models/BoundingBox').Schema
35
35
  Schemas.CalendarDateRangeFilter = require('./models/CalendarDateRangeFilter').Schema
36
- Schemas.Circle = require('./models/geofeatures/Circle').Schema
36
+ Schemas.Circle = require('./models/Circle').Schema
37
37
  Schemas.MessageAction = require('./models/MessageAction').Schema
38
38
  Schemas.MonthlyStat = require('./models/MonthlyStats').Schema
39
39
  Schemas.PercentageCrossedFilter = require('./models/PercentageCrossedFilter').Schema
40
- Schemas.Polygon = require('./models/geofeatures/Polygon').Schema
41
- Schemas.Polyline = require('./models/geofeatures/Polyline').Schema
40
+ Schemas.Polygon = require('./models/Polygon').Schema
41
+ Schemas.Polyline = require('./models/Polyline').Schema
42
42
  Schemas.Project = require('./models/Project').Schema
43
43
  Schemas.RuleRequestAggregation = require('./models/RuleRequestAggregation').Schema
44
44
  Schemas.SpeedFilter = require('./models/SpeedFilter').Schema
@@ -2,7 +2,7 @@ let mongoose = require('mongoose')
2
2
  mongoose.Promise = global.Promise
3
3
 
4
4
  const BearingFilterModel = require('../../../Models').BearingFilter(mongoose)
5
- const { isMinimumNinetyApart } = require('../../../models/BearingFilter')
5
+ const { isMinimumNinetyApart } = require.main.require('models/BearingFilter')
6
6
  const describe = require('mocha').describe
7
7
  const it = require('mocha').it
8
8
  const chai = require('chai')
@@ -4,8 +4,8 @@ mongoose.Promise = global.Promise
4
4
 
5
5
  let PolygonModel = require('../../../Models').Polygon(mongoose)
6
6
  let PolygonModelBuiltInMongoose = require('../../../Models').Polygon()
7
- let testCase = require('mocha').describe
8
- let assertions = require('mocha').it
7
+ let describe = require('mocha').describe
8
+ let it = require('mocha').it
9
9
  let chai = require('chai')
10
10
 
11
11
  let assert = chai.assert
@@ -19,9 +19,10 @@ let polygon
19
19
  beforeEach(() => {
20
20
  polygon = JSON.parse(JSON.stringify(require('./polygon.data.json')))
21
21
  })
22
- testCase('Polygon', () => {
23
- testCase('Valid Polygon', () => {
24
- assertions('should validate a valid polygon ', (done) => {
22
+
23
+ describe('Polygon', () => {
24
+ describe('Valid Polygon', () => {
25
+ it('should validate a valid polygon ', (done) => {
25
26
  let Polygon = new PolygonModel(polygon)
26
27
  Polygon.validate((err, res) => {
27
28
  assert.notExists(res)
@@ -29,7 +30,7 @@ testCase('Polygon', () => {
29
30
  done()
30
31
  })
31
32
  })
32
- assertions('should validate a valid polygon (built in mongoose)', (done) => {
33
+ it('should validate a valid polygon (built in mongoose)', (done) => {
33
34
  let Polygon = new PolygonModelBuiltInMongoose(polygon)
34
35
  Polygon.validate((err, res) => {
35
36
  assert.notExists(res)
@@ -39,8 +40,8 @@ testCase('Polygon', () => {
39
40
  })
40
41
  })
41
42
 
42
- testCase('Invalid Polygon', () => {
43
- assertions('should not validate a polygon with invalid Polygon', (done) => {
43
+ describe('Invalid Polygon', () => {
44
+ it('should not validate a polygon with invalid Polygon', (done) => {
44
45
  delete polygon[rules.requiredFields[0]]
45
46
  let Polygon = new PolygonModel(polygon)
46
47
  Polygon.validate((err, res) => {
@@ -49,10 +50,11 @@ testCase('Polygon', () => {
49
50
  done()
50
51
  })
51
52
  })
52
- testCase('check each required property of the model and validate that it is present', () => {
53
+
54
+ describe('check each required property of the model and validate that it is present', () => {
53
55
  let requiredFields = rules.requiredFields
54
56
  requiredFields.map((i) => {
55
- assertions(`should throw an error with property '${i}' if '${i}' is not present`, (done) => {
57
+ it(`should throw an error with property '${i}' if '${i}' is not present`, (done) => {
56
58
  // delete i from geofeatures' polygon child
57
59
  delete polygon[i]
58
60
  let Polygon = new PolygonModel(polygon)
@@ -66,5 +68,22 @@ testCase('Polygon', () => {
66
68
  })
67
69
  })
68
70
  })
71
+
72
+ it('when it only has less than 3 vertices, it should error', (done) => {
73
+ polygon.vertices = [{
74
+ "latitude": -37.81902680201739,
75
+ "longitude": 144.9821037054062
76
+ },
77
+ {
78
+ "latitude": -37.8196878692931,
79
+ "longitude": 144.98161554336548
80
+ }]
81
+
82
+ let Polygon = new PolygonModel(polygon)
83
+ Polygon.validate((err, res) => {
84
+ assert.match(err, /Must have more than 2 vertices/i)
85
+ done()
86
+ })
87
+ })
69
88
  })
70
89
  })
@@ -100,5 +100,15 @@ describe('Zone', () => {
100
100
  done()
101
101
  })
102
102
  })
103
+
104
+ it('should throw an error when validating an invalid customData key ', (done) => {
105
+ zone.customData["name#3"] = "A Custom action3"
106
+ let Zone = new ZoneModel(zone)
107
+ Zone.validate((err, res) => {
108
+ assert.exists(err, 'err object should exist')
109
+ assert.isObject(err)
110
+ done()
111
+ })
112
+ })
103
113
  })
104
114
  })
package/helpers.js CHANGED
@@ -11,4 +11,8 @@ helpers.validateEmail = function (value) {
11
11
  return regex.test(value);
12
12
  }
13
13
 
14
+ helpers.validatePolygonVertices = (vertices) => {
15
+ return vertices.length >= 3;
16
+ }
17
+
14
18
  module.exports = helpers
@@ -1,10 +1,9 @@
1
- const StateEnum = require('@bluedot-innovation/enums').StateEnum
2
- const patcher = require('mongoose-json-patch')
3
- const mongoose = require('mongoose')
4
- const uuidv4 = require('uuid/v4')
5
- const PointGeometry = require('../../schemas/PointGeometry')
6
- const mongooseHidden = require('../../utils/mongooseHidden')
7
- const Point = require('../../schemas/Point')
1
+ let mongoose = require('mongoose')
2
+ let StateEnum = require('@bluedot-innovation/enums').StateEnum
3
+ let Point = require('../schemas/Point')
4
+ let PointGeometry = require('../schemas/PointGeometry')
5
+ let uuidv4 = require('uuid/v4')
6
+ let patcher = require('mongoose-json-patch')
8
7
 
9
8
  let schema = {
10
9
  _id: {type: String, default: uuidv4},
@@ -42,7 +41,6 @@ BeaconSchema.index({ accountId: 1, geometry: '2dsphere' })
42
41
  // accountId: 1, geometry: "2dsphere"
43
42
 
44
43
  BeaconSchema.plugin(patcher)
45
- BeaconSchema.plugin(mongooseHidden)
46
44
 
47
45
  // mongoose validator helper plugin
48
46
  BeaconSchema.post('validate', function (doc) {
@@ -1,9 +1,8 @@
1
- let StateEnum = require('@bluedot-innovation/enums').StateEnum
2
1
  let mongoose = require('mongoose')
2
+ let StateEnum = require('@bluedot-innovation/enums').StateEnum
3
3
  let uuidv4 = require('uuid/v4')
4
- const PolygonGeometry = require('../../schemas/PolygonGeometry')
5
- const Point = require('../../schemas/Point')
6
- const mongooseHidden = require('../../utils/mongooseHidden')
4
+ let Point = require('../schemas/Point')
5
+ let PolygonGeometry = require('../schemas/PolygonGeometry')
7
6
 
8
7
  const schema = {
9
8
  _id: {type: String, default: uuidv4},
@@ -17,31 +16,28 @@ const schema = {
17
16
  state: {type: String, default: StateEnum.active, select: false}
18
17
  }
19
18
 
20
- const boundingBoxSchema = new mongoose.Schema(
19
+ const BoundingBoxSchema = new mongoose.Schema(
21
20
  schema,
22
21
  {
23
22
  _id: false,
24
23
  versionKey: false
25
24
  })
26
25
 
27
- boundingBoxSchema.add({
26
+ BoundingBoxSchema.add({
28
27
  type:
29
28
  {type: String, required: true}
30
29
  })
31
30
 
32
- boundingBoxSchema.plugin(mongooseHidden)
33
-
34
-
35
31
  // optional mongoose
36
32
  let model = (mongooseInstance) => {
37
33
  let BoundingBox
38
34
  if (mongooseInstance) {
39
- BoundingBox = mongooseInstance.model('BoundingBox', boundingBoxSchema)
35
+ BoundingBox = mongooseInstance.model('BoundingBox', BoundingBoxSchema)
40
36
  } else {
41
- BoundingBox = mongoose.model('BoundingBox', boundingBoxSchema)
37
+ BoundingBox = mongoose.model('BoundingBox', BoundingBoxSchema)
42
38
  }
43
39
 
44
40
  return BoundingBox
45
41
  }
46
42
  // Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
47
- module.exports = { Model: model, Schema: boundingBoxSchema, boundingBoxSchema: schema }
43
+ module.exports = { Model: model, Schema: BoundingBoxSchema, boundingBoxSchema: schema }
@@ -1,9 +1,8 @@
1
1
  let mongoose = require('mongoose')
2
2
  let StateEnum = require('@bluedot-innovation/enums').StateEnum
3
+ let Point = require('../schemas/Point')
3
4
  let uuidv4 = require('uuid/v4')
4
- const PolygonGeometry = require('../../schemas/PolygonGeometry')
5
- const mongooseHidden = require('../../utils/mongooseHidden')
6
- const Point = require('../../schemas/Point')
5
+ let PolygonGeometry = require('../schemas/PolygonGeometry')
7
6
 
8
7
  let schema = {
9
8
  _id: {type: String, default: uuidv4},
@@ -17,29 +16,28 @@ let schema = {
17
16
  state: {type: String, default: StateEnum.active, select: false}
18
17
  }
19
18
 
20
- let circleSchema = new mongoose.Schema(
19
+ let CircleSchema = new mongoose.Schema(
21
20
  schema,
22
21
  {
23
22
  _id: false,
24
23
  __v: false
25
24
  })
26
25
 
27
- circleSchema.add({
28
- type: {type: String, required: true}
26
+ CircleSchema.add({
27
+ type:
28
+ {type: String, required: true}
29
29
  })
30
30
 
31
- circleSchema.plugin(mongooseHidden)
32
-
33
31
  // optional mongoose
34
32
  let model = (mongooseInstance) => {
35
33
  let Circle
36
34
  if (mongooseInstance) {
37
- Circle = mongooseInstance.model('Circle', circleSchema)
35
+ Circle = mongooseInstance.model('Circle', CircleSchema)
38
36
  } else {
39
- Circle = mongoose.model('Circle', circleSchema)
37
+ Circle = mongoose.model('Circle', CircleSchema)
40
38
  }
41
39
 
42
40
  return Circle
43
41
  }
44
42
  // Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
45
- module.exports = { Model: model, Schema: circleSchema, circleSchema: schema }
43
+ module.exports = { Model: model, Schema: CircleSchema, circleSchema: schema }
@@ -0,0 +1,43 @@
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
+ let helpers = require('../helpers')
6
+
7
+ const schema = {
8
+ _id: {type: String, default: uuidv4},
9
+ geometry: {type: mongoose.Schema.Types.Mixed},
10
+ name: {type: String, required: [true, 'name is required.']},
11
+ color: String,
12
+ vertices: {
13
+ type: [Point], required: [true, 'vertices is required.'],
14
+ validate: {
15
+ validator: helpers.validatePolygonVertices,
16
+ msg: 'A polygon must have 3 or more vertices.'
17
+ }
18
+ },
19
+ creationTime: {type: Date, default: Date.now},
20
+ lastUpdateTime: {type: Date, default: Date.now},
21
+ state: {type: String, default: StateEnum.active, select: false}
22
+ }
23
+
24
+ const PolygonSchema = new mongoose.Schema(schema, {
25
+ _id: false,
26
+ versionKey: false
27
+ })
28
+
29
+ PolygonSchema.add({type: {type: String, required: true}})
30
+
31
+ // optional mongoose
32
+ let model = (mongooseInstance) => {
33
+ let Polygon
34
+ if (mongooseInstance) {
35
+ Polygon = mongooseInstance.model('Polygon', PolygonSchema)
36
+ } else {
37
+ Polygon = mongoose.model('Polygon', PolygonSchema)
38
+ }
39
+
40
+ return Polygon
41
+ }
42
+ // Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
43
+ module.exports = { Model: model, Schema: PolygonSchema, polygonSchema: schema }
@@ -1,44 +1,41 @@
1
1
  let mongoose = require('mongoose')
2
2
  let StateEnum = require('@bluedot-innovation/enums').StateEnum
3
- const mongooseHidden = require('../../utils/mongooseHidden')
4
- const Point = require('../../schemas/Point')
3
+ let Point = require('../schemas/Point')
5
4
  let uuidv4 = require('uuid/v4')
5
+ let MultiLineStringGeometry = require('../schemas/MultiLineStringGeometry')
6
6
 
7
7
  const schema = {
8
8
  _id: {type: String, default: uuidv4},
9
- geometry: {type: mongoose.Schema.Types.Mixed},
9
+ geometry: {type: MultiLineStringGeometry},
10
10
  name: {type: String, required: [true, 'name is required. ']},
11
- color: String,
12
11
  vertices: {type: [Point], required: [true, 'vertices is required. ']},
13
12
  creationTime: {type: Date, default: Date.now},
14
13
  lastUpdateTime: {type: Date, default: Date.now},
15
14
  state: {type: String, default: StateEnum.active, select: false}
16
15
  }
17
- const polygonSchema = new mongoose.Schema(
16
+
17
+ const PolylineSchema = new mongoose.Schema(
18
18
  schema,
19
19
  {
20
20
  _id: false,
21
21
  versionKey: false
22
22
  })
23
23
 
24
- polygonSchema.add({
24
+ PolylineSchema.add({
25
25
  type:
26
26
  {type: String, required: true}
27
27
  })
28
28
 
29
- polygonSchema.plugin(mongooseHidden)
30
-
31
-
32
29
  // optional mongoose
33
30
  let model = (mongooseInstance) => {
34
- let Polygon
31
+ let Polyline
35
32
  if (mongooseInstance) {
36
- Polygon = mongooseInstance.model('Polygon', polygonSchema)
33
+ Polyline = mongooseInstance.model('Polyline', PolylineSchema)
37
34
  } else {
38
- Polygon = mongoose.model('Polygon', polygonSchema)
35
+ Polyline = mongoose.model('Polyline', PolylineSchema)
39
36
  }
40
37
 
41
- return Polygon
38
+ return Polyline
42
39
  }
43
40
  // Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
44
- module.exports = { Model: model, Schema: polygonSchema, polygonSchema: schema }
41
+ module.exports = { Model: model, Schema: PolylineSchema, polylineSchema: schema }
package/models/Project.js CHANGED
@@ -9,7 +9,6 @@ let Schema = mongoose.Schema
9
9
  let StateEnum = require('@bluedot-innovation/enums').StateEnum
10
10
  let uuidv4 = require('uuid/v4')
11
11
  let patcher = require('mongoose-json-patch')
12
- const mongooseHidden = require('../utils/mongooseHidden')
13
12
  let helpers = require('../helpers')
14
13
 
15
14
  let WebhookSchema = require('../schemas/Webhook')
@@ -39,7 +38,6 @@ let ProjectSchema = new mongoose.Schema({
39
38
  {collection: 'project'})
40
39
 
41
40
  ProjectSchema.plugin(patcher)
42
- ProjectSchema.plugin(mongooseHidden)
43
41
 
44
42
  // optional mongoose
45
43
  let model = (mongooseInstance) => {
package/models/User.js CHANGED
@@ -9,7 +9,6 @@ const patcher = require('mongoose-json-patch')
9
9
  const helpers = require('../helpers')
10
10
  const ProjectPermission = require('../schemas/ProjectPermission')
11
11
  const uuidv4 = require('uuid/v4')
12
- const mongooseHidden = require('../utils/mongooseHidden')
13
12
 
14
13
  let UserSchema = new mongoose.Schema({
15
14
  _id: {type: String, default: uuidv4},
@@ -46,8 +45,6 @@ let UserSchema = new mongoose.Schema({
46
45
  {collection: 'user'})
47
46
 
48
47
  UserSchema.plugin(patcher)
49
- UserSchema.plugin(mongooseHidden)
50
-
51
48
 
52
49
  // optional mongoose
53
50
  let model = (mongooseInstance) => {
package/models/Zone.js CHANGED
@@ -9,10 +9,10 @@ let Schema = mongoose.Schema
9
9
  let StateEnum = require('@bluedot-innovation/enums').StateEnum
10
10
  let messageActionSchema = require('./MessageAction').messageActionSchema
11
11
  let urlActionSchema = require('./UrlAction').urlActionSchema
12
- let circleSchema = require('./geofeatures/Circle').circleSchema
13
- let boundingBoxSchema = require('./geofeatures/BoundingBox').boundingBoxSchema
14
- let polylineSchema = require('./geofeatures/Polyline').polylineSchema
15
- let polygonSchema = require('./geofeatures/Polygon').polygonSchema
12
+ let circleSchema = require('./Circle').circleSchema
13
+ let boundingBoxSchema = require('./BoundingBox').boundingBoxSchema
14
+ let polylineSchema = require('./Polyline').polylineSchema
15
+ let polygonSchema = require('./Polygon').polygonSchema
16
16
  let beaconSchema = require('./ZoneBeacon').beaconSchema
17
17
  let speedFilterSchema = require('./SpeedFilter').speedFilterSchema
18
18
  let bearingFilterSchema = require('./BearingFilter').bearingFilterSchema
@@ -23,14 +23,6 @@ let uuidv4 = require('uuid/v4')
23
23
  let patcher = require('mongoose-json-patch')
24
24
  let helpers = require('../helpers')
25
25
 
26
- const mongooseHidden = require('mongoose-hidden')({defaultHidden: {
27
- state: true,
28
- creationTime: true,
29
- lastUpdateTime: true,
30
- __v: true,
31
- secret: true
32
- }})
33
-
34
26
  // ////// //
35
27
  // Schema //
36
28
  // ////// //
@@ -77,6 +69,9 @@ let zoneSchema = new Schema({
77
69
  accountId: {type: String, required: true, validate: {isAsync: false, validator: helpers.validateUUIDv4, msg: 'default error message'}}
78
70
  }, {collection: 'zone'})
79
71
 
72
+ // TODO: Test patcher and include for other schemas if required
73
+ zoneSchema.plugin(patcher)
74
+
80
75
  zoneSchema.path('actions').discriminator('url', new Schema(urlActionSchema))
81
76
  zoneSchema.path('actions').discriminator('message', new Schema(messageActionSchema))
82
77
 
@@ -92,10 +87,17 @@ zoneSchema.path('geofeatures').discriminator('polygon', new Schema(polygonSchema
92
87
  zoneSchema.path('geofeatures').discriminator('polyline', new Schema(polylineSchema))
93
88
  zoneSchema.path('geofeatures').discriminator('boundingBox', new Schema(boundingBoxSchema))
94
89
 
95
- // TODO: Test patcher and include for other schemas if required
96
- zoneSchema.plugin(patcher)
97
- zoneSchema.plugin(mongooseHidden)
98
- zoneSchema.path('geofeatures').plugin(mongooseHidden)
90
+ zoneSchema.path('customData').validate(function(data) {
91
+ const customDataKeys = Object.keys(data)
92
+ let hasValidationErrors = false
93
+
94
+ customDataKeys.forEach(key => {
95
+ const alphaNumericValidation = new RegExp(/^\w+$/)
96
+ hasValidationErrors = !alphaNumericValidation.test(key)
97
+ })
98
+
99
+ return !hasValidationErrors
100
+ }, 'CustomData key should have alpha numeric and _ characters only')
99
101
 
100
102
  // optional mongoose
101
103
  const model = (mongooseInstance) => {
@@ -1,6 +1,6 @@
1
1
  const cloneDeep = require('lodash.clonedeep')
2
2
  const mongoose = require('mongoose')
3
- const beaconSchema = require('./geofeatures/Beacon').beaconSchema
3
+ const beaconSchema = require('./Beacon').beaconSchema
4
4
  const BeaconEnum = require('@bluedot-innovation/enums').BeaconEnum
5
5
 
6
6
  const schema = cloneDeep(beaconSchema)
@@ -8,7 +8,7 @@ const schema = cloneDeep(beaconSchema)
8
8
  schema.proximity = {
9
9
  type: String,
10
10
  default: BeaconEnum.FAR,
11
- enum: [BeaconEnum.NEAR, BeaconEnum.FAR]
11
+ enum: [BeaconEnum.NEAR, BeaconEnum.IMMEDIATE, BeaconEnum.FAR]
12
12
  }
13
13
 
14
14
  const ZoneBeaconSchema = new mongoose.Schema(schema)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bluedot-innovation/models",
3
- "version": "2.0.19-alpha.9",
3
+ "version": "2.0.20-alpha.1",
4
4
  "description": "",
5
5
  "main": "Models.js",
6
6
  "scripts": {
@@ -30,11 +30,10 @@
30
30
  "sinon": "^4.1.2"
31
31
  },
32
32
  "dependencies": {
33
- "@bluedot-innovation/enums": "2.0.2",
33
+ "@bluedot-innovation/enums": "2.1.1",
34
34
  "lodash.clonedeep": "4.5.0",
35
35
  "mongoose": "^4.13.9",
36
36
  "mongoose-error-helper": "0.0.2",
37
- "mongoose-hidden": "^1.5.3",
38
37
  "mongoose-json-patch": "^1.1.1",
39
38
  "uuid": "^3.1.0"
40
39
  }
@@ -1,43 +0,0 @@
1
- let mongoose = require('mongoose')
2
- let StateEnum = require('@bluedot-innovation/enums').StateEnum
3
- const Point = require('../../schemas/Point')
4
- let uuidv4 = require('uuid/v4')
5
- const MultiLineStringGeometry = require('../../schemas/MultiLineStringGeometry')
6
- const mongooseHidden = require('../../utils/mongooseHidden')
7
-
8
- const schema = {
9
- _id: {type: String, default: uuidv4},
10
- geometry: {type: MultiLineStringGeometry},
11
- name: {type: String, required: [true, 'name is required.']},
12
- vertices: {type: [Point], required: [true, 'vertices is required.']},
13
- creationTime: {type: Date, default: Date.now},
14
- lastUpdateTime: {type: Date, default: Date.now},
15
- state: {type: String, default: StateEnum.active, select: false}
16
- }
17
-
18
- const polylineSchema = new mongoose.Schema(
19
- schema,
20
- {
21
- _id: false,
22
- versionKey: false
23
- })
24
-
25
- polylineSchema.add({
26
- type: {type: String, required: true}
27
- })
28
-
29
- polylineSchema.plugin(mongooseHidden)
30
-
31
- // optional mongoose
32
- let model = (mongooseInstance) => {
33
- let Polyline
34
- if (mongooseInstance) {
35
- Polyline = mongooseInstance.model('Polyline', polylineSchema)
36
- } else {
37
- Polyline = mongoose.model('Polyline', polylineSchema)
38
- }
39
-
40
- return Polyline
41
- }
42
- // Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
43
- module.exports = { Model: model, Schema: polylineSchema, polylineSchema: schema }
@@ -1,9 +0,0 @@
1
- const mongooseHidden = require('mongoose-hidden')({defaultHidden: {
2
- state: true,
3
- creationTime: true,
4
- lastUpdateTime: true,
5
- __v: true,
6
- secret: true
7
- }})
8
-
9
- module.exports = mongooseHidden;