mirror of
https://github.com/n8n-io/n8n.git
synced 2026-06-01 17:27:14 +02:00
52 lines
1.3 KiB
TypeScript
52 lines
1.3 KiB
TypeScript
import {
|
|
NodeOperationError,
|
|
type IDisplayOptions,
|
|
type IExecuteFunctions,
|
|
type INodeExecutionData,
|
|
type INodeProperties,
|
|
} from 'n8n-workflow';
|
|
|
|
import { DRY_RUN } from '../../common/fields';
|
|
import { getSelectFields, getSelectFilter } from '../../common/selectMany';
|
|
import { getDataTableProxyExecute, getDryRunParameter } from '../../common/utils';
|
|
|
|
// named `deleteRows` since `delete` is a reserved keyword
|
|
export const FIELD: string = 'deleteRows';
|
|
|
|
const displayOptions: IDisplayOptions = {
|
|
show: {
|
|
resource: ['row'],
|
|
operation: [FIELD],
|
|
},
|
|
};
|
|
|
|
export const description: INodeProperties[] = [
|
|
...getSelectFields(displayOptions),
|
|
{
|
|
displayName: 'Options',
|
|
name: 'options',
|
|
type: 'collection',
|
|
default: {},
|
|
placeholder: 'Add option',
|
|
options: [DRY_RUN],
|
|
displayOptions,
|
|
},
|
|
];
|
|
|
|
export async function execute(
|
|
this: IExecuteFunctions,
|
|
index: number,
|
|
): Promise<INodeExecutionData[]> {
|
|
const dataTableProxy = await getDataTableProxyExecute(this, index);
|
|
const dryRun = getDryRunParameter(this, index);
|
|
const filter = await getSelectFilter(this, index);
|
|
|
|
if (filter.filters.length === 0) {
|
|
throw new NodeOperationError(this.getNode(), 'At least one condition is required');
|
|
}
|
|
|
|
const result = await dataTableProxy.deleteRows({ filter, dryRun });
|
|
|
|
return result.map((json) => ({ json }));
|
|
}
|