Skip to content

Commit

Permalink
Merge pull request #33 from sebelga/release/v0.9.1
Browse files Browse the repository at this point in the history
Release/v0.9.1
  • Loading branch information
sebelga authored Dec 17, 2016
2 parents ac25626 + a46731f commit 781e2e0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1581,7 +1581,7 @@ query.run({ format: gstore.Queries.formats.ENTITY })
gstore.save(entities).then(() => {
...
});
})
});

```
Expand Down
14 changes: 8 additions & 6 deletions lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -937,9 +937,7 @@ class Model extends Entity {
if (is.object(propertyValue) && Object.keys(propertyValue).length === 2
&& {}.hasOwnProperty.call(propertyValue, 'longitude')
&& {}.hasOwnProperty.call(propertyValue, 'latitude')) {
const validLng = validateLngLat(propertyValue.longitude);
const validLat = validateLngLat(propertyValue.latitude);
typeValid = validLng && validLat;
typeValid = validateLngLat(propertyValue);
} else {
typeValid = propertyValue.constructor.name === 'GeoPoint';
}
Expand Down Expand Up @@ -1025,9 +1023,13 @@ class Model extends Entity {
(typeof v === 'string' && v.trim().length === 0);
}

function validateLngLat(value) {
const regEx = /^-?([1-8]?[1-9]|[1-9]0)\.{1}\d{1,6}/;
return regEx.test(value);
function validateLngLat(data) {
const validLatitude = (isInt(data.latitude) || isFloat(data.latitude))
&& data.latitude >= -90 && data.latitude <= 90;
const validLongitude = (isInt(data.longitude) || isFloat(data.longitude))
&& data.longitude >= -180 && data.longitude <= 180;

return validLatitude && validLongitude;
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gstore-node",
"version": "0.9.0",
"version": "0.9.1",
"description": "gstore-node is a Google Datastore Entity Models tools",
"main": "index.js",
"scripts": {
Expand Down
8 changes: 6 additions & 2 deletions test/model-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1749,8 +1749,8 @@ describe('Model', () => {
// valid geo object
const model3 = new ModelInstance({
location: {
latitude: 40.6894,
longitude: -74.0447,
latitude: 40.68942342541,
longitude: -74.044743654572,
},
});
const valid3 = model3.validate();
Expand All @@ -1765,12 +1765,16 @@ describe('Model', () => {
const model6 = new ModelInstance({ location: { longitude: 40.6895 } });
const valid6 = model6.validate();

const model7 = new ModelInstance({ location: { longitude: '120.123', latitude: '40.12345678' } });
const valid7 = model7.validate();

expect(valid.success).equal(false);
expect(valid2.success).equal(true);
expect(valid3.success).equal(true);
expect(valid4.success).equal(false);
expect(valid5.success).equal(false);
expect(valid6.success).equal(false);
expect(valid7.success).equal(false);
});

it('--> array ok', () => {
Expand Down

0 comments on commit 781e2e0

Please sign in to comment.