1
0
forked from apxtri/apxtri

odmdb ans wwws for pageadmin.html

This commit is contained in:
philc 2024-05-02 07:36:23 +02:00
parent 7c4b285995
commit fe64375566
5 changed files with 503 additions and 209 deletions

View File

@ -1,4 +1,4 @@
## apxtri  Decentralized Autonomous Organisation (DAO) for Libertarian ## apxtri  Decentralized Autonomous Organisation (DAO)
You are here on the tech side, to understand under the wood how it works and how you can contribute to this tech journey. You are here on the tech side, to understand under the wood how it works and how you can contribute to this tech journey.
See [apxtri web site](https://apxtri.crabdance.com) how to create a new social world with apxtri. See [apxtri web site](https://apxtri.crabdance.com) how to create a new social world with apxtri.

View File

@ -216,40 +216,39 @@ Odmdb.Schema = (objectPathname, validschema, lg = "en") => {
}; };
const convoptionstoenum = (propertie, lg) => { const convoptionstoenum = (propertie, lg) => {
if (!propertie.options) return propertie; if (!propertie.options) return propertie;
if (!(propertie.options["$ref"])){ if (!propertie.options["$ref"]) {
propertie.msg="missingref" propertie.msg = "missingref";
return propertie return propertie;
} }
let optionsfile; let optionsfile;
let optionstype; let optionstype;
if (propertie.options["$ref"].includes("/options/")) { if (propertie.options["$ref"].includes("/options/")) {
propertie.comment = `options:${propertie.options["$ref"]}}`;
optionstype = "options"; optionstype = "options";
optionsfile = path.resolve( optionsfile = path.resolve(
`../../${propertie.options["$ref"]}_${lg}.json` `../../${propertie.options["$ref"]}_${lg}.json`
); );
} }
if (propertie.options["$ref"].includes("/idx/")) { if (propertie.options["$ref"].includes("/idx/")) {
optionstype = "idx"; (propertie.comment = `itms:${propertie.options["$ref"]}}`),
optionsfile = path.resolve( (optionstype = "idx");
`../../${propertie.options["$ref"]}.json` optionsfile = path.resolve(`../../${propertie.options["$ref"]}.json`);
);
} }
if (log) console.log(currentmod, "Lien vers options:", optionsfile); if (log) console.log(currentmod, "Lien vers options:", optionsfile);
if (!fs.existsSync(optionsfile)) { if (!fs.existsSync(optionsfile)) {
propertie.msg = "missingref"; propertie.msg = "missingref";
return propertie; return propertie;
} else { } else {
delete propertie.options delete propertie.options;
if (optionstype == "options") { if (optionstype == "options") {
propertie.enum = propertie.enum = fs.readJSONSync(optionsfile).lst_idx;
fs.readJSONSync(optionsfile).lst_idx;
} }
if (optionstype == "idx") { if (optionstype == "idx") {
propertie.enum = fs.readJSONSync(optionsfile); propertie.enum = fs.readJSONSync(optionsfile);
} }
} }
return propertie return propertie;
} };
if (log) console.log(currentmod, `${objectPathname}/conf.json`); if (log) console.log(currentmod, `${objectPathname}/conf.json`);
const res = { const res = {
@ -275,22 +274,28 @@ Odmdb.Schema = (objectPathname, validschema, lg = "en") => {
} }
// get $ref from $def // get $ref from $def
if (res.data.schema["$defs"]) { if (res.data.schema["$defs"]) {
Object.keys(res.data.schema["$defs"]).forEach(ss=>{ Object.keys(res.data.schema["$defs"]).forEach((ss) => {
Object.keys(res.data.schema["$defs"][ss].properties).forEach(pp=>{ Object.keys(res.data.schema["$defs"][ss].properties).forEach((pp) => {
res.data.schema["$defs"][ss].properties[pp]=convoptionstoenum(res.data.schema["$defs"][ss].properties[pp],lg) res.data.schema["$defs"][ss].properties[pp] = convoptionstoenum(
}) res.data.schema["$defs"][ss].properties[pp],
}) lg
);
});
});
} }
Object.keys(res.data.schema.properties).forEach((p) => { Object.keys(res.data.schema.properties).forEach((p) => {
if ( if (
res.data.schema.properties[p].type == "object" && res.data.schema.properties[p].type == "object" &&
res.data.schema.properties[p]["$ref"] res.data.schema.properties[p]["$ref"]
) { ) {
let subschema let subschema;
const localdef=res.data.schema.properties[p]["$ref"].includes("#/") const localdef = res.data.schema.properties[p]["$ref"].includes("#/");
if ( if (
localdef && localdef &&
!(res.data.schema["$defs"] && res.data.schema["$defs"][propertie["$ref"]]) !(
res.data.schema["$defs"] &&
res.data.schema["$defs"][propertie["$ref"]]
)
) { ) {
res.status = 404; res.status = 404;
res.msg = "missinglocalref"; res.msg = "missinglocalref";
@ -298,20 +303,28 @@ Odmdb.Schema = (objectPathname, validschema, lg = "en") => {
return res; return res;
} }
if (localdef) { if (localdef) {
res.data.schema.properties[p]=res.data.schema["$defs"][res.data.schema.properties[p]["$ref"]] res.data.schema.properties[p] =
res.data.schema["$defs"][res.data.schema.properties[p]["$ref"]];
} else { } else {
subschema = Odmdb.Schema(path.resolve(res.data.schema.properties[p]["$ref"]), validschema, lg) subschema = Odmdb.Schema(
path.resolve(res.data.schema.properties[p]["$ref"]),
validschema,
lg
);
if (subschema.status == 200) { if (subschema.status == 200) {
res.data.schema.properties[p] = subschema.data.schema; res.data.schema.properties[p] = subschema.data.schema;
} else { } else {
subschema.data.originschemaproperty=p subschema.data.originschemaproperty = p;
return subschema return subschema;
} }
} }
} }
if (res.data.schema.properties[p].options) { if (res.data.schema.properties[p].options) {
//remplace options par enum:[] //remplace options par enum:[]
res.data.schema.properties[p]=convoptionstoenum(res.data.schema.properties[p],lg) res.data.schema.properties[p] = convoptionstoenum(
res.data.schema.properties[p],
lg
);
} }
}); });
@ -359,15 +372,19 @@ Odmdb.Schema = (objectPathname, validschema, lg = "en") => {
} }
return res; return res;
}; };
Odmdb.search = (objectPath, objectName, search) => { Odmdb.search = (objectPathname, objsearch, role) => {
/* /*
@search= { if (fields exist):
txt: string, return data:{id:{field:value}]}
algo: match | pattern | fuzzy else:
fieldstring:[list of field], return data:[id]
indexfilter:{index1:[val1,val2 | ] }
exemple:
objsearch= {
apxid:['toto','titi'],fields:['firstname']
} }
Return data:[uuids] return data:{toto:{firstname:"Paul"},titi:"fistname:"Jacques"}
ADD HERE OTHER OPTION USING IDX FOR PERFORMANCE
example: search exact match hill in townId example: search exact match hill in townId
heavy search={txt:"hill",algo:"match",fieldstring:"toxnId"} heavy search={txt:"hill",algo:"match",fieldstring:"toxnId"}
@ -375,8 +392,58 @@ Odmdb.search = (objectPath, objectName, search) => {
light search={txt:"hill", algo:"match", indexfilter:{"key":"nationId","value":"ants"}} light search={txt:"hill", algo:"match", indexfilter:{"key":"nationId","value":"ants"}}
*/ */
const schema = Odmdb.schema(objectPath, objectName); const getschema = Odmdb.Schema(objectPathname, true);
if (schema.status != 200) return schema; if (getschema.status != 200) return getschema;
//console.log(getschema.data);
const apxid = getschema.data.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) {
// remove or add in subsearch
}
if (objsearch.fields) {
const resultat = {};
const accessright = Odmdb.accessright(
getschema.data.schema.apxaccessrights,
role
);
//console.log(accessright);
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");
}
objsearch.fields.forEach((f) => {
if (accessright.R.includes(f)) {
ifields[f] = itm[f];
} else {
ifields[f] = "unauthorized";
}
});
} else {
ifields.notfound = true;
}
resultat[i] = ifields;
});
return {
status: 200,
ref: "Odmdb",
msg: "resultsearchlist",
data: resultat,
};
} else {
return {
status: 200,
ref: "Odmdb",
msg: "resultsearchlist",
data: [subsearch],
};
}
}; };
Odmdb.r = (objectPathname, apxid, role) => { Odmdb.r = (objectPathname, apxid, role) => {

View File

@ -7,82 +7,155 @@ const Odmdb = require("./Odmdb.js");
const conf = require(`../../../conf.json`); const conf = require(`../../../conf.json`);
const Wwws = {}; const Wwws = {};
Wwws.initlocaldata = (tribe, appname, profils,lg) => { Wwws.initlocaldata = (tribe, appname, pagename, version, profils, lg) => {
const fileparam = `../../${tribe}/objects/wwws/itm/${appname}.json`; const fileparam = `../../${tribe}/objects/wwws/itm/${appname}.json`;
console.log(fileparam);
if (!fs.existsSync(fileparam)) { if (!fs.existsSync(fileparam)) {
return res return { status: 404, ref: "Wwws", msg: "appdoesnotexist", data: {} };
.status(404)
.json({ status: 404, ref: "Wwws", msg: "appdoesnotexist", data: {} });
} }
const locals = fs.readJSONSync(fileparam); const locals = fs.readJSONSync(fileparam);
if (!locals.pages[pagename]) {
return {
status: 200,
ref: "Wwws",
msg: "pagedoesnotexist",
data: { pagename },
};
}
if (locals.pages[pagename].version == version) {
return { status: 200, ref: "Wwws", msg: "nonewdatamodel", data: {} };
}
let authorize = false;
profils.forEach((p) => {
authorize = authorize || locals.pages[pagename].profils.includes(p);
});
if (!authorize) {
return {
status: 200,
ref: "Wwws",
msg: "forbidenaccess",
data: { pagename, profils },
};
}
//check version
const initname = `../../tmp/initlocaldata/${tribe}_${appname}_${pagename}_${lg}_${locals.pages[pagename].version}.json`;
if (fs.existsSync(initname) && 1 != 1) {
const init = fs.readJsonSync(initname);
if (init.app.version == locals.app.version) {
return { status: 200, ref: "Wwws", msg: "datamodelupdate", data: init };
}
}
const localstorage = { const localstorage = {
headers: locals.headers, version: locals.pages[pagename].version,
headers: locals.apxtri.headers,
confpages:locals.pages[pagename].confpage,
req: {}, req: {},
itm:{}, itm:{},
itms: {}, itms: {},
options: {}, options: {},
tpl: {}, tpl: {},
tpldata:{},
ref: {}, ref: {},
schema: {}, schema: {},
}; };
localstorage.headers.xlang = lg; localstorage.headers.xlang = lg;
profils.forEach((p) => { // A faire plus tard charger tous les referentiele et les data pour une page adminpage
if (locals.profils[p]) { /* if (pagename=="pageadmin"){
if (locals.profils[p].req){ // load any referentialdata
localstorage.req[p] = locals.profils[p].req; glob.Sync(`../../${tribe}/objects/*.json`).forEach(f=>{
if (!localstorage.schema.includes(`${tribe}/objects/${path.basename(f,".json")}`)){
localstorage.schema.push(`${tribe}/objects/${path.basename(f,".json")}`)
} }
if (locals.profils[p].ref){ })
Object.keys(locals.profils[p].ref).forEach(r=>{
const src= `../../${locals.profils[p].ref[r]}_${lg}.json`; }
*/
const loc = locals.pages[pagename];
if (loc.itms){
Object.keys(loc.itms).forEach((r) => {
const src = `../../${loc.itms[r]}.json`;
if (fs.existsSync(src)) { if (fs.existsSync(src)) {
localstorage.ref[r]=fs.readJSONSync(src) localstorage.itms[r] = fs.readJSONSync(src);
} else { } else {
localstorage.ref[r]=`Check your ${fileparam} for ref in ${p} and ${r}` localstorage.itms[r] = `Check your ${fileparam} for itms in ${pagename} and ${r}`;
}
})
}
if (locals.profils[p].options){
Object.keys(locals.profils[p].options).forEach(r=>{
const src= `../../${locals.profils[p].options[r]}_${lg}.json`;
if (fs.existsSync(src)){
localstorage.options[r]=fs.readJSONSync(src)
}else{
localstorage.options[r]=`Check your ${fileparam} for options in ${p} profil and ${r}`
}
})
}
if (locals.profils[p].tpl){
Object.keys(locals.profils[p].tpl).forEach(r=>{
let src= `../../${locals.profils[p].tpl[r]}`;
if (!fs.existsSync(src)){
src+=`_${lg}.mustache`
}
if (fs.existsSync(src)){
localstorage.tpl[r]=fs.readJSONSync(src)
}else{
localstorage.tpl[r]=`Check your ${fileparam} for template in ${p} profil and ${r}`
}
})
}
if (locals.profils[p].schema){
locals.profils[p].schema.forEach(objpath=>{
const name=path.basename(objpath)
const schema=Odmdb.Schema(`../../${objpath}`,false,lg)
if (schema.status==200){
localstorage.schema[name]=schema.data.schema
}else{
console.log(schema)
localstorage.schema[name]=`Check your ${fileparam} for schema in ${p} profil`
}
})
}
} }
}); });
}
if (loc.ref) {
Object.keys(loc.ref).forEach((r) => {
const src = `../../${loc.ref[r]}_${lg}.json`;
if (fs.existsSync(src)) {
localstorage.ref[r] = fs.readJSONSync(src);
} else {
localstorage.ref[
r
] = `Check your ${fileparam} for ref in ${pagename} and ${r}`;
}
});
}
if (loc.options) {
Object.keys(loc.options).forEach((r) => {
const src = `../../${loc.options[r]}_${lg}.json`;
if (fs.existsSync(src)) {
localstorage.options[r] = fs.readJSONSync(src);
} else {
localstorage.options[
r
] = `Check your ${fileparam} for options in ${pagename} profil and ${r}`;
}
});
}
if (loc.tpl) {
Object.keys(loc.tpl).forEach((r) => {
let src = `../../${loc.tpl[r]}`;
console.log(path.resolve(src))
if (!fs.existsSync(src)) {
src += `_${lg}.mustache`;
}
if (fs.existsSync(src)) {
localstorage.tpl[r] = fs.readFileSync(src,'utf-8');
} else {
localstorage.tpl[
r
] = `Check your ${fileparam} for template in ${pagename} profil and ${r}`;
}
});
}
if (loc.tpldata) {
Object.keys(loc.tpldata).forEach((r) => {
let src = `../../${loc.tpldata[r]}`;
console.log(path.resolve(src))
if (!fs.existsSync(src)) {
src += `_${lg}.json`;
}
if (fs.existsSync(src)) {
localstorage.tpldata[r] = fs.readJSONSync(src);
} else {
localstorage.tpldata[
r
] = `Check your ${fileparam} for template in ${pagename} profil and ${r} in tpldata`;
}
});
}
if (loc.schema) {
loc.schema.forEach((objpath) => {
const name = path.basename(objpath);
const schema = Odmdb.Schema(`../../${objpath}`, false, lg);
if (schema.status == 200) {
localstorage.schema[name] = schema.data.schema;
} else {
console.log(schema);
localstorage.schema[
name
] = `Check your ${fileparam} for schema in ${pagename} profil`;
}
});
}
return { return {
status: 200, status: 200,
ref: "Wwws", ref: "Wwws",
msg: "initdbsuccess", msg: "datamodelupdate",
data: { localstorage }, data: localstorage
}; };
}; };

View File

@ -26,17 +26,17 @@ router.get("/schemas/:tribe", checkHeaders, isAuthenticated, (req, res) => {
apx: { conf: {}, objectnames: [] }, apx: { conf: {}, objectnames: [] },
tribe: { conf: {}, objectnames: [] }, tribe: { conf: {}, objectnames: [] },
}; };
let trb let trb;
glob.sync(`..{/,/../${req.params.tribe}/}schema/*.json`).forEach(f=>{ glob.sync(`..{/,/../${req.params.tribe}/}schema/*.json`).forEach((f) => {
const objectname = path.basename(f, ".json"); const objectname = path.basename(f, ".json");
console.log(f) console.log(f);
trb = (f.includes(req.params.tribe))? "tribe":"apx"; trb = f.includes(req.params.tribe) ? "tribe" : "apx";
if (objectname == "conf") { if (objectname == "conf") {
data[trb].conf = fs.readJSONSync(f); data[trb].conf = fs.readJSONSync(f);
} else { } else {
data[trb].objectnames.push(objectname); data[trb].objectnames.push(objectname);
} }
}) });
res.status(200).json({ status: 200, ref: "Odmdb", msg: "objectslist", data }); res.status(200).json({ status: 200, ref: "Odmdb", msg: "objectslist", data });
}); });
/** /**
@ -52,12 +52,17 @@ router.get("/schemas/:tribe", checkHeaders, isAuthenticated, (req, res) => {
* HTTP/1.1 200 OK * HTTP/1.1 200 OK
* {"status":200, "ref":"Odmdb", "msg":"schema", "data":{schema,objectname,lg} * {"status":200, "ref":"Odmdb", "msg":"schema", "data":{schema,objectname,lg}
*/ */
router.get("/schema/:tribe/:objectname", checkHeaders, isAuthenticated, (req, res) => { router.get(
const objectPathname=`../../${req.params.tribe}/objects/${req.params.objectname}` "/schema/:tribe/:objectname",
console.log(objectPathname) checkHeaders,
const retschema = Odmdb.Schema(objectPathname, true, req.header.xlang) isAuthenticated,
(req, res) => {
const objectPathname = `../../${req.params.tribe}/objects/${req.params.objectname}`;
console.log(objectPathname);
const retschema = Odmdb.Schema(objectPathname, true, req.header.xlang);
res.status(retschema.status).json(retschema); res.status(retschema.status).json(retschema);
}); }
);
/** /**
* @api {get} /adminapi/odmdb/options/:tribe/objects/option/:optionname - Get option list in header language * @api {get} /adminapi/odmdb/options/:tribe/objects/option/:optionname - Get option list in header language
@ -72,24 +77,43 @@ router.get("/schema/:tribe/:objectname", checkHeaders, isAuthenticated, (req, re
* HTTP/1.1 200 OK * HTTP/1.1 200 OK
* {"status":200, "ref":"Odmdb", "msg":"schema", "data":{schema,objectname,lg} * {"status":200, "ref":"Odmdb", "msg":"schema", "data":{schema,objectname,lg}
*/ */
router.get("/options/:tribe/objects/option/:optionname", checkHeaders, isAuthenticated, (req, res) => { router.get(
const objectPathname=`../../${req.params.tribe}/objects/options/${req.params.optionname}_${req.header.xlang}.json` "/options/:tribe/objects/option/:optionname",
checkHeaders,
isAuthenticated,
(req, res) => {
const objectPathname = `../../${req.params.tribe}/objects/options/${req.params.optionname}_${req.header.xlang}.json`;
if (fs.existsSync(objectPathname)) { if (fs.existsSync(objectPathname)) {
res.status(200).json({status:200,ref:"Odmdb",msg:"optionfind",data:fs.readJsonSync(objectPathname)}) res
}else{ .status(200)
res.status(404).json({status:404,ref:"Odmdb",msg:"optionnotfound",data:{objectPathname}}) .json({
} status: 200,
ref: "Odmdb",
msg: "optionfind",
data: fs.readJsonSync(objectPathname),
}); });
} else {
res
.status(404)
.json({
status: 404,
ref: "Odmdb",
msg: "optionnotfound",
data: { objectPathname },
});
}
}
);
/** /**
* @api {get} /adminapi/odmdb/idx/:tribe/:objectname/:indexname - index Get * @api {get} /api/adminapi/odmdb/idx/:tribe/:objectname/:indexname - index Get
* @apiGroup Odmdb * @apiGroup Odmdb
* @apiName getIndex * @apiName getIndexbyindexname
* @apiDescription Get index file for an object * @apiDescription Get index file for an object
* *
* @apiParam {string} tribe if common adminapi or tribename * @apiParams {string} tribe if common adminapi or tribename
* @apiParam {string} objectname If in conf.nationObjects then object is into nationchains/ else in tribes/xtribe/objectname/idx/indexname indexname * @apiParams {string} objectname If in conf.nationObjects then object is into nationchains/ else in tribes/xtribe/objectname/idx/indexname indexname
* @apiParam {String} indexname name of index file in /idx/indexnamme.json * @apiParams {String} indexname name of index file in /idx/indexnamme.json
* *
* *
* @apiError {json} objectNotfound the file does not exist * @apiError {json} objectNotfound the file does not exist
@ -101,8 +125,6 @@ router.get("/options/:tribe/objects/option/:optionname", checkHeaders, isAuthent
* @apiSuccessExample {json} Success-Response: * @apiSuccessExample {json} Success-Response:
* HTTP/1.1 200 OK * HTTP/1.1 200 OK
* {"status":200, "ref":"Odmdb", "msg":"indexexist", "data":{indexname,content:{index file}} * {"status":200, "ref":"Odmdb", "msg":"indexexist", "data":{indexname,content:{index file}}
*
*
*/ */
router.get( router.get(
"/idx/:tribe/:objectname/:indexname", "/idx/:tribe/:objectname/:indexname",
@ -111,6 +133,7 @@ router.get(
(req, res) => { (req, res) => {
console.log("passe"); console.log("passe");
const indexpath = `../../${req.params.tribe}/objects/${req.params.objectname}/idx/${req.params.indexname}`; const indexpath = `../../${req.params.tribe}/objects/${req.params.objectname}/idx/${req.params.indexname}`;
console.log(indexpath);
if (fs.existsSync(indexpath)) { if (fs.existsSync(indexpath)) {
res.status(200).json({ res.status(200).json({
ref: "Odmdb", ref: "Odmdb",
@ -157,7 +180,7 @@ router.get(
console.log("reindex"); console.log("reindex");
// check validity and accessright // check validity and accessright
const objectPathname=`../../${req.params.tribe}/objects/${req.params.objectname}` const objectPathname = `../../${req.params.tribe}/objects/${req.params.objectname}`;
if (!fs.existsSync(objectPathname)) { if (!fs.existsSync(objectPathname)) {
res.status(404).json({ res.status(404).json({
status: 404, status: 404,
@ -223,14 +246,21 @@ router.get(
* {"status":404,"ref":"Odmdb","msg":"see nationchains/model/lg/Odmdb_xx.json","data":"object to render with msg"} * {"status":404,"ref":"Odmdb","msg":"see nationchains/model/lg/Odmdb_xx.json","data":"object to render with msg"}
* *
*/ */
router.post("/itm/:tribe/:objectname", checkHeaders, isAuthenticated, (req, res) => { router.post(
"/itm/:tribe/:objectname",
checkHeaders,
isAuthenticated,
(req, res) => {
// Create an item of an object with no specificities // Create an item of an object with no specificities
// if specificities then create a route / model that import odmdb // if specificities then create a route / model that import odmdb
const objectPathname = `../../${req.params.tribe}/objects/${req.params.objectname}`; const objectPathname = `../../${req.params.tribe}/objects/${req.params.objectname}`;
const postitm=Odmdb.cud(objectPathname,"C",req.body,{xprofils:req.session.header.xprofils,xalias:req.session.header.xalias}); const postitm = Odmdb.cud(objectPathname, "C", req.body, {
res.status(postitm.status).json(postitm); xprofils: req.session.header.xprofils,
xalias: req.session.header.xalias,
}); });
res.status(postitm.status).json(postitm);
}
);
/** /**
* @api {put} /adminapi/odmdb/itm/:tribe/:objectname - item Update * @api {put} /adminapi/odmdb/itm/:tribe/:objectname - item Update
@ -259,13 +289,21 @@ router.post("/itm/:tribe/:objectname", checkHeaders, isAuthenticated, (req, res)
* {"status":404,"ref":"Odmdb","msg":"see nationchains/model/lg/Odmdb_xx.json","data":"object to render with msg"} * {"status":404,"ref":"Odmdb","msg":"see nationchains/model/lg/Odmdb_xx.json","data":"object to render with msg"}
* *
*/ */
router.put("/itm/:tribe/:objectname", checkHeaders, isAuthenticated, (req, res) => { router.put(
"/itm/:tribe/:objectname",
checkHeaders,
isAuthenticated,
(req, res) => {
// Create an item of an object with no specificities // Create an item of an object with no specificities
// if specificities then create a route / model that import odmdb // if specificities then create a route / model that import odmdb
const objectPathname = `../../${req.params.tribe}/objects/${req.params.objectname}`; const objectPathname = `../../${req.params.tribe}/objects/${req.params.objectname}`;
const postitm=Odmdb.cud(objectPathname,"U",req.body,{xprofils:req.session.header.xprofils,xalias:req.session.header.xalias}); const postitm = Odmdb.cud(objectPathname, "U", req.body, {
res.status(postitm.status).json(postitm); xprofils: req.session.header.xprofils,
xalias: req.session.header.xalias,
}); });
res.status(postitm.status).json(postitm);
}
);
/** /**
* @api {delete} /adminapi/odmdb/itm/:tribe/:objectname/:primaryid - item Delete * @api {delete} /adminapi/odmdb/itm/:tribe/:objectname/:primaryid - item Delete
@ -293,30 +331,41 @@ router.put("/itm/:tribe/:objectname", checkHeaders, isAuthenticated, (req, res)
* {"status":404,"ref":"Odmdb","msg":"see nationchains/model/lg/Odmdb_xx.json","data":"object to render with msg"} * {"status":404,"ref":"Odmdb","msg":"see nationchains/model/lg/Odmdb_xx.json","data":"object to render with msg"}
* *
*/ */
router.put("/itm/:tribe/:objectname", checkHeaders, isAuthenticated, (req, res) => { router.put(
"/itm/:tribe/:objectname",
checkHeaders,
isAuthenticated,
(req, res) => {
// Create an item of an object with no specificities // Create an item of an object with no specificities
// if specificities then create a route / model that import odmdb // if specificities then create a route / model that import odmdb
const objectPathname = `../../${req.params.tribe}/objects/${req.params.objectname}`; const objectPathname = `../../${req.params.tribe}/objects/${req.params.objectname}`;
const postitm=Odmdb.cud(objectPathname,"U",req.body,{xprofils:req.session.header.xprofils,xalias:req.session.header.xalias}); const postitm = Odmdb.cud(objectPathname, "U", req.body, {
res.status(postitm.status).json(postitm); xprofils: req.session.header.xprofils,
xalias: req.session.header.xalias,
}); });
res.status(postitm.status).json(postitm);
}
);
/** /**
* @api {post} /adminapi/odmdb/searchitms/:tribe/:objectname - items Search * @api {post} /adminapi/odmdb/searchitms/:tribe/:objectname - items Search
* @apiGroup Odmdb * @apiGroup Odmdb
* @apiName searchItm * @apiName searchItms
* @apiPermission none * @apiPermission none
* @apiDescription Search in an object collection of items * @apiDescription Search dynamicaly in an object collection of items, results can be a list of apxid or an object {apxid1:{propertie:value,..}}. To get object you must specify in body the key fields. See usage example. TODO: This will evolve with deeper search technics
* @apiParam {string} tribe adminapi or 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} fields list of properties at least apxid propertie * @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 {string} question a specific syntaxe to find quickly items by using index litteral text @TODO : create a query syntaxe... * @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...
* *
* @apiSuccess {json} contain a json file * @apiSuccess {json} contain {status,ref,msg,data}
* @apiSuccessExample {json} Success-Response: * @apiSuccessExample {json} Success-Response:
* HTTP/1.1 200 OK * HTTP/1.1 200 OK from {apxid:[itmid],fields:[field1,field2]}
* {"status":200, "ref":"Odmdb", "msg":"searchresult", "data":{"itms":[{itm fields}]}} * {"status":200, "ref":"Odmdb", "msg":"searchresult", "data":{"itms":{itmid:{field1,field2}]}}
* @apiSuccessExample {json} Success-Response:
* HTTP/1.1 200 OK from {question:}
* {"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} unconsistentquestion the question format is not relevant
* @apiErrorExample {json} * @apiErrorExample {json}
@ -325,12 +374,16 @@ router.put("/itm/:tribe/:objectname", checkHeaders, isAuthenticated, (req, res)
* *
*/ */
router.post( router.post(
"/searchitems/:objectname/:question", "/searchitms/:tribe/:objectname",
checkHeaders, checkHeaders,
isAuthenticated, isAuthenticated,
(req, res) => { (req, res) => {
// voir comment sortir isAuthenticated poure autoriser l'acces au search sur des object plublic const objectPathname = `../../${req.params.tribe}/objects/${req.params.objectname}`;
res.status(200).json({status:200,ref:"Odmdb",msg:"TODO",data:{}}) const ressearch = Odmdb.search(objectPathname, req.body, {
xprofils: req.session.header.xprofils,
xalias: req.session.header.xalias,
});
res.status(ressearch.status).json(ressearch);
} }
); );
@ -362,7 +415,14 @@ 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.status(200).json({status:200,ref:"Odmdb",msg:"itmfound", data:fs.readJsonSync(objectpath) }); res
.status(200)
.json({
status: 200,
ref: "Odmdb",
msg: "itmfound",
data: fs.readJsonSync(objectpath),
});
} else { } else {
res.status(404).json({ res.status(404).json({
status: 404, status: 404,

View File

@ -10,29 +10,123 @@ const isAuthenticated = require("../middlewares/isAuthenticated");
const router = express.Router(); const router = express.Router();
// GET api/wwws/conf/:tribeId/:website // GET api/wwws/conf/:tribeId/:website
// if profils accessright return the nginx conf in ${conf.dirtown}/tribes/${req.param.tribeId}/www/nginx_${req.params.tribeId}_${req.params.website}.conf // if profils accessright return the nginx conf in ${conf.dirtown}/tribes/${req.param.tribeId}/www/nginx_${req.params.tribeId}_${req.params.website}.conf
router.get("/conf/:tribeId/:website", checkHeaders, isAuthenticated, (req, res) => { router.get(
"/conf/:tribeId/:website",
checkHeaders,
isAuthenticated,
(req, res) => {
res.send(Www.configlist(req.params.tribeId)); res.send(Www.configlist(req.params.tribeId));
}); }
router.post("/conf/:tribeId/:website", checkHeaders, isAuthenticated, (req, res) => { );
router.post(
"/conf/:tribeId/:website",
checkHeaders,
isAuthenticated,
(req, res) => {
res.send(Wwws.create(req.params.tribeId)); res.send(Wwws.create(req.params.tribeId));
}); }
);
/** /**
* @api {get} /adminapi/wwws/initlocaldb/:tribe/:appname - Get app data model * @api {get} /api/adminapi/wwws/updatelocaldbanonymous/:tribe/:appname/:pagename/:version - Get app data model for anonymous only
* @apiGroup Wwws * @apiGroup Wwws
* @apiName getappcontext * @apiName getappcontext
* @apiDescription Get data base from backend to localstorage * @apiDescription Get data base from backend to localstorage
* *
* @apiParams {string} tribe (adminapi,smatchit,..) to looking for * @apiParams {string} tribe (adminapi,smatchit,..) to looking for
* @apiParams {string} appname agregate a full data referential to store localy * @apiParams {string} appname agregate a full data referential to store localy
* @apiSuccess {object} contain data model for a local web or mobile app in a PWA logical in the language of the header * @apiParams {string} pagename app page name
* @apiParams {interger} version the current version
* @apiSuccess {object} contain new version data model for a local web app in a PWA logical in the language of the header or if no new version exist then return
* @apiSuccessExample {json} Success-Response: * @apiSuccessExample {json} Success-Response:
* HTTP/1.1 200 OK * HTTP/1.1 200 OK
* {"status":200, "ref":"Odmdb", "msg":"datamodel", "data":{} * {"status":200, "ref":"Odmdb", "msg":"datamodelupdate", "data":{version,conpages,profils,...}}
* {"status":200, "ref":"Odmdb", "msg":"nonewdatamodel", "data":{}}
*/ */
router.get("/initlocaldb/:tribe/:appname", checkHeaders, isAuthenticated, (req, res) => { router.get(
console.log('pass localstorage') "/updatelocaldbanonymous/:tribe/:appname/:pagename/:version",
const getlocal = Wwws.initlocaldata(req.params.tribe,req.params.appname,req.session.header.xprofils,req.session.header.xlang); checkHeaders,
res.status(getlocal.status).json(getlocal) (req, res) => {
console.log("pass localstorage anonymous", req.session.header.xalias);
req.session.header.xprofils = ["anonymous"];
console.log(req.session.header.xprofils);
//ajouter une detection de changement
const getlocal = Wwws.initlocaldata(
req.params.tribe,
req.params.appname,
req.params.pagename,
req.params.version,
req.session.header.xprofils,
req.session.header.xlang
);
res.status(getlocal.status).json(getlocal);
}
);
/**
* @api {get} /api/adminapi/wwws/updatelocaldb/:tribe/:appname/:pagename/:version - Get app data model
* @apiGroup Wwws
* @apiName getappcontext
* @apiDescription Get data base from backend to localstorage
*
* @apiParams {string} tribe (adminapi,smatchit,..) to looking for
* @apiParams {string} appname agregate a full data referential to store localy
* @apiParams {string} pagename app page name
* @apiParams {interger} version the current version
* @apiSuccess {object} contain new version data model for a local web app in a PWA logical in the language of the header or if no new version exist then return
* @apiSuccessExample {json} Success-Response:
* HTTP/1.1 200 OK
* {"status":200, "ref":"Odmdb", "msg":"datamodelupdate", "data":{version,conpages,profils,...}}
* {"status":200, "ref":"Odmdb", "msg":"nonewdatamodel", "data":{}}
*/
router.get(
"/updatelocaldb/:tribe/:appname/:pagename/:version",
checkHeaders, isAuthenticated,
(req, res) => {
console.log("pass localstorage", req.session.header.xalias);
console.log(req.session.header.xprofils);
//ajouter une detection de changement
const getlocal = Wwws.initlocaldata(
req.params.tribe,
req.params.appname,
req.params.pagename,
req.params.version,
req.session.header.xprofils,
req.session.header.xlang
);
res.status(getlocal.status).json(getlocal);
}
);
/**
* @api {get} /api/adminapi/wwws/buildpage/:tribe/:appname/:pagename - Create pagename
* @apiGroup Wwws
* @apiName createPagename
* @apiDescription Create a pagename from /appscreen/template/:pagename with
*
* @apiParams {string} tribe (adminapi,smatchit,..) to looking for
* @apiParams {string} appname agregate a full data referential to store localy
* @apiSuccess {object} contain cuurent version of the data model
* @apiSuccessExample {json} Success-Response:
* HTTP/1.1 200 OK
* {"status":200, "ref":"Odmdb", "msg":"datamodelversion", "data":{version}
*/
router.get("/buildpage/:tribe/:appname/:pagename", checkHeaders, (req, res) => {
console.log("pass get version localstorage");
const localdbf = `../../${req.params.tribe}/objects/wwws/itm/${req.params.appname}`;
if (!existsSync(localdbf)) {
return res
.status(404)
.json({ status: 404, ref: "Wwws", msg: "localdbnotfound", data: {} });
}
res
.status(200)
.json({
status: 200,
ref: "Wwws",
msg: "lastversion",
data: { version: fs.readJSONSync(localdbf).version },
});
}); });
module.exports = router; module.exports = router;