parent
940aa82cb2
commit
9b9e87ceb3
|
@ -1,13 +1,10 @@
|
|||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethod('logInfo', {
|
||||
description: 'Gets all models information',
|
||||
accepts: [
|
||||
{
|
||||
arg: 'ctx',
|
||||
type: 'Object',
|
||||
http: {source: 'context'}
|
||||
}
|
||||
],
|
||||
accepts: [],
|
||||
returns: {
|
||||
type: 'Object',
|
||||
root: true
|
||||
|
@ -18,6 +15,24 @@ module.exports = Self => {
|
|||
}
|
||||
});
|
||||
|
||||
Self.logInfo = async function(ctx) {
|
||||
const modelsLocale = new Map();
|
||||
const modulesDir = path.resolve(`${process.cwd()}/modules`);
|
||||
const modules = fs.readdirSync(modulesDir);
|
||||
|
||||
for (const mod of modules) {
|
||||
const modelsDir = path.join(modulesDir, mod, `back/models`);
|
||||
if (!fs.existsSync(modelsDir)) continue;
|
||||
const models = (fs.readdirSync(modelsDir)).filter(fileName => fileName.endsWith('.json'));
|
||||
for (const model of models) {
|
||||
const modelFile = path.join(modelsDir, model);
|
||||
const modelConfig = JSON.parse(fs.readFileSync(modelFile, {encoding: 'utf-8'}));
|
||||
const {log} = modelConfig;
|
||||
if (!log) continue;
|
||||
modelsLocale.set(modelConfig.name, log);
|
||||
}
|
||||
}
|
||||
|
||||
Self.logInfo = async function() {
|
||||
return Object.fromEntries(modelsLocale);
|
||||
};
|
||||
};
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
|
||||
module.exports = function(Self) {
|
||||
require('../methods/schema/model-info')(Self);
|
||||
require('../methods/schema/log-info')(Self);
|
||||
};
|
||||
|
|
|
@ -7,6 +7,12 @@
|
|||
"principalType": "ROLE",
|
||||
"principalId": "$everyone",
|
||||
"permission": "ALLOW"
|
||||
},
|
||||
{
|
||||
"property": "logInfo",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "$everyone",
|
||||
"permission": "ALLOW"
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue