From a342c30175bd3130072c68a24848a60b195db12d Mon Sep 17 00:00:00 2001 From: chenos Date: Tue, 15 Dec 2020 09:58:42 +0800 Subject: [PATCH] fix: dynamic action params --- packages/app/src/api/index.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/app/src/api/index.ts b/packages/app/src/api/index.ts index 6359cd55c..9573d27cb 100644 --- a/packages/app/src/api/index.ts +++ b/packages/app/src/api/index.ts @@ -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);