mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
feat(core): Refactor data table update row to use filters (no-changelog) (#19092)
This commit is contained in:
@@ -7,7 +7,7 @@ import {
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { makeAddRow, getAddRow } from '../../common/addRow';
|
||||
import { executeSelectMany, getSelectFields } from '../../common/selectMany';
|
||||
import { getSelectFields, getSelectFilter } from '../../common/selectMany';
|
||||
import { getDataTableProxyExecute } from '../../common/utils';
|
||||
|
||||
export const FIELD: string = 'update';
|
||||
@@ -31,26 +31,16 @@ export async function execute(
|
||||
const dataStoreProxy = await getDataTableProxyExecute(this, index);
|
||||
|
||||
const row = getAddRow(this, index);
|
||||
const filter = getSelectFilter(this, index);
|
||||
|
||||
const matches = await executeSelectMany(this, index, dataStoreProxy, true);
|
||||
|
||||
const result = [];
|
||||
for (const x of matches) {
|
||||
const updatedRows = await dataStoreProxy.updateRows({
|
||||
data: row,
|
||||
filter: { id: x.json.id },
|
||||
});
|
||||
if (updatedRows.length !== 1) {
|
||||
throw new NodeOperationError(this.getNode(), 'invariant broken');
|
||||
}
|
||||
|
||||
// The input object gets updated in the api call, somehow
|
||||
// And providing this column to the backend causes an unexpected column error
|
||||
// So let's just re-delete the field until we have a more aligned API
|
||||
delete row['updatedAt'];
|
||||
|
||||
result.push(updatedRows[0]);
|
||||
if (filter.filters.length === 0) {
|
||||
throw new NodeOperationError(this.getNode(), 'At least one condition is required');
|
||||
}
|
||||
|
||||
return result.map((json) => ({ json }));
|
||||
const updatedRows = await dataStoreProxy.updateRows({
|
||||
data: row,
|
||||
filter,
|
||||
});
|
||||
|
||||
return updatedRows.map((json) => ({ json }));
|
||||
}
|
||||
|
||||
@@ -45,7 +45,10 @@ export async function execute(
|
||||
for (const match of matches) {
|
||||
const updatedRows = await dataStoreProxy.updateRows({
|
||||
data: row,
|
||||
filter: { id: match.json.id },
|
||||
filter: {
|
||||
type: 'and',
|
||||
filters: [{ columnName: 'id', condition: 'eq', value: match.json.id }],
|
||||
},
|
||||
});
|
||||
if (updatedRows.length !== 1) {
|
||||
throw new NodeOperationError(this.getNode(), 'invariant broken');
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { NodeOperationError } from 'n8n-workflow';
|
||||
import type {
|
||||
DataTableFilter,
|
||||
DataStoreRowReturn,
|
||||
IDataStoreProjectService,
|
||||
IDisplayOptions,
|
||||
@@ -94,7 +95,7 @@ export function getSelectFields(
|
||||
];
|
||||
}
|
||||
|
||||
export function getSelectFilter(ctx: IExecuteFunctions, index: number) {
|
||||
export function getSelectFilter(ctx: IExecuteFunctions, index: number): DataTableFilter {
|
||||
const fields = ctx.getNodeParameter('filters.conditions', index, []);
|
||||
const matchType = ctx.getNodeParameter('matchType', index, ANY_CONDITION);
|
||||
const node = ctx.getNode();
|
||||
|
||||
@@ -2,7 +2,7 @@ import { DateTime } from 'luxon';
|
||||
import type {
|
||||
IDataObject,
|
||||
INode,
|
||||
ListDataStoreContentFilter,
|
||||
DataTableFilter,
|
||||
IDataStoreProjectAggregateService,
|
||||
IDataStoreProjectService,
|
||||
IExecuteFunctions,
|
||||
@@ -82,7 +82,7 @@ export function isMatchType(obj: unknown): obj is FilterType {
|
||||
export function buildGetManyFilter(
|
||||
fieldEntries: FieldEntry[],
|
||||
matchType: FilterType,
|
||||
): ListDataStoreContentFilter {
|
||||
): DataTableFilter {
|
||||
const filters = fieldEntries.map((x) => {
|
||||
switch (x.condition) {
|
||||
case 'isEmpty':
|
||||
|
||||
Reference in New Issue
Block a user