mirror of
https://github.com/bellingcat/datasheet-server.git
synced 2026-06-12 05:18:31 +03:00
Wrote validation functions and getter to grab appropriate validation function
This commit is contained in:
@@ -28,6 +28,7 @@
|
|||||||
"express-handlebars": "^4.0.4",
|
"express-handlebars": "^4.0.4",
|
||||||
"googleapis": "^32.0.0",
|
"googleapis": "^32.0.0",
|
||||||
"graphql": "^0.13.2",
|
"graphql": "^0.13.2",
|
||||||
|
"moment": "^2.27.0",
|
||||||
"morgan": "^1.8.0",
|
"morgan": "^1.8.0",
|
||||||
"mz": "^2.7.0",
|
"mz": "^2.7.0",
|
||||||
"node-fetch": "^2.3.0",
|
"node-fetch": "^2.3.0",
|
||||||
|
|||||||
@@ -1,7 +1,13 @@
|
|||||||
import { timemap } from './lib'
|
import { timemap } from './lib'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
gsheets: [],
|
gsheets: [
|
||||||
|
{
|
||||||
|
name: 'us2020',
|
||||||
|
id: '1I_pgyTQJlIorTIEHBxw1mM1STn-SrIi66FKYxut61iM',
|
||||||
|
tabs: timemap.default
|
||||||
|
}
|
||||||
|
],
|
||||||
xlsx: [
|
xlsx: [
|
||||||
{
|
{
|
||||||
name: 'timemap_data',
|
name: 'timemap_data',
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import R from 'ramda'
|
import R from 'ramda';
|
||||||
|
|
||||||
/* eslint-disable */
|
/* eslint-disable */
|
||||||
String.prototype.replaceAll = function (search, replacement) {
|
String.prototype.replaceAll = function (search, replacement) {
|
||||||
|
|||||||
35
src/lib/validation.js
Normal file
35
src/lib/validation.js
Normal file
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user