diff --git a/frontend/src/Editor/QueryManager/QueryEditors/TooljetDatabase/operations.js b/frontend/src/Editor/QueryManager/QueryEditors/TooljetDatabase/operations.js index 9e3302756d..87fabfa900 100644 --- a/frontend/src/Editor/QueryManager/QueryEditors/TooljetDatabase/operations.js +++ b/frontend/src/Editor/QueryManager/QueryEditors/TooljetDatabase/operations.js @@ -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; diff --git a/frontend/src/Editor/QueryManager/QueryEditors/TooljetDatabase/util.js b/frontend/src/Editor/QueryManager/QueryEditors/TooljetDatabase/util.js new file mode 100644 index 0000000000..d67aa2d53c --- /dev/null +++ b/frontend/src/Editor/QueryManager/QueryEditors/TooljetDatabase/util.js @@ -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; +};