@bluedot-innovation/models 3.1.0 → 3.1.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 +4 -0
- package/Models.js +2 -2
- package/__tests__/geofeature/{polyline/polyline.data.json → geoline/geoline.data.json} +3 -3
- package/__tests__/geofeature/{polyline/polyline.spec.js → geoline/geoline.spec.js} +22 -22
- package/__tests__/zone/zone.data.json +2 -2
- package/__tests__/zone/zone.spec.js +2 -2
- package/models/Zone.js +2 -2
- package/models/geofeatures/{Polyline.js → Geoline.js} +8 -8
- package/package.json +1 -1
- package/validators/checkDistanceBetweenVertices.js +1 -1
- /package/__tests__/geofeature/{polyline/polyline.rules.json → geoline/geoline.rules.json} +0 -0
package/CHANGELOG.md
CHANGED
package/Models.js
CHANGED
|
@@ -19,7 +19,7 @@ Models.Zone = require('./models/Zone').Model
|
|
|
19
19
|
Models.BoundingBox = require('./models/geofeatures/BoundingBox').Model
|
|
20
20
|
Models.Circle = require('./models/geofeatures/Circle').Model
|
|
21
21
|
Models.Polygon = require('./models/geofeatures/Polygon').Model
|
|
22
|
-
Models.
|
|
22
|
+
Models.Geoline = require('./models/geofeatures/Geoline').Model
|
|
23
23
|
Models.ZoneBeacon = require('./models/geofeatures/ZoneBeacon').Model
|
|
24
24
|
|
|
25
25
|
// Conditions
|
|
@@ -45,7 +45,7 @@ Schemas.Zone = require('./models/Zone').Schema
|
|
|
45
45
|
Schemas.BoundingBox = require('./models/geofeatures/BoundingBox').Schema
|
|
46
46
|
Schemas.Circle = require('./models/geofeatures/Circle').Schema
|
|
47
47
|
Schemas.Polygon = require('./models/geofeatures/Polygon').Schema
|
|
48
|
-
Schemas.
|
|
48
|
+
Schemas.Geoline = require('./models/geofeatures/Geoline').Schema
|
|
49
49
|
Schemas.ZoneBeacon = require('./models/geofeatures/ZoneBeacon').Schema
|
|
50
50
|
|
|
51
51
|
// Conditions
|
|
@@ -2,8 +2,8 @@ let mongoose = require('mongoose')
|
|
|
2
2
|
|
|
3
3
|
mongoose.Promise = global.Promise
|
|
4
4
|
|
|
5
|
-
let
|
|
6
|
-
let
|
|
5
|
+
let GeolineModel = require('../../../Models').Geoline(mongoose)
|
|
6
|
+
let GeolineModelBuiltInMongoose = require('../../../Models').Geoline()
|
|
7
7
|
let testCase = require('mocha').describe
|
|
8
8
|
let assertions = require('mocha').it
|
|
9
9
|
let chai = require('chai')
|
|
@@ -12,26 +12,26 @@ let assert = chai.assert
|
|
|
12
12
|
let mocha = require('mocha')
|
|
13
13
|
let beforeEach = mocha.beforeEach
|
|
14
14
|
|
|
15
|
-
let rules = require('./
|
|
15
|
+
let rules = require('./geoline.rules.json')
|
|
16
16
|
|
|
17
|
-
let
|
|
17
|
+
let geoline
|
|
18
18
|
|
|
19
19
|
beforeEach(() => {
|
|
20
|
-
|
|
20
|
+
geoline = JSON.parse(JSON.stringify(require('./geoline.data.json')))
|
|
21
21
|
})
|
|
22
|
-
testCase('
|
|
23
|
-
testCase('Valid
|
|
24
|
-
assertions('should validate a valid
|
|
25
|
-
let
|
|
26
|
-
|
|
22
|
+
testCase('Geoline', () => {
|
|
23
|
+
testCase('Valid Geoline', () => {
|
|
24
|
+
assertions('should validate a valid geoline ', (done) => {
|
|
25
|
+
let Geoline = new GeolineModel(geoline)
|
|
26
|
+
Geoline.validate((err, res) => {
|
|
27
27
|
assert.notExists(res)
|
|
28
28
|
assert(err === null, 'err should equals null')
|
|
29
29
|
done()
|
|
30
30
|
})
|
|
31
31
|
})
|
|
32
|
-
assertions('should validate a valid
|
|
33
|
-
let
|
|
34
|
-
|
|
32
|
+
assertions('should validate a valid geoline (built in mongoose)', (done) => {
|
|
33
|
+
let Geoline = new GeolineModelBuiltInMongoose(geoline)
|
|
34
|
+
Geoline.validate((err, res) => {
|
|
35
35
|
assert.notExists(res)
|
|
36
36
|
assert(err === null, 'err should equals null')
|
|
37
37
|
done()
|
|
@@ -39,11 +39,11 @@ testCase('Polyline', () => {
|
|
|
39
39
|
})
|
|
40
40
|
})
|
|
41
41
|
|
|
42
|
-
testCase('Invalid
|
|
43
|
-
assertions('should not validate a
|
|
44
|
-
delete
|
|
45
|
-
let
|
|
46
|
-
|
|
42
|
+
testCase('Invalid Geoline', () => {
|
|
43
|
+
assertions('should not validate a geoline with invalid geoline', (done) => {
|
|
44
|
+
delete geoline[rules.requiredFields[0]]
|
|
45
|
+
let Geoline = new GeolineModel(geoline)
|
|
46
|
+
Geoline.validate((err, res) => {
|
|
47
47
|
assert.exists(err, 'err object should exist')
|
|
48
48
|
assert.isObject(err)
|
|
49
49
|
done()
|
|
@@ -53,10 +53,10 @@ testCase('Polyline', () => {
|
|
|
53
53
|
let requiredFields = rules.requiredFields
|
|
54
54
|
requiredFields.map((i) => {
|
|
55
55
|
assertions(`should throw an error with property '${i}' if '${i}' is not present`, (done) => {
|
|
56
|
-
// delete i from geofeatures'
|
|
57
|
-
delete
|
|
58
|
-
let
|
|
59
|
-
|
|
56
|
+
// delete i from geofeatures' geoline child
|
|
57
|
+
delete geoline[i]
|
|
58
|
+
let Geoline = new GeolineModel(geoline)
|
|
59
|
+
Geoline.validate((err, res) => {
|
|
60
60
|
assert.notExists(res)
|
|
61
61
|
assert.exists(err, 'err object should exist')
|
|
62
62
|
assert.isObject(err)
|
|
@@ -57,8 +57,8 @@ describe('Zone', () => {
|
|
|
57
57
|
})
|
|
58
58
|
})
|
|
59
59
|
|
|
60
|
-
it('should instantiate a
|
|
61
|
-
zone.geofeatures = zone.geofeatures.filter(gf => gf.type.match(/^
|
|
60
|
+
it('should instantiate a geoline', (done) => {
|
|
61
|
+
zone.geofeatures = zone.geofeatures.filter(gf => gf.type.match(/^geoline$/))
|
|
62
62
|
let Zone = new ZoneModel(zone)
|
|
63
63
|
Zone.validate((err, res) => {
|
|
64
64
|
assert.notExists(res)
|
package/models/Zone.js
CHANGED
|
@@ -11,7 +11,7 @@ let messageActionSchema = require('./MessageAction').messageActionSchema
|
|
|
11
11
|
let urlActionSchema = require('./UrlAction').urlActionSchema
|
|
12
12
|
let circleSchema = require('./geofeatures/Circle').circleSchema
|
|
13
13
|
let boundingBoxSchema = require('./geofeatures/BoundingBox').boundingBoxSchema
|
|
14
|
-
let
|
|
14
|
+
let geolineSchema = require('./geofeatures/Geoline').geolineSchema
|
|
15
15
|
let polygonSchema = require('./geofeatures/Polygon').polygonSchema
|
|
16
16
|
let beaconSchema = require('./geofeatures/ZoneBeacon').beaconSchema
|
|
17
17
|
|
|
@@ -92,7 +92,7 @@ zoneSchema.path('conditions').discriminator('travelPath', new Schema(travelPathR
|
|
|
92
92
|
zoneSchema.path('geofeatures').discriminator('beacon', new Schema(beaconSchema))
|
|
93
93
|
zoneSchema.path('geofeatures').discriminator('circle', new Schema(circleSchema))
|
|
94
94
|
zoneSchema.path('geofeatures').discriminator('polygon', new Schema(polygonSchema))
|
|
95
|
-
zoneSchema.path('geofeatures').discriminator('
|
|
95
|
+
zoneSchema.path('geofeatures').discriminator('geoline', new Schema(geolineSchema))
|
|
96
96
|
zoneSchema.path('geofeatures').discriminator('boundingBox', new Schema(boundingBoxSchema))
|
|
97
97
|
|
|
98
98
|
zoneSchema.pre('validate', function(next) {
|
|
@@ -7,28 +7,28 @@ const schema = {
|
|
|
7
7
|
_id: {type: String, default: uuidv4},
|
|
8
8
|
geometry: {type: {}},
|
|
9
9
|
name: {type: String, required: [true, 'name is required. ']},
|
|
10
|
-
vertices: {type: [Point], required: [true, 'vertices
|
|
10
|
+
vertices: {type: [Point], required: [true, 'vertices are required. ']}
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
const
|
|
13
|
+
const GeolineSchema = new mongoose.Schema(schema, {
|
|
14
14
|
_id: false,
|
|
15
15
|
versionKey: false
|
|
16
16
|
})
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
GeolineSchema.add({
|
|
19
19
|
type: {type: String, required: true}
|
|
20
20
|
})
|
|
21
21
|
|
|
22
22
|
// optional mongoose
|
|
23
23
|
let model = (mongooseInstance) => {
|
|
24
|
-
let
|
|
24
|
+
let Geoline
|
|
25
25
|
if (mongooseInstance) {
|
|
26
|
-
|
|
26
|
+
Geoline = mongooseInstance.model('Geoline', GeolineSchema)
|
|
27
27
|
} else {
|
|
28
|
-
|
|
28
|
+
Geoline = mongoose.model('Geoline', GeolineSchema)
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
return
|
|
31
|
+
return Geoline
|
|
32
32
|
}
|
|
33
33
|
// Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
|
|
34
|
-
module.exports = { Model: model, Schema:
|
|
34
|
+
module.exports = { Model: model, Schema: GeolineSchema, geolineSchema: schema }
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@ const { notSameThreeInARow, trimDecimals } = require('../utils');
|
|
|
4
4
|
/**
|
|
5
5
|
* checkDistanceBetweenVertices -
|
|
6
6
|
* Returns boolean signalling whether or not enough space between points in
|
|
7
|
-
* polygons and
|
|
7
|
+
* polygons and geolines. Checks closeness by checking if the same when trimmed
|
|
8
8
|
* to 6 decimal places
|
|
9
9
|
*/
|
|
10
10
|
const checkDistanceBetweenVertices = function(vertices) {
|
|
File without changes
|