mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-27 21:49:41 -08:00
216ec079c9
## Summary This is part-1 of refactoring our code editors to extract different type of editors into their own components. In part-2 we'll 1. delete a of unused or duplicate code 2. switch to a `useEditor` composable to bring more UX consistency across all the code editors. ## Review / Merge checklist - [x] PR title and summary are descriptive - [x] Tests included
77 lines
2.1 KiB
TypeScript
77 lines
2.1 KiB
TypeScript
import type {
|
|
IDataObject,
|
|
IExecuteFunctions,
|
|
INodeExecutionData,
|
|
INodeProperties,
|
|
} from 'n8n-workflow';
|
|
import { NodeOperationError, jsonParse } from 'n8n-workflow';
|
|
|
|
import { theHiveApiRequest } from '../../transport';
|
|
import { updateDisplayOptions, wrapData } from '@utils/utilities';
|
|
|
|
const properties: INodeProperties[] = [
|
|
{
|
|
displayName: 'Query',
|
|
name: 'queryJson',
|
|
type: 'json',
|
|
required: true,
|
|
default: '=[\n {\n "_name": "listOrganisation"\n }\n]',
|
|
description: 'Search for objects with filtering and sorting capabilities',
|
|
hint: 'The query should be an array of operations with the required selection and optional filtering, sorting, and pagination. See <a href="https://docs.strangebee.com/thehive/api-docs/#operation/Query%20API" target="_blank">Query API</a> for more information.',
|
|
typeOptions: {
|
|
rows: 10,
|
|
},
|
|
},
|
|
];
|
|
|
|
const displayOptions = {
|
|
show: {
|
|
resource: ['query'],
|
|
operation: ['executeQuery'],
|
|
},
|
|
};
|
|
|
|
export const description = updateDisplayOptions(displayOptions, properties);
|
|
|
|
export async function execute(this: IExecuteFunctions, i: number): Promise<INodeExecutionData[]> {
|
|
let responseData: IDataObject | IDataObject[] = [];
|
|
|
|
const queryJson = this.getNodeParameter('queryJson', i) as string;
|
|
|
|
let query: IDataObject = {};
|
|
if (typeof queryJson === 'object') {
|
|
query = queryJson;
|
|
} else {
|
|
query = jsonParse<IDataObject>(queryJson, {
|
|
errorMessage: 'Query JSON must be a valid JSON object',
|
|
});
|
|
}
|
|
|
|
if (query.query) {
|
|
query = query.query as IDataObject;
|
|
}
|
|
|
|
if (!Array.isArray(query)) {
|
|
throw new NodeOperationError(
|
|
this.getNode(),
|
|
'The query should be an array of operations with the required selection and optional filtering, sorting, and pagination',
|
|
);
|
|
}
|
|
|
|
const body: IDataObject = {
|
|
query,
|
|
};
|
|
|
|
responseData = await theHiveApiRequest.call(this, 'POST', '/v1/query', body);
|
|
|
|
if (typeof responseData !== 'object') {
|
|
responseData = { queryResult: responseData };
|
|
}
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(wrapData(responseData), {
|
|
itemData: { item: i },
|
|
});
|
|
|
|
return executionData;
|
|
}
|