@bluedot-innovation/models 5.1.10 → 5.1.13
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 +6 -0
- package/__tests__/beacon/beacon.spec.js +19 -3
- package/__tests__/zone/zone.geofeatures.spec.js +1 -1
- package/helpers.js +4 -0
- package/models/Account.js +1 -1
- package/models/AdminPortalUser.js +1 -1
- package/models/Beacon.js +36 -32
- package/models/CustomerLogin.js +1 -1
- package/models/PartnerCustomer.js +1 -1
- package/models/PartnerUser.js +1 -1
- package/models/TestScenario.js +0 -1
- package/models/User.js +1 -1
- package/models/Zone.js +1 -1
- package/models/ZoneUIState.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -42,12 +42,12 @@ describe('Beacon', () => {
|
|
|
42
42
|
})
|
|
43
43
|
})
|
|
44
44
|
|
|
45
|
-
describe('check each required property of the model and validate that it is present', (
|
|
45
|
+
describe('check each dependent required property of the model and validate that it is present and in a valid format', () => {
|
|
46
46
|
let dependentRequiredFields = rules.dependentRequiredFields
|
|
47
47
|
dependentRequiredFields.forEach((parent) => {
|
|
48
48
|
parent.pairings.forEach((i) => {
|
|
49
49
|
i.requiredFields.forEach((field) => {
|
|
50
|
-
it(`should throw an error with property '${
|
|
50
|
+
it(`should throw an error with property '${field}' if '${i.value}' is selected and '${field}' is not present`, (done) => {
|
|
51
51
|
// delete beacon[field] i.e. txPower from beacon
|
|
52
52
|
delete beacon[field]
|
|
53
53
|
// set required dependent field property
|
|
@@ -57,7 +57,23 @@ describe('Beacon', () => {
|
|
|
57
57
|
assert.notExists(res)
|
|
58
58
|
assert.exists(err, 'err object should exist')
|
|
59
59
|
assert.isObject(err)
|
|
60
|
-
assert.nestedProperty(err, `errors.${
|
|
60
|
+
assert.nestedProperty(err, `errors.${field}`, `error should have a ${field} property`)
|
|
61
|
+
done()
|
|
62
|
+
})
|
|
63
|
+
})
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
i.requiredFields.forEach((field) => {
|
|
67
|
+
it(`should throw an error with property '${field}' if '${i.value}' is selected and '${field}' is not in a valid format`, (done) => {
|
|
68
|
+
beacon[field] = "dumpt text"
|
|
69
|
+
// set required dependent field property
|
|
70
|
+
beacon[parent.property] = i.value
|
|
71
|
+
let Beacon = new BeaconModel(beacon)
|
|
72
|
+
Beacon.validate((err, res) => {
|
|
73
|
+
assert.notExists(res)
|
|
74
|
+
assert.exists(err, 'err object should exist')
|
|
75
|
+
assert.isObject(err)
|
|
76
|
+
assert.nestedProperty(err, `errors.${field}`, `error should have a ${field} property`)
|
|
61
77
|
done()
|
|
62
78
|
})
|
|
63
79
|
})
|
|
@@ -57,7 +57,7 @@ testCase('Zone - Action', () => {
|
|
|
57
57
|
Zone.validate((err, res) => {
|
|
58
58
|
assert.exists(err, 'err object should exist')
|
|
59
59
|
assert.isObject(err)
|
|
60
|
-
assert('geofeatures.0.
|
|
60
|
+
assert('geofeatures.0.minor' in err.errors)
|
|
61
61
|
done()
|
|
62
62
|
})
|
|
63
63
|
})
|
package/helpers.js
CHANGED
|
@@ -168,6 +168,10 @@ helpers.validateNotNull = function(value) {
|
|
|
168
168
|
return value !== null
|
|
169
169
|
}
|
|
170
170
|
|
|
171
|
+
helpers.isValidMacAddress = function (value){
|
|
172
|
+
return /^([0-9a-f]{1,2}[\.:-]){5}([0-9a-f]{1,2})$/i.test(value);
|
|
173
|
+
}
|
|
174
|
+
|
|
171
175
|
const isValidObject = data => {
|
|
172
176
|
// data not null, not undefined, must be an object
|
|
173
177
|
return !(data === null || typeof data === 'undefined'|| data.constructor !== Object)
|
package/models/Account.js
CHANGED
|
@@ -23,7 +23,7 @@ let AccountSchema = new mongoose.Schema({
|
|
|
23
23
|
// the createdBy will be.
|
|
24
24
|
default: uuidv4
|
|
25
25
|
},
|
|
26
|
-
state: {type: String, default: StateEnum.
|
|
26
|
+
state: {type: String, default: StateEnum.ACTIVE},
|
|
27
27
|
poiCredits: Number,
|
|
28
28
|
integrations: Object,
|
|
29
29
|
features: Object,
|
|
@@ -11,7 +11,7 @@ let AdminPortalUser = mongoose.model('AdminPortalUser', new mongoose.Schema(
|
|
|
11
11
|
password: String,
|
|
12
12
|
firstName: String,
|
|
13
13
|
lastName: String,
|
|
14
|
-
state: {type: String, default: Enums.StateEnum.
|
|
14
|
+
state: {type: String, default: Enums.StateEnum.ACTIVE},
|
|
15
15
|
'creationTime': {type: Date, default: Date.now},
|
|
16
16
|
'dataSource': {type: String, select: false, default: 'AdminPortal'},
|
|
17
17
|
adminId: String,
|
package/models/Beacon.js
CHANGED
|
@@ -1,10 +1,35 @@
|
|
|
1
|
-
const
|
|
1
|
+
const BeaconEnum = require('@bluedot-innovation/enums').BeaconEnum
|
|
2
2
|
const PointGeometry = require('../schemas/PointGeometry')
|
|
3
3
|
const patcher = require('@bluedot-innovation/mongoose-json-patch')
|
|
4
4
|
const Point = require('../schemas/Point')
|
|
5
5
|
const mongoose = require('mongoose')
|
|
6
6
|
const uuidv4 = require('uuid/v4')
|
|
7
7
|
const helpers = require('../helpers')
|
|
8
|
+
const StateEnum = require('@bluedot-innovation/enums').StateEnum
|
|
9
|
+
|
|
10
|
+
function validateMacAddress(beaconType, macAddress) {
|
|
11
|
+
if(isRequiredForAndroid(beaconType)){
|
|
12
|
+
return helpers.isValidMacAddress(macAddress)
|
|
13
|
+
}
|
|
14
|
+
return true
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
function isRequiredForAndroid(beaconType){
|
|
19
|
+
return beaconType.toLowerCase() === BeaconEnum.ANDROID.toLowerCase() || beaconType.toLowerCase() === BeaconEnum.BOTH.toLowerCase()
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function validateProximityUUID(beaconType, proximityUUID) {
|
|
23
|
+
if(isRequiredForIOS(beaconType)){
|
|
24
|
+
return helpers.validateUUIDv4(proximityUUID)
|
|
25
|
+
}
|
|
26
|
+
return true
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function isRequiredForIOS(beaconType){
|
|
30
|
+
return beaconType.toLowerCase() === BeaconEnum.IOS.toLowerCase() || beaconType.toLowerCase() === BeaconEnum.BOTH.toLowerCase()
|
|
31
|
+
}
|
|
32
|
+
|
|
8
33
|
|
|
9
34
|
let schema = {
|
|
10
35
|
_id: {type: String, default: uuidv4},
|
|
@@ -12,26 +37,21 @@ let schema = {
|
|
|
12
37
|
description: {type: String, default: '', require: true},
|
|
13
38
|
creationTime: {type: Date, default: Date.now},
|
|
14
39
|
lastUpdateTime: {type: Date, default: Date.now},
|
|
15
|
-
state: {type: String, default: StateEnum.
|
|
40
|
+
state: {type: String, default: StateEnum.ACTIVE},
|
|
16
41
|
beaconType: {
|
|
17
42
|
type: String,
|
|
18
43
|
required: true,
|
|
19
|
-
enum: [BeaconEnum.IOS, BeaconEnum.ANDROID, BeaconEnum.BOTH]
|
|
20
|
-
validate: {
|
|
21
|
-
isAsync: true,
|
|
22
|
-
validator: validateBeaconType,
|
|
23
|
-
msg: 'Async validation. This message is not used'
|
|
24
|
-
}
|
|
44
|
+
enum: [BeaconEnum.IOS, BeaconEnum.ANDROID, BeaconEnum.BOTH]
|
|
25
45
|
},
|
|
26
46
|
location: {type: Point, required: true},
|
|
27
47
|
geometry: {type: PointGeometry},
|
|
28
48
|
accountId: {type: String, required: true},
|
|
29
49
|
// These must be unique
|
|
30
|
-
major: {type: Number,
|
|
31
|
-
minor: {type: Number,
|
|
50
|
+
major: {type: Number, required: [function() {return isRequiredForIOS(this.beaconType)}, 'Please enter a major'], validate: [function() {return validateMajorMinor(this.beaconType, this.major)}, 'Major needs to be within range(0-65535)']},
|
|
51
|
+
minor: {type: Number, required: [function() {return isRequiredForIOS(this.beaconType)}, 'Please enter a minor'], validate: [function() {return validateMajorMinor(this.beaconType, this.minor)}, 'Minor needs to be within range(0-65535)']},
|
|
32
52
|
txPower: {type: Number, validate: helpers.validateNotNull},
|
|
33
|
-
macAddress: {type: String, validate:
|
|
34
|
-
proximityUUID: {type: String, validate:
|
|
53
|
+
macAddress: {type: String, required: [function() {return isRequiredForAndroid(this.beaconType)}, 'Please enter a Mac Address'], validate: [function () {return validateMacAddress(this.beaconType, this.macAddress)}, 'Please enter a valid Mac Address']},
|
|
54
|
+
proximityUUID: {type: String, required: [function() {return isRequiredForIOS(this.beaconType)}, 'Please enter a Proximity UUID'], validate: [function () {return validateProximityUUID(this.beaconType, this.proximityUUID)}, 'Please enter a valid Proximity UUID']}
|
|
35
55
|
}
|
|
36
56
|
|
|
37
57
|
let BeaconSchema = new mongoose.Schema(schema, {collection: 'beacon', autoIndex: false})
|
|
@@ -49,29 +69,13 @@ BeaconSchema.post('validate', function (doc) {
|
|
|
49
69
|
Object.assign(this.errors || {}, this.errors || {}, this.customErrors)
|
|
50
70
|
})
|
|
51
71
|
|
|
52
|
-
function validateMajorMinor (
|
|
72
|
+
function validateMajorMinor (beaconType, value) {
|
|
53
73
|
'use strict'
|
|
54
|
-
return v >= 0 && v <= 65535
|
|
55
|
-
}
|
|
56
74
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const beaconType = v
|
|
60
|
-
const { minor, major, macAddress, proximityUUID } = this;
|
|
61
|
-
|
|
62
|
-
let androidRegex = new RegExp(/(android)/ig)
|
|
63
|
-
let iosRegex = new RegExp(/(ios)/ig)
|
|
64
|
-
let bothRegex = new RegExp(/(both)/ig)
|
|
65
|
-
|
|
66
|
-
if (androidRegex.test(beaconType)) {
|
|
67
|
-
callback((!!macAddress), "Beacon type 'Android' must have a mac address")
|
|
68
|
-
} else if (iosRegex.test(beaconType)) {
|
|
69
|
-
callback((!!proximityUUID && !!minor && !!major), "Beacon type 'IOS' must have 'proximityUUID', 'minor' and 'major' values")
|
|
70
|
-
} else if (bothRegex.test(beaconType)) {
|
|
71
|
-
callback((!!proximityUUID && !!minor && !!major && !!macAddress), "Beacon type 'Both' must have all of 'proximityUUID', 'minor', 'major', and 'mac address' values")
|
|
72
|
-
} else {
|
|
73
|
-
callback(true)
|
|
75
|
+
if(isRequiredForIOS(beaconType)){
|
|
76
|
+
return value >= 0 && value <= 65535
|
|
74
77
|
}
|
|
78
|
+
return true
|
|
75
79
|
}
|
|
76
80
|
|
|
77
81
|
// optional mongoose
|
package/models/CustomerLogin.js
CHANGED
|
@@ -19,7 +19,7 @@ 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.
|
|
22
|
+
state: {type: String, default: StateEnum.ACTIVE},
|
|
23
23
|
creationTime: {type: Date, default: Date.now},
|
|
24
24
|
lastUpdateTime: {type: Date, default: Date.now},
|
|
25
25
|
createdBy: String,
|
|
@@ -21,7 +21,7 @@ let PartnerCustomer = mongoose.model('PartnerCustomer', new mongoose.Schema(
|
|
|
21
21
|
isUsingGeofencing: Boolean,
|
|
22
22
|
additionalComments: String,
|
|
23
23
|
referredBy: mongoose.Schema.Types.ObjectId,
|
|
24
|
-
state: {type: String, default: StateEnum.
|
|
24
|
+
state: {type: String, default: StateEnum.ACTIVE},
|
|
25
25
|
'creationTime': {type: Date, default: Date.now},
|
|
26
26
|
'dataSource': {type: String, select: false, default: 'PartnerPortal'},
|
|
27
27
|
partnerId: String
|
package/models/PartnerUser.js
CHANGED
|
@@ -16,7 +16,7 @@ let PartnerUser = mongoose.model('PartnerUser', new mongoose.Schema(
|
|
|
16
16
|
approvalToken: String,
|
|
17
17
|
phoneNumber: String,
|
|
18
18
|
partnerCompany: String,
|
|
19
|
-
state: {type: String, default: StateEnum.
|
|
19
|
+
state: {type: String, default: StateEnum.ACTIVE},
|
|
20
20
|
'creationTime': {type: Date, default: Date.now},
|
|
21
21
|
'dataSource': {type: String, select: false, default: 'PartnerPortal'},
|
|
22
22
|
partnerId: String
|
package/models/TestScenario.js
CHANGED
|
@@ -12,7 +12,6 @@ let TestScenario = mongoose.model('TestScenario', new mongoose.Schema(
|
|
|
12
12
|
apiKey: String,
|
|
13
13
|
customerApiKey: String,
|
|
14
14
|
email: String,
|
|
15
|
-
package: String,
|
|
16
15
|
'creationTime': {type: Date, default: Date.now},
|
|
17
16
|
'lastUpdateTime': {type: Date, default: Date.now},
|
|
18
17
|
state: {type: String, default: StateEnum.ACTIVE},
|
package/models/User.js
CHANGED
|
@@ -29,7 +29,7 @@ let UserSchema = new mongoose.Schema({
|
|
|
29
29
|
firstName: {type: String, required: true},
|
|
30
30
|
lastName: {type: String, required: true},
|
|
31
31
|
phoneNumber: {type: String, maxlength: 20, validate: helpers.validateNotNull},
|
|
32
|
-
state: {type: String, default: StateEnum.
|
|
32
|
+
state: {type: String, default: StateEnum.ACTIVE},
|
|
33
33
|
creationTime: {type: Date, default: Date.now},
|
|
34
34
|
lastUpdateTime: {type: Date, default: Date.now},
|
|
35
35
|
isAdmin: {type: Boolean, required: true},
|
package/models/Zone.js
CHANGED
|
@@ -77,7 +77,7 @@ let zoneSchema = new Schema({
|
|
|
77
77
|
creationTime: {type: Date, default: Date.now},
|
|
78
78
|
lastUpdateTime: {type: Date, default: Date.now},
|
|
79
79
|
projectId: {type: String, required: true},
|
|
80
|
-
state: {type: String, default: StateEnum.
|
|
80
|
+
state: {type: String, default: StateEnum.ACTIVE, select: false},
|
|
81
81
|
accountId: {type: String, required: true, validate: {isAsync: false, validator: helpers.validateUUIDv4, msg: 'default error message'}}
|
|
82
82
|
}, {collection: 'zone'})
|
|
83
83
|
|
package/models/ZoneUIState.js
CHANGED
|
@@ -15,7 +15,7 @@ let ZoneUIStateSchema = new mongoose.Schema({
|
|
|
15
15
|
zoom: {type: Number, default: 4},
|
|
16
16
|
lastUpdateTime: {type: Date, default: Date.now},
|
|
17
17
|
creationTime: {type: Date, default: Date.now},
|
|
18
|
-
state: {type: String, default: StateEnum.
|
|
18
|
+
state: {type: String, default: StateEnum.ACTIVE, select: false},
|
|
19
19
|
zoneId: String
|
|
20
20
|
},
|
|
21
21
|
{collection: 'zoneUIState'}
|
package/package.json
CHANGED