1
0
forked from apxtri/apxtri

modif Odmdb for search and wwws to improve localdb

This commit is contained in:
philc 2024-05-06 06:44:58 +02:00
parent ab562c7e9e
commit 009cbcbd2f
3 changed files with 62 additions and 40 deletions

View File

@ -395,31 +395,39 @@ Odmdb.search = (objectPathname, objsearch, role) => {
const getschema = Odmdb.Schema(objectPathname, true);
if (getschema.status != 200) return getschema;
//console.log(getschema.data);
const apxid = getschema.data.apxid;
const apxid = getschema.data.schema.apxid;
let subsearch = objsearch.apxid
? objsearch.apxid
: fs.readJSONSync(`${objectPathname}/idx/lst_${apxid}.json`);
// ADD HERE OTHER FILTRATION SEARCH depending of question
if (objsearch.question) {
if (objsearch.condition) {
// remove or add in subsearch
}
if (objsearch.fields) {
const resultat = {};
//console.log(getschema.data.schema.apxaccessrights);
//console.log(role);
const accessright = Odmdb.accessright(
getschema.data.schema.apxaccessrights,
role
);
//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) => {
const ifields = {};
if (fs.existsSync(`${objectPathname}/itm/${i}.json`)) {
const itm = fs.readJSONSync(`${objectPathname}/itm/${i}.json`);
if (itm.owner && itm.owner == role.xalias) {
role.xprofils.push("owner");
} else {
role.xprofils = role.xprofils.filter((e) => e !== "owner");
}
objsearch.fields.forEach((f) => {
if (accessright.R.includes(f)) {
if (accessright.R.length==0 || accessright.R.includes(f)) {
ifields[f] = itm[f];
} else {
ifields[f] = "unauthorized";
@ -564,10 +572,13 @@ Odmdb.accessright = (apxaccessrights, role) => {
if (!accessright[act]) {
accessright[act] = apxaccessrights[p][act];
} else {
if (accessright[act].length != 0) {
//case where [] that mean all accessright on any properties
accessright[act] = [
...new Set([...accessright[act], ...apxaccessrights[p][act]]),
];
}
}
//if (log) console.log(currentmod,act,accessright[act])
});
}

View File

@ -145,9 +145,18 @@ Wwws.initlocaldata = (tribe, appname, pagename, version, profils, lg) => {
localstorage.schema[name] = schema.data.schema;
} else {
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[
name
] = `Check your ${fileparam} for schema in ${pagename} profil`;
] = msg;
}
});
}

View File

@ -84,18 +84,14 @@ router.get(
(req, res) => {
const objectPathname = `../../${req.params.tribe}/objects/options/${req.params.optionname}_${req.header.xlang}.json`;
if (fs.existsSync(objectPathname)) {
res
.status(200)
.json({
res.status(200).json({
status: 200,
ref: "Odmdb",
msg: "optionfind",
data: fs.readJsonSync(objectPathname),
});
} else {
res
.status(404)
.json({
res.status(404).json({
status: 404,
ref: "Odmdb",
msg: "optionnotfound",
@ -356,18 +352,18 @@ router.put(
* @apiParam {string} tribe name (smatchit), where object is store
* @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} [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 {string} [question] a specific syntaxe to find quickly items by using index litteral text @TODO : create a query syntaxe for a question...
* @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} [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}
* @apiSuccessExample {json} Success-Response:
* HTTP/1.1 200 OK from {apxid:[itmid],fields:[field1,field2]}
* @apiSuccessExample {json} Return objects per id
* HTTP/1.1 200 OK from body {apxid:[itmid],fields:[field1,field2]}
* {"status":200, "ref":"Odmdb", "msg":"searchresult", "data":{"itms":{itmid:{field1,field2}]}}
* @apiSuccessExample {json} Success-Response:
* HTTP/1.1 200 OK from {question:}
* @apiSuccessExample {json} Return arrays of ids
* HTTP/1.1 200 OK from {question:[{"color":['blue','red']},{size:["<100"]},{function:name}]}
* {"status":200, "ref":"Odmdb", "msg":"searchresult", "data":[itm1,itm2]}
* @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}
* HTTP/1.1 404 Not Found
* {"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`;
if (fs.existsSync(objectpath)) {
res
.status(200)
.json({
const readobj = Odmdb.r(
`../../${req.params.tribe}/objects/${req.params.objectname}`,
req.params.primaryindex,
{
xprofils: req.session.header.xprofils,
xalias: req.session.header.xalias,
}
);
res.status(200).json({
status: 200,
ref: "Odmdb",
msg: "itmfound",