From fba74d8e9cf5cbd3054caf453194fdfadbc87ce3 Mon Sep 17 00:00:00 2001 From: efarooqui Date: Tue, 11 Aug 2020 21:40:34 -0700 Subject: [PATCH] Wrote validation functions and getter to grab appropriate validation function --- package.json | 1 + src/config.js | 8 +++++++- src/lib/util.js | 2 +- src/lib/validation.js | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 src/lib/validation.js diff --git a/package.json b/package.json index 5d518fa..2220fd0 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "express-handlebars": "^4.0.4", "googleapis": "^32.0.0", "graphql": "^0.13.2", + "moment": "^2.27.0", "morgan": "^1.8.0", "mz": "^2.7.0", "node-fetch": "^2.3.0", diff --git a/src/config.js b/src/config.js index 31c18be..c49055d 100644 --- a/src/config.js +++ b/src/config.js @@ -1,7 +1,13 @@ import { timemap } from './lib' export default { - gsheets: [], + gsheets: [ + { + name: 'us2020', + id: '1I_pgyTQJlIorTIEHBxw1mM1STn-SrIi66FKYxut61iM', + tabs: timemap.default + } + ], xlsx: [ { name: 'timemap_data', diff --git a/src/lib/util.js b/src/lib/util.js index e213df1..d619985 100755 --- a/src/lib/util.js +++ b/src/lib/util.js @@ -1,4 +1,4 @@ -import R from 'ramda' +import R from 'ramda'; /* eslint-disable */ String.prototype.replaceAll = function (search, replacement) { diff --git a/src/lib/validation.js b/src/lib/validation.js new file mode 100644 index 0000000..307537c --- /dev/null +++ b/src/lib/validation.js @@ -0,0 +1,35 @@ +import moment from 'moment'; + +const DATE_FORMAT = "MM/DD/YYYY"; +const TIME_REGEX = "^([01]\d|2[0-3]):?([0-5]\d)$" + +export const validateLongitude = value => { + return isFinite(value) && Math.abs(value) <= 180; +} + +export const validateLatitude = value => { + return isFinite(lat) && Math.abs(lat) <= 90; +} + +export const validateDate = date => { + return moment(date, DATE_FORMAT, true).isValid(); +} + +export const validateTime = time => { + return TIME_REGEX.test(time); +} + + +export const getColumnValidator = colName => { + switch(colName) { + case 'longitue': + return validateLongitude; + case 'latitude': + return validateLatitude; + case 'date': + return validateDate; + case 'time': + return validateTime; + default: () => return true; + } +} \ No newline at end of file