From a6a132de7ea234b355ff92e1e0ef4a2556f80b7b Mon Sep 17 00:00:00 2001 From: Fabian Date: Sat, 19 Feb 2022 13:31:28 +0100 Subject: [PATCH 1/3] Throw Error on wrong Properties --- modules/get-collmex-data.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/get-collmex-data.js b/modules/get-collmex-data.js index 0d2cb0e..e3dee2d 100644 --- a/modules/get-collmex-data.js +++ b/modules/get-collmex-data.js @@ -11,6 +11,9 @@ function getRequestBody (opts) { return opts.reduce((req, opt) => { const satz = satzarten[opt.Satzart] for (const prop in opt) { + if (!satz.hasOwnProperty(prop)) { + throw (`Property ${prop} not in ${satz.Satzart}`); + } satz[prop] = opt[prop] } for (const prop of ['Firma_Nr', 'Systemname']) { From f1f75f0a39b64c981c56e8633151e15696314d8f Mon Sep 17 00:00:00 2001 From: Fabian Date: Sat, 19 Feb 2022 16:34:37 +0100 Subject: [PATCH 2/3] correct number format to comma decimals --- modules/get-collmex-data.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/get-collmex-data.js b/modules/get-collmex-data.js index e3dee2d..245976d 100644 --- a/modules/get-collmex-data.js +++ b/modules/get-collmex-data.js @@ -15,6 +15,9 @@ function getRequestBody (opts) { throw (`Property ${prop} not in ${satz.Satzart}`); } satz[prop] = opt[prop] + if (typeof satz[prop] === 'number') { + satz[prop] = satz[prop].toString().replace(".", ","); + } } for (const prop of ['Firma_Nr', 'Systemname']) { if (Object.prototype.hasOwnProperty.call(satz, prop)) { From f2b940991245524f2cb27ec13f91c611286d676e Mon Sep 17 00:00:00 2001 From: Fabian Date: Sun, 20 Feb 2022 13:03:31 +0100 Subject: [PATCH 3/3] copy "satz" to "tempsatz" to prevent overwriting copy "satz" to "tempsatz" to prevent overwriting the values in "satz". Otherwise if you have two lines with not every property set in the second line, you will receive the values from the first line because the original template got overwritten. --- modules/get-collmex-data.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/modules/get-collmex-data.js b/modules/get-collmex-data.js index 245976d..c3097de 100644 --- a/modules/get-collmex-data.js +++ b/modules/get-collmex-data.js @@ -10,21 +10,24 @@ function getRequestBody (opts) { const satzarten = require('./load-satzarten.js')() return opts.reduce((req, opt) => { const satz = satzarten[opt.Satzart] + let tempsatz = { + ...satz + }; for (const prop in opt) { - if (!satz.hasOwnProperty(prop)) { - throw (`Property ${prop} not in ${satz.Satzart}`); + if (!tempsatz.hasOwnProperty(prop)) { + throw (`Property ${prop} not in ${tempsatz.Satzart}`); } - satz[prop] = opt[prop] - if (typeof satz[prop] === 'number') { - satz[prop] = satz[prop].toString().replace(".", ","); + tempsatz[prop] = opt[prop] + if (typeof tempsatz[prop] === 'number') { + tempsatz[prop] = tempsatz[prop].toString().replace(".", ","); } } for (const prop of ['Firma_Nr', 'Systemname']) { - if (Object.prototype.hasOwnProperty.call(satz, prop)) { - satz[prop] = opt[prop] || this[prop] + if (Object.prototype.hasOwnProperty.call(tempsatz, prop)) { + tempsatz[prop] = opt[prop] || this[prop] } } - return req + `${Object.values(satz).join(';')}\n` + return req + `${Object.values(tempsatz).join(';')}\n` }, '') }