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,
|
IExecuteSingleFunctions,
|
||||||
IHttpRequestOptions,
|
IHttpRequestOptions,
|
||||||
ILoadOptionsFunctions,
|
ILoadOptionsFunctions,
|
||||||
|
IN8nHttpFullResponse,
|
||||||
INodeExecutionData,
|
INodeExecutionData,
|
||||||
INodeListSearchItems,
|
INodeListSearchItems,
|
||||||
INodeListSearchResult,
|
INodeListSearchResult,
|
||||||
|
@ -344,6 +345,7 @@ export async function formatCustomProperties(
|
||||||
requestOptions: IHttpRequestOptions,
|
requestOptions: IHttpRequestOptions,
|
||||||
): Promise<IHttpRequestOptions> {
|
): Promise<IHttpRequestOptions> {
|
||||||
const rawCustomProperties = this.getNodeParameter('customProperties', '{}') as string;
|
const rawCustomProperties = this.getNodeParameter('customProperties', '{}') as string;
|
||||||
|
const newId = this.getNodeParameter('newId') as string;
|
||||||
|
|
||||||
let parsedProperties: Record<string, unknown>;
|
let parsedProperties: Record<string, unknown>;
|
||||||
try {
|
try {
|
||||||
|
@ -371,7 +373,7 @@ export async function formatCustomProperties(
|
||||||
requestOptions.body = {};
|
requestOptions.body = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.assign(requestOptions.body as Record<string, unknown>, parsedProperties);
|
Object.assign(requestOptions.body as Record<string, unknown>, { id: newId }, parsedProperties);
|
||||||
|
|
||||||
return requestOptions;
|
return requestOptions;
|
||||||
}
|
}
|
||||||
|
@ -418,6 +420,32 @@ export async function formatJSONFields(
|
||||||
return requestOptions;
|
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(
|
export async function mapOperationsToRequest(
|
||||||
this: IExecuteSingleFunctions,
|
this: IExecuteSingleFunctions,
|
||||||
requestOptions: IHttpRequestOptions,
|
requestOptions: IHttpRequestOptions,
|
||||||
|
@ -458,7 +486,6 @@ export async function mapOperationsToRequest(
|
||||||
return formattedOperation;
|
return formattedOperation;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Assign the formatted operations to the request body
|
|
||||||
requestOptions.body = { operations: formattedOperations };
|
requestOptions.body = { operations: formattedOperations };
|
||||||
|
|
||||||
return requestOptions;
|
return requestOptions;
|
||||||
|
|
|
@ -3,6 +3,7 @@ import type { INodeProperties } from 'n8n-workflow';
|
||||||
import {
|
import {
|
||||||
formatCustomProperties,
|
formatCustomProperties,
|
||||||
handlePagination,
|
handlePagination,
|
||||||
|
processResponse,
|
||||||
validateOperations,
|
validateOperations,
|
||||||
validateQueryParameters,
|
validateQueryParameters,
|
||||||
} from '../GenericFunctions';
|
} from '../GenericFunctions';
|
||||||
|
@ -32,8 +33,7 @@ export const itemOperations: INodeProperties[] = [
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: '=/colls/{{ $parameter["collId"] }}/docs',
|
url: '=/colls/{{ $parameter["collId"] }}/docs',
|
||||||
headers: {
|
headers: {
|
||||||
// 'x-ms-partitionkey': '=["{{$parameter["newId"]}}"]',
|
'x-ms-documentdb-partitionkey': '=["{{$parameter["newId"]}}"]',
|
||||||
// 'x-ms-documentdb-partitionkey': '=["{{$parameter["newId"]}}"]',
|
|
||||||
'x-ms-documentdb-is-upsert': 'True',
|
'x-ms-documentdb-is-upsert': 'True',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -83,14 +83,7 @@ export const itemOperations: INodeProperties[] = [
|
||||||
url: '=/colls/{{ $parameter["collId"] }}/docs',
|
url: '=/colls/{{ $parameter["collId"] }}/docs',
|
||||||
},
|
},
|
||||||
output: {
|
output: {
|
||||||
postReceive: [
|
postReceive: [processResponse],
|
||||||
{
|
|
||||||
type: 'rootProperty',
|
|
||||||
properties: {
|
|
||||||
property: 'json',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
action: 'Get many items',
|
action: 'Get many items',
|
||||||
|
@ -186,28 +179,28 @@ export const createFields: INodeProperties[] = [
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
// {
|
{
|
||||||
// displayName: 'ID',
|
displayName: 'ID',
|
||||||
// name: 'newId',
|
name: 'newId',
|
||||||
// type: 'string',
|
type: 'string',
|
||||||
// default: '',
|
default: '',
|
||||||
// placeholder: 'e.g. AndersenFamily',
|
placeholder: 'e.g. AndersenFamily',
|
||||||
// description: "Item's ID",
|
description: "Item's ID",
|
||||||
// required: true,
|
required: true,
|
||||||
// displayOptions: {
|
displayOptions: {
|
||||||
// show: {
|
show: {
|
||||||
// resource: ['item'],
|
resource: ['item'],
|
||||||
// operation: ['create'],
|
operation: ['create'],
|
||||||
// },
|
},
|
||||||
// },
|
},
|
||||||
// routing: {
|
routing: {
|
||||||
// send: {
|
send: {
|
||||||
// type: 'body',
|
type: 'body',
|
||||||
// property: 'id',
|
property: 'id',
|
||||||
// value: '={{$value}}',
|
value: '={{$value}}',
|
||||||
// },
|
},
|
||||||
// },
|
},
|
||||||
// },
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Custom Properties',
|
displayName: 'Custom Properties',
|
||||||
name: 'customProperties',
|
name: 'customProperties',
|
||||||
|
|
Loading…
Reference in a new issue