@bluedot-innovation/models 2.0.9 → 2.0.10-alpha.2

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,3 +1,8 @@
1
+ ## 2.0.10
2
+ - Added indexes on beacons model
3
+ - Added `apiKey` to project model (for backwards compatability)
4
+ - Added `customerApiKey` to account model (for backwards compatability)
5
+
1
6
  ## 2.0.9
2
7
  - Validation on `projectPermissions` in user model
3
8
 
package/models/Account.js CHANGED
@@ -12,6 +12,7 @@ const helpers = require('../helpers')
12
12
 
13
13
  let AccountSchema = new mongoose.Schema({
14
14
  _id: {type: String, default: uuidv4},
15
+ customerApiKey: {type: String, default: uuidv4}, // Backwards compatability
15
16
  name: {type: String, required: true},
16
17
  createdBy: {
17
18
  // type: Schema.Types.ObjectId,
package/models/Beacon.js CHANGED
@@ -7,7 +7,6 @@ let patcher = require('mongoose-json-patch')
7
7
 
8
8
  let schema = {
9
9
  _id: {type: String, default: uuidv4},
10
- geometry: {type: PointGeometry},
11
10
  name: {type: String, required: [true, 'name is required.']},
12
11
  description: {type: String, default: ''},
13
12
  creationTime: {type: Date, default: Date.now},
@@ -23,9 +22,8 @@ let schema = {
23
22
  }
24
23
  },
25
24
  location: {type: Point, required: true},
26
- accountId: {
27
- type: String, required: true
28
- },
25
+ geometry: {type: PointGeometry},
26
+ accountId: {type: String, required: true},
29
27
  // These must be unique
30
28
  major: {type: Number, validate: [{validator: validateMajorMinor, msg: 'Major needs to be within range(1-65535)'}]},
31
29
  minor: {type: Number, validate: [{validator: validateMajorMinor, msg: 'Minor needs to be within range(1-65535)'}]},
@@ -34,7 +32,14 @@ let schema = {
34
32
  proximityUUID: {type: String}
35
33
  }
36
34
 
37
- let BeaconSchema = new mongoose.Schema(schema, {collection: 'beacon'})
35
+ let BeaconSchema = new mongoose.Schema(schema, {collection: 'beacon', autoIndex: false})
36
+
37
+ BeaconSchema.index({ macAddress: 1 })
38
+ BeaconSchema.index({ proximityUUID: 1, major: 1, minor: 1 })
39
+ BeaconSchema.index({ accountId: 1, geometry: '2dsphere' })
40
+
41
+ // accountId: 1, geometry: "2dsphere"
42
+
38
43
  BeaconSchema.plugin(patcher)
39
44
 
40
45
  // mongoose validator helper plugin
@@ -74,12 +79,12 @@ function validateBeaconType (v, magicCallback) {
74
79
 
75
80
  // optional mongoose
76
81
  let model = (mongooseInstance) => {
77
- let Beacon
78
- if (mongooseInstance) {
79
- Beacon = mongooseInstance.model('Beacon', BeaconSchema)
80
- } else {
81
- Beacon = mongoose.model('Beacon', BeaconSchema)
82
- }
82
+ const instance = mongooseInstance || mongoose
83
+ let Beacon = instance.model('Beacon', BeaconSchema)
84
+
85
+ Beacon.on('index', function (error) {
86
+ console.log(error.message)
87
+ })
83
88
 
84
89
  return Beacon
85
90
  }
@@ -7,15 +7,12 @@ const schema = {
7
7
  toAngle: {type: Number, required: true, min: 0, max: 359, validate: {isAsync: true, validator: validateAngles, msg: 'default error message'}}
8
8
  }
9
9
 
10
- const BearingFilterSchema = new mongoose.Schema(
11
- schema,
12
- {
13
- versionKey: false
14
- })
10
+ const BearingFilterSchema = new mongoose.Schema(schema, {
11
+ versionKey: false
12
+ })
15
13
 
16
14
  BearingFilterSchema.add({
17
- type:
18
- {type: String, required: true}
15
+ type: {type: String, required: true}
19
16
  })
20
17
 
21
18
  function validateAngles (toAngle, magicCallback) {
package/models/Project.js CHANGED
@@ -15,6 +15,7 @@ let WebhookSchema = require('../schemas/Webhook')
15
15
 
16
16
  let ProjectSchema = new mongoose.Schema({
17
17
  _id: {type: String, default: uuidv4},
18
+ apiKey: {type: String, default: uuidv4}, // Backwards compatability
18
19
  state: {type: String, default: StateEnum.active},
19
20
  nextRuleUpdateInterval: {
20
21
  type: Number,
package/models/Zone.js CHANGED
@@ -43,7 +43,7 @@ let ZoneSchema = new Schema({
43
43
  type: Number,
44
44
  required: [true, 'minimumRetriggerTime is required'],
45
45
  min: 60,
46
- max: 3599940,
46
+ max: 359940,
47
47
  validate: {
48
48
  validator: Number.isInteger,
49
49
  message: '{VALUE} is not a number'
@@ -14,8 +14,9 @@ schema.proximity = {
14
14
  const ZoneBeaconSchema = new mongoose.Schema(schema)
15
15
 
16
16
  // optional mongoose
17
- let model = (mongooseInstance = mongoose) => {
18
- return mongooseInstance.model('ZoneBeacon', ZoneBeaconSchema)
17
+ let model = (mongooseInstance) => {
18
+ const instance = mongooseInstance || mongoose
19
+ return instance.model('ZoneBeacon', ZoneBeaconSchema)
19
20
  }
20
21
 
21
22
  // Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bluedot-innovation/models",
3
- "version": "2.0.9",
3
+ "version": "2.0.10-alpha.2",
4
4
  "description": "",
5
5
  "main": "Models.js",
6
6
  "scripts": {