mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-06 06:48:21 +00:00
Merge pull request #6128 from ToolJet/bug_fix/handle_eq_with_null
bug-fix: 🐛 - handle when a filter exist for equal & null
This commit is contained in:
commit
6e5c2ca7c3
2 changed files with 64 additions and 0 deletions
|
|
@ -2,6 +2,7 @@ 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,
|
||||
|
|
@ -55,6 +56,15 @@ function buildPostgrestQuery(filters) {
|
|||
async function listRows(queryOptions, organizationId, currentState) {
|
||||
let query = [];
|
||||
const resolvedOptions = resolveReferences(queryOptions, currentState);
|
||||
if (hasEqualWithNull(resolvedOptions, 'list_rows')) {
|
||||
return {
|
||||
status: 'failed',
|
||||
statusText: 'failed',
|
||||
message: 'Null value comparison not allowed, To check null values Please use IS operator instead.',
|
||||
description: 'Is operator should be used with null value comparision.',
|
||||
data: {},
|
||||
};
|
||||
}
|
||||
const { table_name: tableName, list_rows: listRows } = resolvedOptions;
|
||||
|
||||
if (!isEmpty(listRows)) {
|
||||
|
|
@ -91,6 +101,15 @@ async function createRow(queryOptions, organizationId, currentState) {
|
|||
|
||||
async function updateRows(queryOptions, organizationId, currentState) {
|
||||
const resolvedOptions = resolveReferences(queryOptions, currentState);
|
||||
if (hasEqualWithNull(resolvedOptions, 'update_rows')) {
|
||||
return {
|
||||
status: 'failed',
|
||||
statusText: 'failed',
|
||||
message: 'Null value comparison not allowed, To check null values Please use IS operator instead.',
|
||||
description: 'Is operator should be used with null value comparision.',
|
||||
data: {},
|
||||
};
|
||||
}
|
||||
const { table_name: tableName, update_rows: updateRows } = resolvedOptions;
|
||||
const { where_filters: whereFilters, columns } = updateRows;
|
||||
|
||||
|
|
@ -108,6 +127,15 @@ async function updateRows(queryOptions, organizationId, currentState) {
|
|||
|
||||
async function deleteRows(queryOptions, organizationId, currentState) {
|
||||
const resolvedOptions = resolveReferences(queryOptions, currentState);
|
||||
if (hasEqualWithNull(resolvedOptions, 'delete_rows')) {
|
||||
return {
|
||||
status: 'failed',
|
||||
statusText: 'failed',
|
||||
message: 'Null value comparison not allowed, To check null values Please use IS operator instead.',
|
||||
description: 'Is operator should be used with null value comparision.',
|
||||
data: {},
|
||||
};
|
||||
}
|
||||
const { table_name: tableName, delete_rows: deleteRows = { whereFilters: {} } } = resolvedOptions;
|
||||
const { where_filters: whereFilters, limit = 1 } = deleteRows;
|
||||
|
||||
|
|
|
|||
|
|
@ -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, operation) => {
|
||||
const filters = get(queryOptions, `${operation}.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 !== 'is' && filter.value === null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
Loading…
Reference in a new issue