fix: dynamic action params

This commit is contained in:
chenos 2020-12-15 09:58:42 +08:00
parent 7fcce0943a
commit a342c30175

View File

@ -12,6 +12,8 @@ const sync = {
},
};
console.log('process.env.NOCOBASE_ENV', process.env.NOCOBASE_ENV);
dotenv.config();
const api = Api.create({
@ -35,7 +37,7 @@ const api = Api.create({
},
});
api.resourcer.use(async (ctx, next) => {
api.resourcer.use(async (ctx: actions.Context, next) => {
const { resourceName } = ctx.action.params;
const table = ctx.db.getTable(resourceName);
// ctx.state.developerMode = {[Op.not]: null};
@ -43,6 +45,17 @@ api.resourcer.use(async (ctx, next) => {
if (table && table.hasField('developerMode') && ctx.state.developerMode === false) {
ctx.action.setParam('filter.developerMode', ctx.state.developerMode);
}
if (table) {
const except = [];
for (const [name, field] of table.getFields()) {
if (field.options.hidden) {
except.push(field.options.name);
}
}
if (except.length) {
ctx.action.setParam('fields.except', except);
}
}
await next();
});
api.resourcer.use(associated);