forked from apxtri/apxtri
modif odmdb accessright
This commit is contained in:
parent
4b7cf11712
commit
355b1cebd5
@ -221,7 +221,7 @@ Odmdb.Schema = (objectPathname, validschema, lg="en") => {
|
|||||||
status: 404,
|
status: 404,
|
||||||
ref: "Odmdb",
|
ref: "Odmdb",
|
||||||
msg: "schemanotfound",
|
msg: "schemanotfound",
|
||||||
data: { objectPathname, schema: {} },
|
data: { objectPathname:path.resolve(objectPathname), schema: {} },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -471,6 +471,7 @@ Odmdb.accessright = (apxaccessrights, role) => {
|
|||||||
|
|
||||||
Odmdb.cud = (objectPathname, crud, itm, role, runindex = true) => {
|
Odmdb.cud = (objectPathname, crud, itm, role, runindex = true) => {
|
||||||
const getschema = Odmdb.Schema(objectPathname, true);
|
const getschema = Odmdb.Schema(objectPathname, true);
|
||||||
|
|
||||||
if (getschema.status != 200) return getschema;
|
if (getschema.status != 200) return getschema;
|
||||||
|
|
||||||
if (!itm[getschema.data.schema.apxid]) {
|
if (!itm[getschema.data.schema.apxid]) {
|
||||||
@ -486,7 +487,7 @@ Odmdb.cud = (objectPathname, crud, itm, role, runindex = true) => {
|
|||||||
const existid = fs.existsSync(
|
const existid = fs.existsSync(
|
||||||
`${objectPathname}/itm/${itm[getschema.data.schema.apxid]}.json`
|
`${objectPathname}/itm/${itm[getschema.data.schema.apxid]}.json`
|
||||||
);
|
);
|
||||||
|
if (log) console.log(currentmod,"Pass schema itm existid = ", existid)
|
||||||
/*const pathindex = `${objectPathname}/idx/lst_${getschema.data.schema.apxid}.json`;
|
/*const pathindex = `${objectPathname}/idx/lst_${getschema.data.schema.apxid}.json`;
|
||||||
if (!fs.existsSync(pathindex)) {
|
if (!fs.existsSync(pathindex)) {
|
||||||
fs.outputJSONSync(pathindex, []);
|
fs.outputJSONSync(pathindex, []);
|
||||||
@ -538,12 +539,13 @@ Odmdb.cud = (objectPathname, crud, itm, role, runindex = true) => {
|
|||||||
getschema.data.schema.apxaccessrights,
|
getschema.data.schema.apxaccessrights,
|
||||||
role
|
role
|
||||||
);
|
);
|
||||||
if (log) console.log(currentmod,"accessright", accessright);
|
|
||||||
if (
|
if (
|
||||||
(crud == "C" && !accessright.C) ||
|
(crud == "C" && !accessright.C) ||
|
||||||
(crud == "D" && !accessright.D) ||
|
(crud == "D" && !accessright.D) ||
|
||||||
(crud == "U" && !accessright.U)
|
(crud == "U" && !accessright.U)
|
||||||
) {
|
) {
|
||||||
|
if (log) console.log(currentmod,"Forbidden accessright:", accessright);
|
||||||
return {
|
return {
|
||||||
status: 403,
|
status: 403,
|
||||||
ref: "Odmdb",
|
ref: "Odmdb",
|
||||||
@ -578,7 +580,11 @@ Odmdb.cud = (objectPathname, crud, itm, role, runindex = true) => {
|
|||||||
itmtostore,
|
itmtostore,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
if (chkdata.status != 200) return chkdata;
|
if (chkdata.status != 200) {
|
||||||
|
if (log) console.log(currentmod,"Unconsistency data", chkdata);
|
||||||
|
return chkdata;
|
||||||
|
}
|
||||||
|
if (log) console.log(currentmod,"Data compliance with schema");
|
||||||
if (!getschema.data.schema.apxuniquekey)
|
if (!getschema.data.schema.apxuniquekey)
|
||||||
getschema.data.schema.apxuniquekey = [];
|
getschema.data.schema.apxuniquekey = [];
|
||||||
if (log) console.log(currentmod,`${objectPathname}/itm/${chkdata.data.apxid}.json`);
|
if (log) console.log(currentmod,`${objectPathname}/itm/${chkdata.data.apxid}.json`);
|
||||||
|
@ -228,8 +228,47 @@ router.get(
|
|||||||
router.post("/itm/:objectname", checkHeaders, isAuthenticated, (req, res) => {
|
router.post("/itm/: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
|
||||||
res.json({});
|
const objectPathname=`../../${req.session.header.xtribe}/objects/${req.params.objectname}`;
|
||||||
|
const postitm=Odmdb.cud(objectPathname,"C",req.body,{xprofils:req.session.header.xprofils,xalias:req.session.header.xalias});
|
||||||
|
res.status(postitm.status).json(postitm);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @api {put} /adminapi/odmdb/itm/:objectname - item Update
|
||||||
|
* @apiGroup Odmdb
|
||||||
|
* @apiName putItm
|
||||||
|
* @apiPermission none
|
||||||
|
* @apiDescription Update an item (data) into a collection of objectname items. Before Check data integrity with the relevant schema.
|
||||||
|
* Then create a new primarykey. For multilanguage return see nationchains/model/lg/Odmdb_xx.json.
|
||||||
|
*
|
||||||
|
* @apiParam {string} objectname Place where to create new item, schema and version are available in /objectname/conf.json
|
||||||
|
*
|
||||||
|
* @apiBody {Object} data must pass Checkjson.js with schema
|
||||||
|
*
|
||||||
|
* @apiSuccess {json} data idxprimary Value of idxprimary into objectname collection
|
||||||
|
* @apiSuccessExample {json} Success-Response:
|
||||||
|
* HTTP/1.1 200 OK
|
||||||
|
* {"status":200, "ref":"Odmdb", "msg":"cudsuccessfull", "data":{"itm":{}}}
|
||||||
|
*
|
||||||
|
* @apiError {json} schemanotfound The objectname schema is not found
|
||||||
|
* @apiError {json} pathnamedoesnotexist The objectname does not exist for the tribe
|
||||||
|
* @apiError {json} missingprimarykey Body data must have primarykey to be created
|
||||||
|
* @apiError {json} unconsistencyapxidx some Body data get unique key that already exist
|
||||||
|
* @apiError {json} checkjsonfalse The body data are not consistent with the schema
|
||||||
|
* @apiErrorExample {json}
|
||||||
|
* HTTP/1.1 404 Not Found
|
||||||
|
* {"status":404,"ref":"Odmdb","msg":"see nationchains/model/lg/Odmdb_xx.json","data":"object to render with msg"}
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
router.put("/itm/:objectname", checkHeaders, isAuthenticated, (req, res) => {
|
||||||
|
// Create an item of an object with no specificities
|
||||||
|
// if specificities then create a route / model that import odmdb
|
||||||
|
const objectPathname=`../../${req.session.header.xtribe}/objects/${req.params.objectname}`;
|
||||||
|
const postitm=Odmdb.cud(objectPathname,"U",req.body,{xprofils:req.session.header.xprofils,xalias:req.session.header.xalias});
|
||||||
|
res.status(postitm.status).json(postitm);
|
||||||
|
});
|
||||||
|
|
||||||
router.get(
|
router.get(
|
||||||
"/searchitems/:objectname/:question",
|
"/searchitems/:objectname/:question",
|
||||||
checkHeaders,
|
checkHeaders,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user