@bluedot-innovation/models 10.0.0-beta-4 → 10.0.0-beta-5
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/helpers.js +9 -0
- package/models/geofeatures/Circle.js +3 -1
- package/package.json +1 -1
- package/schemas/Point.js +2 -2
- package/schemas/PointGeometry.js +3 -2
package/helpers.js
CHANGED
|
@@ -267,4 +267,13 @@ helpers.validateNoDuplicateReportConfigurations = function(reportConfigArray) {
|
|
|
267
267
|
return true;
|
|
268
268
|
}
|
|
269
269
|
|
|
270
|
+
helpers.transformDecimal128 = (value) => {
|
|
271
|
+
try {
|
|
272
|
+
return value === null ? null : parseFloat(value)
|
|
273
|
+
} catch(err) {
|
|
274
|
+
return value
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
}
|
|
278
|
+
|
|
270
279
|
module.exports = helpers
|
|
@@ -2,6 +2,7 @@ let mongoose = require('mongoose')
|
|
|
2
2
|
let ZoneEnum = require('@bluedot-innovation/enums').ZoneEnum
|
|
3
3
|
let Point = require('../../schemas/Point')
|
|
4
4
|
let uuidv4 = require('uuid/v4')
|
|
5
|
+
const { transformDecimal128 } = require('../../helpers')
|
|
5
6
|
|
|
6
7
|
let schema = {
|
|
7
8
|
_id: {type: String, default: uuidv4},
|
|
@@ -10,7 +11,8 @@ let schema = {
|
|
|
10
11
|
color: String,
|
|
11
12
|
accuracy: {type: String, enum: Object.values(ZoneEnum.fenceAccuracy)},
|
|
12
13
|
radius: {
|
|
13
|
-
type:
|
|
14
|
+
type: mongoose.Types.Decimal128,
|
|
15
|
+
get: transformDecimal128,
|
|
14
16
|
required: [true, 'radius is required. '],
|
|
15
17
|
validate: {
|
|
16
18
|
validator: function(v) {
|
package/package.json
CHANGED
package/schemas/Point.js
CHANGED
|
@@ -3,8 +3,8 @@ const helpers = require("../helpers")
|
|
|
3
3
|
|
|
4
4
|
let PointSchema = new mongoose.Schema({
|
|
5
5
|
type: {type: String},
|
|
6
|
-
latitude: {type:
|
|
7
|
-
longitude: {type:
|
|
6
|
+
latitude: {type: mongoose.Types.Decimal128, get: helpers.transformDecimal128, required: [true, 'latitude is required. '], validate: {validator: helpers.validateLatitude, message: "latitude must be between a value between -90 and 90"}},
|
|
7
|
+
longitude: {type: mongoose.Types.Decimal128, get: helpers.transformDecimal128, required: [true, 'longitude is required. '], validate: {validator: helpers.validateLongitude, message: "longitude must be between a value between -180 and 180"}}
|
|
8
8
|
},
|
|
9
9
|
{
|
|
10
10
|
_id: false,
|
package/schemas/PointGeometry.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
let mongoose = require('mongoose')
|
|
2
|
+
const { transformDecimal128 } = require('../helpers')
|
|
2
3
|
|
|
3
4
|
let PointGeometrySchema = new mongoose.Schema(
|
|
4
5
|
{
|
|
5
6
|
type: {type: String, match: /Point/},
|
|
6
|
-
coordinates: [{type:
|
|
7
|
-
{type:
|
|
7
|
+
coordinates: [{type: mongoose.Types.Decimal128, get: transformDecimal128, required: [true, 'longitude is required. '], min: -180, max: 180},
|
|
8
|
+
{type: mongoose.Types.Decimal128, get: transformDecimal128, required: [true, 'latitude is required. '], min: -90, max: 90}]
|
|
8
9
|
},
|
|
9
10
|
{
|
|
10
11
|
_id: false,
|