feat(salix): refs #6533 #6533 feat logInfo method

This commit is contained in:
Javier Segarra 2024-04-24 14:16:39 +02:00
parent 940aa82cb2
commit 9b9e87ceb3
3 changed files with 31 additions and 9 deletions

View File

@ -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);
};
};

View File

@ -1,4 +1,5 @@
module.exports = function(Self) {
require('../methods/schema/model-info')(Self);
require('../methods/schema/log-info')(Self);
};

View File

@ -7,6 +7,12 @@
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW"
},
{
"property": "logInfo",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW"
}
]
}