modif Odmdb for search and wwws to improve localdb
This commit is contained in:
		| @@ -395,31 +395,39 @@ Odmdb.search = (objectPathname, objsearch, role) => { | |||||||
|   const getschema = Odmdb.Schema(objectPathname, true); |   const getschema = Odmdb.Schema(objectPathname, true); | ||||||
|   if (getschema.status != 200) return getschema; |   if (getschema.status != 200) return getschema; | ||||||
|   //console.log(getschema.data); |   //console.log(getschema.data); | ||||||
|   const apxid = getschema.data.apxid; |   const apxid = getschema.data.schema.apxid; | ||||||
|   let subsearch = objsearch.apxid |   let subsearch = objsearch.apxid | ||||||
|     ? objsearch.apxid |     ? objsearch.apxid | ||||||
|     : fs.readJSONSync(`${objectPathname}/idx/lst_${apxid}.json`); |     : fs.readJSONSync(`${objectPathname}/idx/lst_${apxid}.json`); | ||||||
|   // ADD HERE OTHER FILTRATION SEARCH depending of question |   // ADD HERE OTHER FILTRATION SEARCH depending of question | ||||||
|   if (objsearch.question) { |   if (objsearch.condition) { | ||||||
|     // remove or add in subsearch |     // remove or add in subsearch | ||||||
|   } |   } | ||||||
|   if (objsearch.fields) { |   if (objsearch.fields) { | ||||||
|     const resultat = {}; |     const resultat = {}; | ||||||
|  |     //console.log(getschema.data.schema.apxaccessrights); | ||||||
|  |     //console.log(role); | ||||||
|     const accessright = Odmdb.accessright( |     const accessright = Odmdb.accessright( | ||||||
|       getschema.data.schema.apxaccessrights, |       getschema.data.schema.apxaccessrights, | ||||||
|       role |       role | ||||||
|     ); |     ); | ||||||
|     //console.log(accessright); |     //console.log(accessright); | ||||||
|     const ifields={} |     if (objsearch.fields == "all") { | ||||||
|  |       //console.log(getschema.data) | ||||||
|  |       objsearch.fields = Object.keys(getschema.data.schema.properties); | ||||||
|  |     } | ||||||
|  |     const ifields = {}; | ||||||
|     subsearch.forEach((i) => { |     subsearch.forEach((i) => { | ||||||
|       const ifields = {}; |       const ifields = {}; | ||||||
|       if (fs.existsSync(`${objectPathname}/itm/${i}.json`)) { |       if (fs.existsSync(`${objectPathname}/itm/${i}.json`)) { | ||||||
|         const itm = fs.readJSONSync(`${objectPathname}/itm/${i}.json`); |         const itm = fs.readJSONSync(`${objectPathname}/itm/${i}.json`); | ||||||
|         if (itm.owner && itm.owner == role.xalias) { |         if (itm.owner && itm.owner == role.xalias) { | ||||||
|           role.xprofils.push("owner"); |           role.xprofils.push("owner"); | ||||||
|  |         } else { | ||||||
|  |           role.xprofils = role.xprofils.filter((e) => e !== "owner"); | ||||||
|         } |         } | ||||||
|         objsearch.fields.forEach((f) => { |         objsearch.fields.forEach((f) => { | ||||||
|           if (accessright.R.includes(f)) { |           if (accessright.R.length==0 || accessright.R.includes(f)) { | ||||||
|             ifields[f] = itm[f]; |             ifields[f] = itm[f]; | ||||||
|           } else { |           } else { | ||||||
|             ifields[f] = "unauthorized"; |             ifields[f] = "unauthorized"; | ||||||
| @@ -564,10 +572,13 @@ Odmdb.accessright = (apxaccessrights, role) => { | |||||||
|         if (!accessright[act]) { |         if (!accessright[act]) { | ||||||
|           accessright[act] = apxaccessrights[p][act]; |           accessright[act] = apxaccessrights[p][act]; | ||||||
|         } else { |         } else { | ||||||
|  |           if (accessright[act].length != 0) { | ||||||
|  |             //case where [] that mean all accessright on any properties | ||||||
|             accessright[act] = [ |             accessright[act] = [ | ||||||
|               ...new Set([...accessright[act], ...apxaccessrights[p][act]]), |               ...new Set([...accessright[act], ...apxaccessrights[p][act]]), | ||||||
|             ]; |             ]; | ||||||
|           } |           } | ||||||
|  |         } | ||||||
|         //if (log) console.log(currentmod,act,accessright[act]) |         //if (log) console.log(currentmod,act,accessright[act]) | ||||||
|       }); |       }); | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -145,9 +145,18 @@ Wwws.initlocaldata = (tribe, appname, pagename, version, profils, lg) => { | |||||||
|         localstorage.schema[name] = schema.data.schema; |         localstorage.schema[name] = schema.data.schema; | ||||||
|       } else { |       } else { | ||||||
|         console.log(schema); |         console.log(schema); | ||||||
|  |         let msg=`Check your ${fileparam} for schema in ${pagename} :` | ||||||
|  |         if (schema.status==406){ | ||||||
|  |           if (schema.msg) msg+=schema.msg | ||||||
|  |           if (schema.multimsg) { | ||||||
|  |             schema.multimsg.forEach(err=>{ | ||||||
|  |               msg+=`${err.msg} ${JSON.stringify(err.data)})` | ||||||
|  |             }) | ||||||
|  |           } | ||||||
|  |         } | ||||||
|         localstorage.schema[ |         localstorage.schema[ | ||||||
|           name |           name | ||||||
|         ] = `Check your ${fileparam} for schema in ${pagename} profil`; |         ] = msg; | ||||||
|       } |       } | ||||||
|     }); |     }); | ||||||
|   } |   } | ||||||
|   | |||||||
| @@ -84,18 +84,14 @@ router.get( | |||||||
|   (req, res) => { |   (req, res) => { | ||||||
|     const objectPathname = `../../${req.params.tribe}/objects/options/${req.params.optionname}_${req.header.xlang}.json`; |     const objectPathname = `../../${req.params.tribe}/objects/options/${req.params.optionname}_${req.header.xlang}.json`; | ||||||
|     if (fs.existsSync(objectPathname)) { |     if (fs.existsSync(objectPathname)) { | ||||||
|       res |       res.status(200).json({ | ||||||
|         .status(200) |  | ||||||
|         .json({ |  | ||||||
|         status: 200, |         status: 200, | ||||||
|         ref: "Odmdb", |         ref: "Odmdb", | ||||||
|         msg: "optionfind", |         msg: "optionfind", | ||||||
|         data: fs.readJsonSync(objectPathname), |         data: fs.readJsonSync(objectPathname), | ||||||
|       }); |       }); | ||||||
|     } else { |     } else { | ||||||
|       res |       res.status(404).json({ | ||||||
|         .status(404) |  | ||||||
|         .json({ |  | ||||||
|         status: 404, |         status: 404, | ||||||
|         ref: "Odmdb", |         ref: "Odmdb", | ||||||
|         msg: "optionnotfound", |         msg: "optionnotfound", | ||||||
| @@ -356,18 +352,18 @@ router.put( | |||||||
|  * @apiParam {string} tribe name (smatchit), where object is store |  * @apiParam {string} tribe name (smatchit), where object is store | ||||||
|  * @apiParam {string} objectname object name where looking for |  * @apiParam {string} objectname object name where looking for | ||||||
|  * @apiBody {array} [apxid] list of apxid prefilter when for perfomance you want filter the search investigation. If omit then it is looking for in any item object |  * @apiBody {array} [apxid] list of apxid prefilter when for perfomance you want filter the search investigation. If omit then it is looking for in any item object | ||||||
|  * @apiBody {array} [fields]  list of properties of object you want to get (profils user must have accessright in Read for those fields, a value 'unauthorized' can be return in this case) |  * @apiBody {array} [fields]  string "all" or list of properties of object you want to get (profils user must have accessright in Read for those fields, a value 'unauthorized' can be return in this case) | ||||||
|  * @apiBody {string} [question] a specific syntaxe to find quickly items by using index litteral text @TODO : create a query syntaxe for a question... |  * @apiBody {string} [condition] an array of condition {propertieA:[value1,value2],propertieB:[valu9],function:["name1",name2],...} select objectname id that match proprieteA = valu1 or value2 AND proprieteB=valu9 AND function name1(object) return true AND function name2(object) function are string code into schema  @TODO ... | ||||||
|  * |  * | ||||||
|  * @apiSuccess {json} contain {status,ref,msg,data} |  * @apiSuccess {json} contain {status,ref,msg,data} | ||||||
|  * @apiSuccessExample {json} Success-Response: |  * @apiSuccessExample {json} Return objects per id | ||||||
|  * HTTP/1.1 200 OK from {apxid:[itmid],fields:[field1,field2]} |  * HTTP/1.1 200 OK from body {apxid:[itmid],fields:[field1,field2]} | ||||||
|  * {"status":200, "ref":"Odmdb", "msg":"searchresult", "data":{"itms":{itmid:{field1,field2}]}} |  * {"status":200, "ref":"Odmdb", "msg":"searchresult", "data":{"itms":{itmid:{field1,field2}]}} | ||||||
|  * @apiSuccessExample {json} Success-Response: |  * @apiSuccessExample {json} Return arrays of ids | ||||||
|  * HTTP/1.1 200 OK from {question:} |  * HTTP/1.1 200 OK from {question:[{"color":['blue','red']},{size:["<100"]},{function:name}]} | ||||||
|  * {"status":200, "ref":"Odmdb",  "msg":"searchresult", "data":[itm1,itm2]} |  * {"status":200, "ref":"Odmdb",  "msg":"searchresult", "data":[itm1,itm2]} | ||||||
|  * @apiError {json} objectdoesnotexist the obbject does not exist for the tribe |  * @apiError {json} objectdoesnotexist the obbject does not exist for the tribe | ||||||
|  * @apiError {json} unconsistentquestion the question format is not relevant |  * @apiError {json} unconsistentcondition condition format is not relevant | ||||||
|  * @apiErrorExample {json} |  * @apiErrorExample {json} | ||||||
|  * HTTP/1.1 404 Not Found |  * HTTP/1.1 404 Not Found | ||||||
|  * {"status":404,"ref":"Odmdb","msg":"templatestring Odmdb_xx.json","data":"object to render with msg"} |  * {"status":404,"ref":"Odmdb","msg":"templatestring Odmdb_xx.json","data":"object to render with msg"} | ||||||
| @@ -415,9 +411,15 @@ router.get( | |||||||
|     const objectpath = `../../${req.params.tribe}/objects/${req.params.objectname}/itm/${req.params.primaryindex}.json`; |     const objectpath = `../../${req.params.tribe}/objects/${req.params.objectname}/itm/${req.params.primaryindex}.json`; | ||||||
|  |  | ||||||
|     if (fs.existsSync(objectpath)) { |     if (fs.existsSync(objectpath)) { | ||||||
|       res |       const readobj = Odmdb.r( | ||||||
|         .status(200) |         `../../${req.params.tribe}/objects/${req.params.objectname}`, | ||||||
|         .json({ |         req.params.primaryindex, | ||||||
|  |         { | ||||||
|  |           xprofils: req.session.header.xprofils, | ||||||
|  |           xalias: req.session.header.xalias, | ||||||
|  |         } | ||||||
|  |       ); | ||||||
|  |       res.status(200).json({ | ||||||
|         status: 200, |         status: 200, | ||||||
|         ref: "Odmdb", |         ref: "Odmdb", | ||||||
|         msg: "itmfound", |         msg: "itmfound", | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user