forked from apxtri/apxtri
fix issue with integer at 0
This commit is contained in:
parent
6d81688dde
commit
784bb6f6f3
@ -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(
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user