handle when a filter exist for equal & null

This commit is contained in:
Vik 2023-04-25 17:47:14 +05:30
parent 75b7c185d9
commit 3aa6e16286
2 changed files with 49 additions and 0 deletions

View file

@ -2,12 +2,25 @@ import { tooljetDatabaseService } from '@/_services';
import { isEmpty } from 'lodash';
import PostgrestQueryBuilder from '@/_helpers/postgrestQueryBuilder';
import { resolveReferences } from '@/_helpers/utils';
import { hasEqualWithNull } from './util';
export const tooljetDbOperations = {
perform,
};
async function perform(queryOptions, organizationId, currentState) {
const hasNullWithEqual = hasEqualWithNull(queryOptions);
// SQL does not support equal operation with null value, so let's handle it here.
if (hasNullWithEqual) {
return {
status: 'failed',
statusText: 'failed',
message: 'Query can not run, because app can not perform equal operation with null value',
description: 'Please use IS operator with the null value comparision.',
data: {},
};
}
switch (queryOptions.operation) {
case 'list_rows':
return listRows(queryOptions, organizationId, currentState);

View file

@ -0,0 +1,36 @@
import { get } from 'lodash';
/**
* Checks if the queryOptions object contains a filter with an 'eq' (equal) operator and a value equal to '{{null}}'.
*
* @function hasEqualWithNull
* @param {Object} queryOptions - The query options object to check for the presence of the specified filter.
* @property {Object} queryOptions.list_rows.where_filters - An object containing the filters to be checked.
* @returns {boolean} - Returns true if the specified filter is found, false otherwise.
*
* @example
* const queryOptions = {
* list_rows: {
* where_filters: {
* filter1: {
* operator: 'eq',
* value: '{{null}}',
* },
* },
* },
* };
*
* const result = hasEqualWithNull(queryOptions); // true
*/
export const hasEqualWithNull = (queryOptions) => {
const filters = get(queryOptions, 'list_rows.where_filters');
if (filters) {
const filterKeys = Object.keys(filters);
for (let i = 0; i < filterKeys.length; i++) {
const filter = filters[filterKeys[i]];
if (filter.operator === 'eq' && filter.value === '{{null}}') {
return true;
}
}
}
return false;
};