@bluedot-innovation/models 6.2.11-alpha.1 → 6.2.12
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 +17 -2
- package/__tests__/geofeature/circle/circle.spec.js +12 -0
- package/__tests__/project/project.data.json +33 -8
- package/__tests__/project/project.remote.config.json +2 -3
- package/__tests__/project/project.spec.js +47 -18
- package/__tests__/zone/zone.spec.js +71 -8
- package/helpers.js +42 -13
- package/models/Project.js +1 -1
- package/models/Zone.js +18 -0
- package/models/geofeatures/Circle.js +11 -1
- package/package.json +1 -1
- package/schemas/ProjectTempo.js +5 -2
- package/schemas/Webhook.js +2 -1
- package/schemas/ZoneTempo.js +2 -1
- package/utils/DbInitialiser/indexInitialiser.js +12 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
|
-
##
|
|
2
|
-
-
|
|
1
|
+
## 7.0.2
|
|
2
|
+
- Re-added Circle radius to be > 5m
|
|
3
|
+
|
|
4
|
+
## 7.0.1
|
|
5
|
+
- Added tempo webhooks array back for migration
|
|
6
|
+
- Added tempo destinationId back for migration
|
|
7
|
+
- Added no duplicate webhooks of same type validation
|
|
8
|
+
|
|
9
|
+
## 7.0.0
|
|
10
|
+
- BREAKING CHANGE - Moved tempo webhooks to within main project webhooks array
|
|
11
|
+
- BREAKING CHANGE - Moved zone destinationId to object root and removed tempo object from zone
|
|
12
|
+
- Added 'doorbell' type to project webhooks
|
|
3
13
|
|
|
14
|
+
## 6.2.12
|
|
15
|
+
- Re-added Circle radius to be > 5m
|
|
16
|
+
|
|
17
|
+
## 6.2.11
|
|
18
|
+
- Replace `isAsync` validators with Mongoose 5.x validators
|
|
4
19
|
|
|
5
20
|
## 6.2.10
|
|
6
21
|
- Added screens feature to account model
|
|
@@ -51,6 +51,18 @@ testCase('Circle', () => {
|
|
|
51
51
|
})
|
|
52
52
|
|
|
53
53
|
testCase('Invalid Circle', () => {
|
|
54
|
+
// BD2571
|
|
55
|
+
assertions('should not validate a Circle with radius <5 meters', (done) => {
|
|
56
|
+
circle.radius = 3
|
|
57
|
+
let Circle = new CircleModelBuiltInMongoose(circle)
|
|
58
|
+
Circle.validate((err, res) => {
|
|
59
|
+
assert.exists(err)
|
|
60
|
+
assert.isObject(err.errors)
|
|
61
|
+
assert.strictEqual(err.errors.radius.message, `radius [3m] must be greater than 5m`)
|
|
62
|
+
done()
|
|
63
|
+
})
|
|
64
|
+
})
|
|
65
|
+
|
|
54
66
|
assertions('should not validate a Circle with no radius', (done) => {
|
|
55
67
|
delete circle.radius
|
|
56
68
|
let Circle = new CircleModel(circle)
|
|
@@ -5,13 +5,36 @@
|
|
|
5
5
|
"creationTime": "2018-02-14T04:12:02.103Z",
|
|
6
6
|
"name": "A New Project",
|
|
7
7
|
"accountId":"b0824b76-ce73-4fcf-81f8-1b63edb1114e",
|
|
8
|
-
"webhooks": [
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"
|
|
8
|
+
"webhooks": [
|
|
9
|
+
{
|
|
10
|
+
"type": "geoTrigger",
|
|
11
|
+
"url": "https://webhooklistener.bluedotinnovation.com",
|
|
12
|
+
"headers" : {
|
|
13
|
+
"securityToken" : "value"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"type": "tempo",
|
|
18
|
+
"url": "https://webhooklistener.bluedotinnovation.com",
|
|
19
|
+
"headers" : {
|
|
20
|
+
"securityToken" : "value"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"type": "doorbell",
|
|
25
|
+
"url": "https://webhooklistener.bluedotinnovation.com",
|
|
26
|
+
"headers" : {
|
|
27
|
+
"securityToken" : "value"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"type": "trigger",
|
|
32
|
+
"url": "https://webhooklistener.bluedotinnovation.com",
|
|
33
|
+
"headers" : {
|
|
34
|
+
"securityToken" : "value"
|
|
35
|
+
}
|
|
13
36
|
}
|
|
14
|
-
|
|
37
|
+
],
|
|
15
38
|
"shouldSync": true,
|
|
16
39
|
"firebaseApiKey": "88888888-4444-4444-4444-121212121212",
|
|
17
40
|
"apiKey": "88888888-4444-4444-4444-123412341234",
|
|
@@ -24,14 +47,16 @@
|
|
|
24
47
|
}
|
|
25
48
|
},
|
|
26
49
|
"tempo": {
|
|
27
|
-
"
|
|
50
|
+
"isochroneBracketInterval": [60, 120, 300],
|
|
51
|
+
"webhooks": [
|
|
28
52
|
{
|
|
29
53
|
"type": "tempo",
|
|
30
54
|
"url": "https://webhooklistener.bluedotinnovation.com",
|
|
31
55
|
"headers" : {
|
|
32
56
|
"securityToken" : "value"
|
|
33
57
|
}
|
|
34
|
-
}
|
|
58
|
+
}
|
|
35
59
|
]
|
|
60
|
+
|
|
36
61
|
}
|
|
37
62
|
}
|
|
@@ -6,9 +6,8 @@
|
|
|
6
6
|
"name": "A New Project",
|
|
7
7
|
"accountId":"b0824b76-ce73-4fcf-81f8-1b63edb1114e",
|
|
8
8
|
"webhooks": {
|
|
9
|
-
"type": "
|
|
9
|
+
"type": "geoTrigger",
|
|
10
10
|
"url": "https://webhooklistener.bluedotinnovation.com",
|
|
11
|
-
"enabled": true,
|
|
12
11
|
"headers" : {
|
|
13
12
|
"securityToken" : "value"
|
|
14
13
|
}
|
|
@@ -120,4 +119,4 @@
|
|
|
120
119
|
"triggerEngine": "BD"
|
|
121
120
|
}
|
|
122
121
|
}
|
|
123
|
-
}
|
|
122
|
+
}
|
|
@@ -90,9 +90,11 @@ testCase('Project', () => {
|
|
|
90
90
|
done()
|
|
91
91
|
})
|
|
92
92
|
})
|
|
93
|
-
|
|
93
|
+
|
|
94
|
+
// TODO: Remove trigger type after migration
|
|
95
|
+
assertions(`should not validate if one of webhooks have a type other than 'geoTrigger', 'tempo', 'doorbell' or 'trigger'`, (done) => {
|
|
94
96
|
project.webhooks.push({
|
|
95
|
-
"type": "
|
|
97
|
+
"type": "sandwich",
|
|
96
98
|
"url": "https://webhooklistener.bluedotinnovation.com",
|
|
97
99
|
"headers" : {
|
|
98
100
|
"securityToken" : "value"
|
|
@@ -101,22 +103,7 @@ testCase('Project', () => {
|
|
|
101
103
|
let Project = new ProjectModel(project)
|
|
102
104
|
Project.validate((err, res) => {
|
|
103
105
|
assert.exists(err)
|
|
104
|
-
assert.match(err.message,
|
|
105
|
-
done()
|
|
106
|
-
})
|
|
107
|
-
})
|
|
108
|
-
assertions(`should not validate if one of tempo webhooks have a type orther than 'tempo'`, (done) => {
|
|
109
|
-
project.tempo.webhooks.push({
|
|
110
|
-
"type": "trigger",
|
|
111
|
-
"url": "https://webhooklistener.bluedotinnovation.com",
|
|
112
|
-
"headers" : {
|
|
113
|
-
"securityToken" : "value"
|
|
114
|
-
}
|
|
115
|
-
})
|
|
116
|
-
let Project = new ProjectModel(project)
|
|
117
|
-
Project.validate((err, res) => {
|
|
118
|
-
assert.exists(err)
|
|
119
|
-
assert.match(err.message, /tempo.webhooks should contain tempo webhooks only/)
|
|
106
|
+
assert.match(err.message, /`sandwich` is not a valid enum value for path `type`/)
|
|
120
107
|
done()
|
|
121
108
|
})
|
|
122
109
|
})
|
|
@@ -292,6 +279,48 @@ testCase('Project', () => {
|
|
|
292
279
|
})
|
|
293
280
|
})
|
|
294
281
|
|
|
282
|
+
testCase('should not validate if webhooks contains two webhooks of the same type', () => {
|
|
283
|
+
// TODO: Remove trigger type after migration
|
|
284
|
+
const webhookTypes = ['geoTrigger', 'tempo', 'doorbell', 'trigger']
|
|
285
|
+
|
|
286
|
+
webhookTypes.map(webhookType => {
|
|
287
|
+
assertions(`should not validate if there are duplicate ${webhookType} webhooks`, (done) => {
|
|
288
|
+
project.webhooks.push({
|
|
289
|
+
"type": webhookType,
|
|
290
|
+
"url": "https://webhooklistener.bluedotinnovation.com",
|
|
291
|
+
"headers" : {
|
|
292
|
+
"securityToken" : "value"
|
|
293
|
+
}
|
|
294
|
+
})
|
|
295
|
+
|
|
296
|
+
let Project = new ProjectModel(project)
|
|
297
|
+
Project.validate((err, res) => {
|
|
298
|
+
assert.exists(err)
|
|
299
|
+
assert.match(err.message, /Duplicate webhooks found. Only have one webhook of each type is allowed/)
|
|
300
|
+
done()
|
|
301
|
+
})
|
|
302
|
+
})
|
|
303
|
+
})
|
|
304
|
+
})
|
|
305
|
+
|
|
306
|
+
// TODO: Remove this test after migration
|
|
307
|
+
assertions(`should not validate if one of tempo webhooks have a type other than 'tempo'`, (done) => {
|
|
308
|
+
project.tempo.webhooks.push({
|
|
309
|
+
"type": "trigger",
|
|
310
|
+
"url": "https://webhooklistener.bluedotinnovation.com",
|
|
311
|
+
"headers" : {
|
|
312
|
+
"securityToken" : "value"
|
|
313
|
+
}
|
|
314
|
+
})
|
|
315
|
+
let Project = new ProjectModel(project)
|
|
316
|
+
Project.validate((err, res) => {
|
|
317
|
+
assert.exists(err)
|
|
318
|
+
assert.match(err.message, /tempo.webhooks should contain tempo webhooks only/)
|
|
319
|
+
done()
|
|
320
|
+
})
|
|
321
|
+
})
|
|
322
|
+
|
|
323
|
+
|
|
295
324
|
describe('should throw an error when any of the values of the array contains a falsy value', () => {
|
|
296
325
|
let arrayTypeFields = rules.arrayTypeFields
|
|
297
326
|
|
|
@@ -94,10 +94,8 @@ describe('Zone', () => {
|
|
|
94
94
|
assert.strictEqual(zone.tags[1], "1")
|
|
95
95
|
})
|
|
96
96
|
|
|
97
|
-
it('should save without errors when
|
|
98
|
-
zone.
|
|
99
|
-
"destinationId": null
|
|
100
|
-
}
|
|
97
|
+
it('should save without errors when destinationId is null', (done) => {
|
|
98
|
+
zone.destinationId = null;
|
|
101
99
|
let Zone = new ZoneModel(zone)
|
|
102
100
|
Zone.validate((err, res) => {
|
|
103
101
|
assert.notExists(res)
|
|
@@ -109,10 +107,8 @@ describe('Zone', () => {
|
|
|
109
107
|
const validTempoGeofeatureTypes = ['boundingBox', 'circle', 'polygon']
|
|
110
108
|
|
|
111
109
|
validTempoGeofeatureTypes.map(type => {
|
|
112
|
-
it(`should save without errors when
|
|
113
|
-
zone.
|
|
114
|
-
"destinationId": "test-destination-id"
|
|
115
|
-
}
|
|
110
|
+
it(`should save without errors when destinationId is set and there is a single ${type} geofeature`, (done) => {
|
|
111
|
+
zone.destinationId = "test-destination-id";
|
|
116
112
|
zone.geofeatures = zone.geofeatures.filter(gf => gf.type.match(new RegExp(type)))
|
|
117
113
|
let Zone = new ZoneModel(zone)
|
|
118
114
|
Zone.validate((err, res) => {
|
|
@@ -419,6 +415,73 @@ describe('Zone', () => {
|
|
|
419
415
|
})
|
|
420
416
|
})
|
|
421
417
|
|
|
418
|
+
it('should throw an error when destinationId is longer than 128 characters', (done) => {
|
|
419
|
+
zone.destinationId = 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry standard dummy text ever since the 1500s';
|
|
420
|
+
let Zone = new ZoneModel(zone)
|
|
421
|
+
Zone.validate((err, res) => {
|
|
422
|
+
assert.exists(err, 'err object should exist')
|
|
423
|
+
assert.match(err.message, /(destinationId must be less than 129 characters long)/i)
|
|
424
|
+
done()
|
|
425
|
+
})
|
|
426
|
+
})
|
|
427
|
+
|
|
428
|
+
const invalidTempoGeofeatures = ['geoline', 'beacon']
|
|
429
|
+
|
|
430
|
+
invalidTempoGeofeatures.map(type => {
|
|
431
|
+
it(`should throw an error when destinationId is set and there is a single ${type} geofeature`, (done) => {
|
|
432
|
+
zone.destinationId = "test-destination-id";
|
|
433
|
+
zone.geofeatures = zone.geofeatures.filter(gf => gf.type.match(new RegExp(type)))
|
|
434
|
+
let Zone = new ZoneModel(zone)
|
|
435
|
+
Zone.validate((err, res) => {
|
|
436
|
+
assert.exists(err, 'err object should exist')
|
|
437
|
+
assert.match(err.message, /(destinationId cannot be set on zones with a geoline or beacon)/i)
|
|
438
|
+
done()
|
|
439
|
+
})
|
|
440
|
+
})
|
|
441
|
+
})
|
|
442
|
+
|
|
443
|
+
it('should throw an error when destinationId is set and there is more than one geofeature', (done) => {
|
|
444
|
+
zone.destinationId = "test-destination-id";
|
|
445
|
+
let Zone = new ZoneModel(zone)
|
|
446
|
+
Zone.validate((err, res) => {
|
|
447
|
+
assert.exists(err, 'err object should exist')
|
|
448
|
+
assert.match(err.message, /(destinationId can only be set on zones with a single geofeature)/i)
|
|
449
|
+
done()
|
|
450
|
+
})
|
|
451
|
+
})
|
|
452
|
+
})
|
|
453
|
+
|
|
454
|
+
// TODO: Remove all tests in below describe block after migration
|
|
455
|
+
describe("tempo.destinationId tests", () => {
|
|
456
|
+
it('should save without errors when tempo.destinationId is null', (done) => {
|
|
457
|
+
zone.tempo = {
|
|
458
|
+
destinationId: null
|
|
459
|
+
}
|
|
460
|
+
let Zone = new ZoneModel(zone)
|
|
461
|
+
Zone.validate((err, res) => {
|
|
462
|
+
assert.notExists(res)
|
|
463
|
+
assert.notExists(err)
|
|
464
|
+
done()
|
|
465
|
+
})
|
|
466
|
+
})
|
|
467
|
+
|
|
468
|
+
const validTempoGeofeatureTypes = ['boundingBox', 'circle', 'polygon']
|
|
469
|
+
|
|
470
|
+
validTempoGeofeatureTypes.map(type => {
|
|
471
|
+
it(`should save without errors when tempo.destinationId is set and there is a single ${type} geofeature`, (done) => {
|
|
472
|
+
zone.tempo = {
|
|
473
|
+
"destinationId": "test-destination-id"
|
|
474
|
+
}
|
|
475
|
+
zone.geofeatures = zone.geofeatures.filter(gf => gf.type.match(new RegExp(type)))
|
|
476
|
+
let Zone = new ZoneModel(zone)
|
|
477
|
+
Zone.validate((err, res) => {
|
|
478
|
+
assert.notExists(res)
|
|
479
|
+
assert.notExists(err)
|
|
480
|
+
done()
|
|
481
|
+
})
|
|
482
|
+
})
|
|
483
|
+
})
|
|
484
|
+
|
|
422
485
|
it('should throw an error when tempo.destinationId is longer than 128 characters', (done) => {
|
|
423
486
|
zone.tempo = {
|
|
424
487
|
"destinationId": 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry standard dummy text ever since the 1500s'
|
package/helpers.js
CHANGED
|
@@ -240,16 +240,16 @@ helpers.ensureNonEmptyGeofeatures = function(zone, next){
|
|
|
240
240
|
next()
|
|
241
241
|
}
|
|
242
242
|
|
|
243
|
-
helpers.
|
|
244
|
-
if(
|
|
245
|
-
return !(
|
|
243
|
+
helpers.validateDestinationIdLength = function(destinationId) {
|
|
244
|
+
if(destinationId){
|
|
245
|
+
return !(destinationId.length > 128)
|
|
246
246
|
}
|
|
247
247
|
return true
|
|
248
248
|
}
|
|
249
249
|
|
|
250
|
-
helpers.
|
|
251
|
-
if(
|
|
252
|
-
const geofeatures = this.
|
|
250
|
+
helpers.validateDestinationSingleGeofeature = function(destinationId) {
|
|
251
|
+
if(destinationId){
|
|
252
|
+
const geofeatures = this.geofeatures
|
|
253
253
|
if(!geofeatures.length){
|
|
254
254
|
return false
|
|
255
255
|
}
|
|
@@ -258,21 +258,30 @@ helpers.validateTempoDestinationSingleGeofeature = function(tempoDestinationId)
|
|
|
258
258
|
return true
|
|
259
259
|
}
|
|
260
260
|
|
|
261
|
-
helpers.
|
|
262
|
-
const geofeatures = this.
|
|
263
|
-
if(
|
|
261
|
+
helpers.validateDestinationIdGeofeatureType = function(destinationId) {
|
|
262
|
+
const geofeatures = this.geofeatures
|
|
263
|
+
if(destinationId && geofeatures.length){
|
|
264
264
|
return !(geofeatures[0].type === 'geoline' || geofeatures[0].type === 'beacon')
|
|
265
265
|
}
|
|
266
266
|
return true
|
|
267
267
|
}
|
|
268
268
|
|
|
269
|
-
helpers.
|
|
270
|
-
|
|
271
|
-
|
|
269
|
+
helpers.validateNoDuplicateWebhookTypes = function(webhookArray) {
|
|
270
|
+
// TODO: Remove trigger type after migration
|
|
271
|
+
const webhookTypes = ['geoTrigger', 'tempo', 'doorbell', 'trigger']
|
|
272
|
+
const webhookCounts = {};
|
|
273
|
+
webhookTypes.forEach(webhookType => webhookCounts[webhookType] = 0);
|
|
274
|
+
let duplicateFound = false
|
|
275
|
+
webhookArray.forEach(webhook => {
|
|
276
|
+
if(webhookCounts[webhook.type] > 0){
|
|
277
|
+
duplicateFound = true
|
|
278
|
+
}
|
|
279
|
+
webhookCounts[webhook.type]++
|
|
272
280
|
})
|
|
273
|
-
return !
|
|
281
|
+
return !duplicateFound;
|
|
274
282
|
}
|
|
275
283
|
|
|
284
|
+
// TODO: Remove below three methods after migration
|
|
276
285
|
helpers.validateTempoWebhooks = function(webhooks) {
|
|
277
286
|
const notTempo = webhooks.some(webhook => {
|
|
278
287
|
return webhook.type && webhook.type != 'tempo'
|
|
@@ -280,4 +289,24 @@ helpers.validateTempoWebhooks = function(webhooks) {
|
|
|
280
289
|
return !notTempo
|
|
281
290
|
}
|
|
282
291
|
|
|
292
|
+
helpers.validateTempoDestinationSingleGeofeature = function(destinationId) {
|
|
293
|
+
if(destinationId){
|
|
294
|
+
const geofeatures = this.ownerDocument().geofeatures
|
|
295
|
+
if(!geofeatures.length){
|
|
296
|
+
return false
|
|
297
|
+
}
|
|
298
|
+
return geofeatures.length === 1
|
|
299
|
+
}
|
|
300
|
+
return true
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
helpers.validateTempoDestinationIdGeofeatureType = function(destinationId) {
|
|
304
|
+
const geofeatures = this.ownerDocument().geofeatures
|
|
305
|
+
if(destinationId && geofeatures.length){
|
|
306
|
+
return !(geofeatures[0].type === 'geoline' || geofeatures[0].type === 'beacon')
|
|
307
|
+
}
|
|
308
|
+
return true
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
|
|
283
312
|
module.exports = helpers
|
package/models/Project.js
CHANGED
|
@@ -19,7 +19,7 @@ let projectTempoSchema = require('../schemas/ProjectTempo')
|
|
|
19
19
|
|
|
20
20
|
let webhooksValidators = [
|
|
21
21
|
{validator: helpers.validateNotNull},
|
|
22
|
-
{validator: helpers.
|
|
22
|
+
{validator: helpers.validateNoDuplicateWebhookTypes, msg: "Duplicate webhooks found. Only have one webhook of each type is allowed"}
|
|
23
23
|
];
|
|
24
24
|
|
|
25
25
|
let ProjectSchema = new mongoose.Schema({
|
package/models/Zone.js
CHANGED
|
@@ -120,9 +120,27 @@ let zoneSchema = new Schema({
|
|
|
120
120
|
projectId: {type: String, required: true, validate: {validator: helpers.validateUUIDv4, message: 'Invalid Project Id.'}},
|
|
121
121
|
state: {type: String, default: StateEnum.ACTIVE, select: false},
|
|
122
122
|
accountId: {type: String, required: true, validate: {validator: helpers.validateUUIDv4, msg: 'default error message'}},
|
|
123
|
+
destinationId: {type: String, validate: [
|
|
124
|
+
{ validator: helpers.validateDestinationIdLength, msg: 'destinationId must be less than 129 characters long' },
|
|
125
|
+
{ validator: helpers.validateDestinationSingleGeofeature, msg: 'destinationId can only be set on zones with a single geofeature' },
|
|
126
|
+
{ validator: helpers.validateDestinationIdGeofeatureType, msg: 'destinationId cannot be set on zones with a geoline or beacon' }
|
|
127
|
+
]},
|
|
128
|
+
// TODO: Remove tempo object after migration
|
|
123
129
|
tempo: zoneTempoSchema
|
|
124
130
|
}, {collection: 'zone', autoIndex: false})
|
|
125
131
|
|
|
132
|
+
zoneSchema.index(
|
|
133
|
+
{
|
|
134
|
+
projectId: 1,
|
|
135
|
+
destinationId: 1
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
unique: true,
|
|
139
|
+
partialFilterExpression: { 'destinationId': { $exists:true, $type:"string" } },
|
|
140
|
+
name: "destinationUniqueWithinProject"
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
// TODO: Remove below index after migration
|
|
126
144
|
zoneSchema.index(
|
|
127
145
|
{
|
|
128
146
|
projectId: 1,
|
|
@@ -10,7 +10,17 @@ let schema = {
|
|
|
10
10
|
name: {type: String, required: [true, 'name is required. ']},
|
|
11
11
|
color: String,
|
|
12
12
|
accuracy: {type: String, enum: Object.values(ZoneEnum.fenceAccuracy)},
|
|
13
|
-
radius: {
|
|
13
|
+
radius: {
|
|
14
|
+
type: Double,
|
|
15
|
+
required: [true, 'radius is required. '],
|
|
16
|
+
validate: {
|
|
17
|
+
validator: function(v) {
|
|
18
|
+
return (v >= 5) ;
|
|
19
|
+
},
|
|
20
|
+
message: props => `radius [${props.value}m] must be greater than 5m`
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
},
|
|
14
24
|
center: {type: Point, required: [true, 'center is required. ']}
|
|
15
25
|
}
|
|
16
26
|
|
package/package.json
CHANGED
package/schemas/ProjectTempo.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
let mongoose = require('mongoose')
|
|
2
|
+
// TODO: Remove below imports after migration
|
|
2
3
|
let WebhookSchema = require('./Webhook')
|
|
3
4
|
let helpers = require('../helpers')
|
|
4
5
|
|
|
@@ -10,14 +11,16 @@ function validateIsochroneBracketInterval (brackets) {
|
|
|
10
11
|
return isInteger
|
|
11
12
|
}
|
|
12
13
|
|
|
14
|
+
// TODO: Remove below validators after migration
|
|
13
15
|
let webhooksValidators = [
|
|
14
16
|
{validator: helpers.validateNotNull},
|
|
15
17
|
{validator: helpers.validateTempoWebhooks, msg: 'tempo.webhooks should contain tempo webhooks only'}
|
|
16
18
|
];
|
|
17
19
|
|
|
18
20
|
let ProjectTempoSchema = new mongoose.Schema({
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
isochroneBracketInterval: {type: [Number], validate: { validator: validateIsochroneBracketInterval, msg: 'tempo.isochroneBracketInterval should contain integer numbers only' }},
|
|
22
|
+
// TODO: Remove webhooks after migration
|
|
23
|
+
webhooks: {type:[WebhookSchema], validate: webhooksValidators}
|
|
21
24
|
}, {
|
|
22
25
|
_id: false
|
|
23
26
|
})
|
package/schemas/Webhook.js
CHANGED
|
@@ -2,7 +2,8 @@ let mongoose = require('mongoose')
|
|
|
2
2
|
let validators = require('../utils/validators')
|
|
3
3
|
|
|
4
4
|
let WebhookSchema = new mongoose.Schema({
|
|
5
|
-
|
|
5
|
+
// TODO: Remove trigger type after migration
|
|
6
|
+
type: {type: String, enum: ['geoTrigger', 'tempo', 'doorbell', 'trigger'], required: [true, 'webhook type is required']},
|
|
6
7
|
url: {type: String, required: [true, 'URL is required'], validate: {validator: validators.validateUrl, msg: 'Please enter a valid URL'}},
|
|
7
8
|
headers: {type: mongoose.Schema.Types.Mixed, validate: { validator: validateHeaderlength, msg: 'Header object can only have 1 key <-> value pair' }}
|
|
8
9
|
}, {
|
package/schemas/ZoneTempo.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
// TODO: Remove this file after migration
|
|
1
2
|
let mongoose = require('mongoose')
|
|
2
3
|
let helpers = require('../helpers')
|
|
3
4
|
|
|
4
5
|
let ZoneTempoSchema = new mongoose.Schema({
|
|
5
6
|
destinationId: {type: String, validate: [
|
|
6
|
-
{ validator: helpers.
|
|
7
|
+
{ validator: helpers.validateDestinationIdLength, msg: 'destinationId must be less than 129 characters long' },
|
|
7
8
|
{ validator: helpers.validateTempoDestinationSingleGeofeature, msg: 'destinationId can only be set on zones with a single geofeature' },
|
|
8
9
|
{ validator: helpers.validateTempoDestinationIdGeofeatureType, msg: 'destinationId cannot be set on zones with a geoline or beacon' }
|
|
9
10
|
]}
|
|
@@ -7,6 +7,18 @@
|
|
|
7
7
|
*/
|
|
8
8
|
const indexes = {
|
|
9
9
|
zone: [
|
|
10
|
+
{
|
|
11
|
+
fields: {
|
|
12
|
+
projectId: 1,
|
|
13
|
+
destinationId: 1
|
|
14
|
+
},
|
|
15
|
+
options: {
|
|
16
|
+
unique: true,
|
|
17
|
+
partialFilterExpression: { destinationId: { $exists:true, $type:"string" } },
|
|
18
|
+
name: "destinationUniqueWithinProject"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
// TODO: Remove below index after migration
|
|
10
22
|
{
|
|
11
23
|
fields: {
|
|
12
24
|
projectId: 1,
|