From 053b45c81cc92d941b48868dee91507199ad6a2d Mon Sep 17 00:00:00 2001 From: philc Date: Wed, 2 Oct 2024 17:29:20 +0200 Subject: [PATCH] fix bug case 0 jobstepposition in post --- models/Odmdb.js | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/models/Odmdb.js b/models/Odmdb.js index ad072fb..5f3a716 100644 --- a/models/Odmdb.js +++ b/models/Odmdb.js @@ -524,19 +524,20 @@ Odmdb.accessright = (apxaccessrights, role, properties) => { //if (log) console.log(currentmod,"properties",properties) const accessright = {}; console.log(); - role.xprofils.forEach(p => { + role.xprofils.forEach((p) => { if (apxaccessrights[p]) { - Object.keys(apxaccessrights[p]).forEach(act => { - if (apxaccessrights[p][act].length===0) apxaccessrights[p][act]=properties; + Object.keys(apxaccessrights[p]).forEach((act) => { + if (apxaccessrights[p][act].length === 0) + apxaccessrights[p][act] = properties; if (!accessright[act]) { accessright[act] = apxaccessrights[p][act]; } else { - accessright[act] = [ - ...new Set([...accessright[act], ...apxaccessrights[p][act]]), - ]; + accessright[act] = [ + ...new Set([...accessright[act], ...apxaccessrights[p][act]]), + ]; } - }) - } + }); + } }); return accessright; }; @@ -622,9 +623,10 @@ Odmdb.cud = (objectPathname, crud, itm, role, runindex = true) => { role, Object.keys(getschema.data.schema.properties) ); - Object.keys(accessright).forEach(act=>{ - if (accessright[act].length===0) accessright[act]=Object.keys(getschema.data.schema.properties) - }) + Object.keys(accessright).forEach((act) => { + if (accessright[act].length === 0) + accessright[act] = Object.keys(getschema.data.schema.properties); + }); if (log) console.log(currentmod, "Accessright to: ", accessright); if ( (crud == "C" && !accessright.C) || @@ -652,7 +654,7 @@ Odmdb.cud = (objectPathname, crud, itm, role, runindex = true) => { ); } else { // if Create Update erase old version - let itmtostore={}; + let itmtostore = {}; if (crud == "U" && accessright.U.length > 0) { itmtostore = itmold; const keynotallow = Object.keys(itm).filter( @@ -666,23 +668,33 @@ Odmdb.cud = (objectPathname, crud, itm, role, runindex = true) => { //console.log(accessright) accessright.U.forEach(async (p) => { // check this propertie exist in the requested update itm - if (itm[p] && itm[p] !== "") itmtostore[p] = itm[p]; + const testvaliditmupdate = + itm[p] === 0 || + (itm[p] && + ((typeof itm[p] === "string" && itm[p].trim() !== "") || + typeof itm[p] !== "string")); + if (testvaliditmupdate) itmtostore[p] = itm[p]; }); itmtostore.dt_update = dayjs().toISOString(); } - if (crud == "C"){ + if (crud == "C") { const keynotallow = Object.keys(itm).filter( (el) => !accessright.C.includes(el) ); accessright.C.forEach(async (p) => { // check this propertie exist in the requested update itm - if (itm[p] && itm[p] !== "") itmtostore[p] = itm[p]; + const testvaliditmcreate = + itm[p] === 0 || + (itm[p] && + ((typeof itm[p] === "string" && itm[p].trim() !== "") || + typeof itm[p] !== "string")); + if (testvaliditmcreate) itmtostore[p] = itm[p]; }); itmtostore.dt_create = dayjs().toISOString(); } Object.keys(itmtostore).forEach((k) => { // remove empty itmtostore in case they are => - console.log(k, itmtostore[k], itmtostore[k] === ""); + //console.log(k, itmtostore[k], itmtostore[k] === ""); if (itmtostore[k] === "") delete itmtostore[k]; });