mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
Extracted documents from response
This commit is contained in:
parent
704f9aa81a
commit
1a51a0fdb3
|
@ -6,6 +6,7 @@ import type {
|
|||
IExecuteSingleFunctions,
|
||||
IHttpRequestOptions,
|
||||
ILoadOptionsFunctions,
|
||||
IN8nHttpFullResponse,
|
||||
INodeExecutionData,
|
||||
INodeListSearchItems,
|
||||
INodeListSearchResult,
|
||||
|
@ -344,6 +345,7 @@ export async function formatCustomProperties(
|
|||
requestOptions: IHttpRequestOptions,
|
||||
): Promise<IHttpRequestOptions> {
|
||||
const rawCustomProperties = this.getNodeParameter('customProperties', '{}') as string;
|
||||
const newId = this.getNodeParameter('newId') as string;
|
||||
|
||||
let parsedProperties: Record<string, unknown>;
|
||||
try {
|
||||
|
@ -371,7 +373,7 @@ export async function formatCustomProperties(
|
|||
requestOptions.body = {};
|
||||
}
|
||||
|
||||
Object.assign(requestOptions.body as Record<string, unknown>, parsedProperties);
|
||||
Object.assign(requestOptions.body as Record<string, unknown>, { id: newId }, parsedProperties);
|
||||
|
||||
return requestOptions;
|
||||
}
|
||||
|
@ -418,6 +420,32 @@ export async function formatJSONFields(
|
|||
return requestOptions;
|
||||
}
|
||||
|
||||
export async function processResponse(
|
||||
this: IExecuteSingleFunctions,
|
||||
items: INodeExecutionData[],
|
||||
response: IN8nHttpFullResponse,
|
||||
): Promise<any> {
|
||||
if (!response || typeof response !== 'object' || !Array.isArray(items)) {
|
||||
throw new ApplicationError('Invalid response format from Cosmos DB.');
|
||||
}
|
||||
|
||||
const extractedDocuments: IDataObject[] = items.flatMap((item) => {
|
||||
if (
|
||||
item.json &&
|
||||
typeof item.json === 'object' &&
|
||||
'Documents' in item.json &&
|
||||
Array.isArray(item.json.Documents)
|
||||
) {
|
||||
return item.json.Documents as IDataObject[];
|
||||
}
|
||||
|
||||
return [];
|
||||
});
|
||||
|
||||
return extractedDocuments;
|
||||
}
|
||||
|
||||
//WIP
|
||||
export async function mapOperationsToRequest(
|
||||
this: IExecuteSingleFunctions,
|
||||
requestOptions: IHttpRequestOptions,
|
||||
|
@ -458,7 +486,6 @@ export async function mapOperationsToRequest(
|
|||
return formattedOperation;
|
||||
});
|
||||
|
||||
// Assign the formatted operations to the request body
|
||||
requestOptions.body = { operations: formattedOperations };
|
||||
|
||||
return requestOptions;
|
||||
|
|
|
@ -3,6 +3,7 @@ import type { INodeProperties } from 'n8n-workflow';
|
|||
import {
|
||||
formatCustomProperties,
|
||||
handlePagination,
|
||||
processResponse,
|
||||
validateOperations,
|
||||
validateQueryParameters,
|
||||
} from '../GenericFunctions';
|
||||
|
@ -32,8 +33,7 @@ export const itemOperations: INodeProperties[] = [
|
|||
method: 'POST',
|
||||
url: '=/colls/{{ $parameter["collId"] }}/docs',
|
||||
headers: {
|
||||
// 'x-ms-partitionkey': '=["{{$parameter["newId"]}}"]',
|
||||
// 'x-ms-documentdb-partitionkey': '=["{{$parameter["newId"]}}"]',
|
||||
'x-ms-documentdb-partitionkey': '=["{{$parameter["newId"]}}"]',
|
||||
'x-ms-documentdb-is-upsert': 'True',
|
||||
},
|
||||
},
|
||||
|
@ -83,14 +83,7 @@ export const itemOperations: INodeProperties[] = [
|
|||
url: '=/colls/{{ $parameter["collId"] }}/docs',
|
||||
},
|
||||
output: {
|
||||
postReceive: [
|
||||
{
|
||||
type: 'rootProperty',
|
||||
properties: {
|
||||
property: 'json',
|
||||
},
|
||||
},
|
||||
],
|
||||
postReceive: [processResponse],
|
||||
},
|
||||
},
|
||||
action: 'Get many items',
|
||||
|
@ -186,28 +179,28 @@ export const createFields: INodeProperties[] = [
|
|||
},
|
||||
],
|
||||
},
|
||||
// {
|
||||
// displayName: 'ID',
|
||||
// name: 'newId',
|
||||
// type: 'string',
|
||||
// default: '',
|
||||
// placeholder: 'e.g. AndersenFamily',
|
||||
// description: "Item's ID",
|
||||
// required: true,
|
||||
// displayOptions: {
|
||||
// show: {
|
||||
// resource: ['item'],
|
||||
// operation: ['create'],
|
||||
// },
|
||||
// },
|
||||
// routing: {
|
||||
// send: {
|
||||
// type: 'body',
|
||||
// property: 'id',
|
||||
// value: '={{$value}}',
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
{
|
||||
displayName: 'ID',
|
||||
name: 'newId',
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: 'e.g. AndersenFamily',
|
||||
description: "Item's ID",
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['item'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
routing: {
|
||||
send: {
|
||||
type: 'body',
|
||||
property: 'id',
|
||||
value: '={{$value}}',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Custom Properties',
|
||||
name: 'customProperties',
|
||||
|
|
Loading…
Reference in a new issue