From 784bb6f6f30d1f9086927edd84bccbe994aa9b35 Mon Sep 17 00:00:00 2001 From: philc Date: Thu, 26 Sep 2024 13:51:54 +0200 Subject: [PATCH] fix issue with integer at 0 --- models/Checkjson.js | 7 ++++--- models/Odmdb.js | 8 +++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/models/Checkjson.js b/models/Checkjson.js index 31973a8..61737c9 100755 --- a/models/Checkjson.js +++ b/models/Checkjson.js @@ -17,9 +17,9 @@ Checkjson.schema.properties.type.object = (val) => Checkjson.schema.properties.type.number = (n) => typeof n === "number"; Checkjson.schema.properties.type.boolean = (n) => typeof n === "boolean"; Checkjson.schema.properties.type.integer = (n) => - n != "" && !isNaN(n) && Math.round(n) == n; + n !== "" && !isNaN(n) && Math.round(n) === n; Checkjson.schema.properties.type.float = (n) => - n != "" && !isNaN(n) && Math.round(n) != n; //not yet in json schema + n !== "" && !isNaN(n) && Math.round(n) !== n; //not yet in json schema Checkjson.schema.properties.minLength = (str, min) => typeof str === "string" && str.length >= parseInt(min); Checkjson.schema.properties.maxLength = (str, max) => @@ -206,6 +206,7 @@ Checkjson.schema.data = (schema, data, withschemacheck) => { // subdata={prop1,prop2} // Return [] => no error, else 1 item per error {msg,ref:checkjson,data} const propertielist = Object.keys(properties); + Object.keys(subdata).forEach((kdata) => { if (!propertielist.includes(kdata)) { delete subdata[kdata]; @@ -214,7 +215,7 @@ Checkjson.schema.data = (schema, data, withschemacheck) => { let multimsg = []; propertielist.forEach((p) => { //type is mandatory in a propertie - if (subdata[p]) { + if (subdata.hasOwnProperty(p)) { if (properties[p].properties) { //means it is a subobject multimsg = multimsg.concat( diff --git a/models/Odmdb.js b/models/Odmdb.js index 1a537ec..ed65809 100644 --- a/models/Odmdb.js +++ b/models/Odmdb.js @@ -553,7 +553,6 @@ Odmdb.accessright = (apxaccessrights, role) => { Odmdb.cud = (objectPathname, crud, itm, role, runindex = true) => { const getschema = Odmdb.Schema(objectPathname, true); - if (getschema.status != 200) return getschema; if (!itm[getschema.data.schema.apxid]) { @@ -672,9 +671,11 @@ Odmdb.cud = (objectPathname, crud, itm, role, runindex = true) => { itmtostore.dt_update = dayjs().toISOString(); } Object.keys(itmtostore).forEach((k) => { - // remove undefined itmtostore because empty => - if (!itmtostore[k]) delete itmtostore[k]; + // remove empty itmtostore in case they are => + console.log(k, itmtostore[k], itmtostore[k] === ""); + if (itmtostore[k] === "") delete itmtostore[k]; }); + Object.keys(itmtostore).forEach((k) => { //Manage base64 case image to convert ans store in webp if (k.includes("imgbase64_") && itmtostore[k] != "") { @@ -711,6 +712,7 @@ Odmdb.cud = (objectPathname, crud, itm, role, runindex = true) => { }); if (crud == "C") itmtostore.dt_create = dayjs().toISOString(); // check consistency of datatostore + console.log("itmstostore::::::", itmtostore); const chkdata = Checkjson.schema.data( getschema.data.schema, itmtostore,