From 0141a5a64c7cdd738b58d581e7fda2be110e149f Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Tue, 22 Jun 2021 14:43:57 +0100 Subject: [PATCH] Fix for #1794 - updating csv validators and parsers for date and numbers to allow attribute to not be present. --- packages/server/src/utilities/csvParser.js | 30 +++++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/packages/server/src/utilities/csvParser.js b/packages/server/src/utilities/csvParser.js index 0d8b12cc0a..93a7d400fa 100644 --- a/packages/server/src/utilities/csvParser.js +++ b/packages/server/src/utilities/csvParser.js @@ -4,13 +4,35 @@ const { FieldTypes } = require("../constants") const VALIDATORS = { [FieldTypes.STRING]: () => true, [FieldTypes.OPTIONS]: () => true, - [FieldTypes.NUMBER]: attribute => !isNaN(Number(attribute)), - [FieldTypes.DATETIME]: attribute => !isNaN(new Date(attribute).getTime()), + [FieldTypes.NUMBER]: attribute => { + // allow not to be present + if (!attribute) { + return true + } + return !isNaN(Number(attribute)) + }, + [FieldTypes.DATETIME]: attribute => { + // allow not to be present + if (!attribute) { + return true + } + return !isNaN(new Date(attribute).getTime()) + }, } const PARSERS = { - [FieldTypes.NUMBER]: attribute => Number(attribute), - [FieldTypes.DATETIME]: attribute => new Date(attribute).toISOString(), + [FieldTypes.NUMBER]: attribute => { + if (!attribute) { + return attribute + } + return Number(attribute) + }, + [FieldTypes.DATETIME]: attribute => { + if (!attribute) { + return attribute + } + return new Date(attribute).toISOString() + }, } function parse(csvString, parsers) {