From 7f7b73d750d2ca71be0d49ec2f70462eb7c89e44 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Tue, 10 Jan 2023 19:20:32 +0800 Subject: [PATCH] fix(nocodb): retrieve correct model based on view, hook or column --- packages/nocodb/src/lib/models/Filter.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/nocodb/src/lib/models/Filter.ts b/packages/nocodb/src/lib/models/Filter.ts index 42838aa22d..f663a215c5 100644 --- a/packages/nocodb/src/lib/models/Filter.ts +++ b/packages/nocodb/src/lib/models/Filter.ts @@ -1,6 +1,7 @@ import Noco from '../Noco'; import Model from './Model'; import Column from './Column'; +import Hook from './Hook'; import { CacheDelDirection, CacheGetType, @@ -70,9 +71,6 @@ export default class Filter { filter: Partial, ncMeta = Noco.ncMeta ) { - if (!filter.fk_column_id) { - NcError.badRequest('fk_column_id is required'); - } const insertObj = { id: filter.id, fk_view_id: filter.fk_view_id, @@ -94,7 +92,16 @@ export default class Filter { }), }; if (!(filter.project_id && filter.base_id)) { - const model = await Column.get({ colId: filter.fk_column_id }, ncMeta); + let model: { project_id?: string; base_id?: string }; + if (filter.fk_view_id) { + model = await View.get(filter.fk_view_id, ncMeta); + } else if (filter.fk_hook_id) { + model = await Hook.get(filter.fk_hook_id, ncMeta); + } else if (filter.fk_column_id) { + model = await Column.get({ colId: filter.fk_column_id }, ncMeta); + } else { + NcError.badRequest('Invalid filter'); + } insertObj.project_id = model.project_id; insertObj.base_id = model.base_id; }