-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added helper functions to validate post data and to transforma geojson data. - Added helper functions to apagon and lugar post endpoints
- Loading branch information
Froilan Irizarry
committed
Apr 14, 2019
1 parent
b37da3a
commit a00ef01
Showing
3 changed files
with
53 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
const getApagonesDBClient = require('./apagones-client'); | ||
const { validatePostData,transformGeoData } = require('./utils') | ||
|
||
module.exports = { | ||
getApagonesDBClient | ||
getApagonesDBClient, | ||
validatePostData, | ||
transformGeoData | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
function validatePostData(data) { | ||
if(data.hasOwnProperty('location')) { | ||
if(!data.location.hasOwnProperty('lat')) { | ||
throw Error('`lat` property missing from location'); | ||
} | ||
if(!data.location.hasOwnProperty('lng')) { | ||
throw Error('`lat` property missing from location'); | ||
} | ||
} else { | ||
throw Error('`location` property is required'); | ||
} | ||
|
||
if(!data.hasOwnProperty('type')) { | ||
throw Error('`type` property is required'); | ||
} | ||
if(!data.hasOwnProperty('source')) { | ||
throw Error('`source` property is required'); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
function transformGeoData({ geoDataType="Point", data }) { | ||
const transformedData = data; | ||
const { lat, lng } = data.location; | ||
|
||
transformedData.location = { | ||
type: geoDataType, | ||
coordinates: [ lng, lat ] | ||
} | ||
|
||
return transformedData; | ||
} | ||
|
||
module.exports = { | ||
validatePostData, | ||
transformGeoData | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters