Browse Source

feat(nocodb): implement hasEmptyOrNullFilters

pull/5106/head
Wing-Kam Wong 2 years ago
parent
commit
b04f5bb868
  1. 10
      packages/nocodb/src/lib/meta/api/projectApis.ts
  2. 38
      packages/nocodb/src/lib/models/Filter.ts

10
packages/nocodb/src/lib/meta/api/projectApis.ts

@ -10,6 +10,7 @@ import syncMigration from '../helpers/syncMigration';
import { IGNORE_TABLES } from '../../utils/common/BaseApiBuilder';
import Column from '../../models/Column';
import Model from '../../models/Model';
import Filter from '../../models/Filter';
import NcHelp from '../../utils/NcHelp';
import Base from '../../models/Base';
import NcConnectionMgrv2 from '../../utils/common/NcConnectionMgrv2';
@ -497,6 +498,10 @@ export async function projectCost(req, res) {
res.json({ cost });
}
export async function hasEmptyOrNullFilters(req, res) {
res.json(await Filter.hasEmptyOrNullFilters(req.params.projectId));
}
export default (router) => {
router.get(
'/api/v1/db/meta/projects/:projectId/info',
@ -533,4 +538,9 @@ export default (router) => {
metaApiMetrics,
ncMetaAclMw(projectList, 'projectList')
);
router.get(
'/api/v1/db/meta/projects/:projectId/has-empty-or-null-filters',
metaApiMetrics,
ncMetaAclMw(hasEmptyOrNullFilters, 'hasEmptyOrNullFilters')
);
};

38
packages/nocodb/src/lib/models/Filter.ts

@ -527,4 +527,42 @@ export default class Filter {
}
return filterObjs?.map((f) => new Filter(f));
}
static async hasEmptyOrNullFilters(projectId: string, ncMeta = Noco.ncMeta) {
const emptyOrNullFilterObjs = await ncMeta.metaList2(
null,
null,
MetaTable.FILTER_EXP,
{
condition: {
project_id: projectId,
},
xcCondition: {
_or: [
{
comparison_op: {
eq: 'null',
},
},
{
comparison_op: {
eq: 'notnull',
},
},
{
comparison_op: {
eq: 'empty',
},
},
{
comparison_op: {
eq: 'notempty',
},
},
],
},
}
);
return emptyOrNullFilterObjs.length > 0;
}
}

Loading…
Cancel
Save