apxtrib/app/routes/odmdb.js

79 lines
3.4 KiB
JavaScript
Raw Normal View History

2023-04-13 05:46:35 +00:00
const express = require( 'express' );
const glob = require( 'glob' );
const path = require( 'path' );
// Classes
const Odmdb = require( '../models/Odmdb.js' );
// Middlewares
const checkHeaders = require( '../middlewares/checkHeaders' );
const isAuthenticated = require( '../middlewares/isAuthenticated' );
const hasAccessrighton = require( '../middlewares/hasAccessrighton' );
const router = express.Router();
router.get('/searchauth/:objectname/:question',checkHeaders,isAuthenticated,( req, res ) => {
/**
*
*
*/
console.log( 'route referentials get all language' + req.params.objectname + '-' + req.params.question );
const getref = Referentials.getref( true, req.params.source, req.params.idref, req.session.header.xworkon, req.session.header.xlang );
// Return any status the data if any erreur return empty object
res.jsonp( getref.payload.data );
} );
router.get('schema/:objectname', checkHeaders, isAuthenticated,(req,res)=>{
/**
* @api {get} /odmdb/schema/:objectname
* @apiName GetSchema
* @apiGroup Odmdb
*
* @apiUse apxHeader
*
* @apiParam {String} objectname Mandatory if headers.xworkon == nationchains then into ./nationchains/ else into ./tribes/xworkon/
*
* @apiError (404) {string} info a key word to understand not found schema
* @apiError (404) {string} ref an string to find referential to get description of info in xlang request
* @apiError (404) {object} [moreinfo} an object with element to render ref_lg.json[info] to understand error
*
* @apiSuccess (200) {object} data contains schema requested
*
*/
const fullpath = path.resolve(`${__dirname}/tribes/${req.session.header.xworkon}/schema/${req.params.pathobjectname}.json`);
if (fs.existsSync(fullpath)){
res.status(200).json(data:fs.readJsonSync(fullpath))
}else{
res.status(404).json(info:"schemanotfound", ref:"odmdb", moreinfo:{fullpath})
}
})
router.put('schema/:objectname', checkHeaders, isAuthenticated,(req,res)=>{
/**
* @api {put} /odmdb/schema/:objectname
* @apiName putSchema
* @apiGroup Odmdb
*
* @apiUse apxHeader
*
* @apiParam {String} objectname Mandatory if headers.xworkon == nationchains then into ./nationchains/ else into ./tribes/xworkon/
* @apiBody {string} schemapath where to store schema .../schema
* @apiBody {string} objectpath where to store object ...objectname/index/config.json
* @apiBody {json} schema content
* @apiBody {json} schemalang content in lg
* @apiBody {string} lang define which schemalg is (2 letters)
*
* @apiError (404) {string} info a key word to understand not found schema
* @apiError (404) {string} ref an string to find referential to get description of info in xlang request
* @apiError (404) {object} [moreinfo} an object with element to render ref_lg.json[info] to understand error
*
* @apiSuccess (200) {object} data contains schema requested
*
*/
const fullpath = path.resolve(`${__dirname}/tribes/${req.session.header.xworkon}/schema/${req.params.pathobjectname}.json`);
const set=Odmdb.setObject(path.resolve(`${__dirname}/tribes/${req.session.header.xworkon}`),)
if (fs.existsSync(fullpath)){
res.status(200).json(data:fs.readJsonSync(fullpath))
}else{
res.status(404).json(info:"schemanotfound", ref:"odmdb", moreinfo:{fullpath})
}
})
module.exports = router;