From 7aa8d7870d6abbaf682f79bf386484923ba1c9f8 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Wed, 4 Nov 2020 13:17:24 +0000 Subject: [PATCH] Fix crash when saving rows --- packages/client/src/api/index.js | 37 +++++++++++++++++--------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/packages/client/src/api/index.js b/packages/client/src/api/index.js index 249c8731fa..aa1bd6a417 100644 --- a/packages/client/src/api/index.js +++ b/packages/client/src/api/index.js @@ -80,27 +80,30 @@ const makeRowRequestBody = (parameters, state) => { if (body._table) delete body._table // then override with supplied parameters - for (let fieldName of Object.keys(parameters.fields)) { - const field = parameters.fields[fieldName] + if (parameters.fields) { + for (let fieldName of Object.keys(parameters.fields)) { + const field = parameters.fields[fieldName] - // ensure fields sent are of the correct type - if (field.type === "boolean") { - if (field.value === "true") body[fieldName] = true - if (field.value === "false") body[fieldName] = false - } else if (field.type === "number") { - const val = parseFloat(field.value) - if (!isNaN(val)) { - body[fieldName] = val + // ensure fields sent are of the correct type + if (field.type === "boolean") { + if (field.value === "true") body[fieldName] = true + if (field.value === "false") body[fieldName] = false + } else if (field.type === "number") { + const val = parseFloat(field.value) + if (!isNaN(val)) { + body[fieldName] = val + } + } else if (field.type === "datetime") { + const date = new Date(field.value) + if (!isNaN(date.getTime())) { + body[fieldName] = date.toISOString() + } + } else { + body[fieldName] = field.value } - } else if (field.type === "datetime") { - const date = new Date(field.value) - if (!isNaN(date.getTime())) { - body[fieldName] = date.toISOString() - } - } else { - body[fieldName] = field.value } } + return body }