From 9236771b2906759892c9a195bd5adc2542279be9 Mon Sep 17 00:00:00 2001 From: Sulka Haro Date: Tue, 5 May 2020 22:18:42 +0300 Subject: [PATCH] Sanitize data from manual careportal entries so only fields with actual data are sent to the server (#5619) --- lib/client/careportal.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/client/careportal.js b/lib/client/careportal.js index a5c86232d8e..632ab24986f 100644 --- a/lib/client/careportal.js +++ b/lib/client/careportal.js @@ -226,11 +226,17 @@ function init (client, $) { , duration: times.msecs(parse_duration($('#duration').val())).mins < 1 ? $('#duration').val() : times.msecs(parse_duration($('#duration').val())).mins , percent: $('#percent').val() , profile: $('#profile').val() - , preBolus: parseInt($('#preBolus').val()) + , preBolus: $('#preBolus').val() , notes: $('#notes').val() , units: client.settings.units }; + data.preBolus = parseInt(data.preBolus); + + if (isNaN(data.preBolus)) { + delete data.preBolus; + } + var reasons = inputMatrix[eventType]['reasons']; var reason = _.find(reasons, function matches (r) { return r.name === selectedReason; @@ -273,7 +279,11 @@ function init (client, $) { data.splitExt = parseInt($('#insulinSplitExt').val()) || 0; } - return data; + let d = {}; + Object.keys(data).forEach(function(key) { + if (data[key] != "" && data[key] != null) d[key] = data[key]; + }); + return d; } careportal.save = function save (event) {