parent
3196510276
commit
409b98e01d
|
@ -1,6 +1,8 @@
|
|||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
const BACK_MODELS = `back/models`;
|
||||
const FILE_EXTENSION = '.json';
|
||||
const FILE_ENCODING = 'utf-8';
|
||||
module.exports = Self => {
|
||||
Self.remoteMethod('logInfo', {
|
||||
description: 'Gets all models information',
|
||||
|
@ -20,19 +22,26 @@ module.exports = Self => {
|
|||
const modules = fs.readdirSync(modulesDir);
|
||||
|
||||
for (const mod of modules) {
|
||||
const modelsDir = path.join(modulesDir, mod, `back/models`);
|
||||
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);
|
||||
}
|
||||
handleModels(modelsDir);
|
||||
}
|
||||
const pathVn = path.join(process.cwd(), BACK_MODELS);
|
||||
handleModels(pathVn);
|
||||
|
||||
Self.logInfo = async function() {
|
||||
return Object.fromEntries(modelsLocale);
|
||||
};
|
||||
|
||||
function handleModels(modelsDir) {
|
||||
const models = (fs.readdirSync(modelsDir)).filter(fileName => fileName.endsWith(FILE_EXTENSION));
|
||||
for (const model of models) {
|
||||
const modelFile = path.join(modelsDir, model);
|
||||
const modelConfig = JSON.parse(fs.readFileSync(modelFile, {encoding: FILE_ENCODING}));
|
||||
const {log} = modelConfig;
|
||||
if (!log?.mainTable) continue;
|
||||
const key = modelConfig.name.startsWith('Vn') ? modelConfig.name.slice(2) : modelConfig.name;
|
||||
modelsLocale.set(key.toLowerCase(), log);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue