From c57f838d51a2cde0851b17ac6ffda214baefc610 Mon Sep 17 00:00:00 2001 From: Stamsy Date: Wed, 27 Nov 2024 12:12:51 +0200 Subject: [PATCH] add process response group --- .../nodes/Aws/Cognito/GenericFunctions.ts | 19 +++++++++++++++++++ .../Cognito/descriptions/GroupDescription.ts | 19 ++----------------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/packages/nodes-base/nodes/Aws/Cognito/GenericFunctions.ts b/packages/nodes-base/nodes/Aws/Cognito/GenericFunctions.ts index ebe216f6de..5d70f513b5 100644 --- a/packages/nodes-base/nodes/Aws/Cognito/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Aws/Cognito/GenericFunctions.ts @@ -116,6 +116,25 @@ export async function processAttributes( return requestOptions; } +/* Helper function to process Group Response */ +export async function processGroupsResponse( + this: IExecuteSingleFunctions, + items: INodeExecutionData[], + response: IN8nHttpFullResponse, +): Promise { + const responseBody = response.body as { Groups: IDataObject[] }; + + if (!responseBody || !Array.isArray(responseBody.Groups)) { + throw new ApplicationError('Unexpected response format: No groups found.'); + } + + const executionData: INodeExecutionData[] = responseBody.Groups.map((group) => ({ + json: group, + })); + + return executionData; +} + /* Helper function to handle pagination */ const possibleRootProperties = ['Users']; // Root properties that can be returned by the list operations of the API // ToDo: Test if pagination works diff --git a/packages/nodes-base/nodes/Aws/Cognito/descriptions/GroupDescription.ts b/packages/nodes-base/nodes/Aws/Cognito/descriptions/GroupDescription.ts index 019010cbf1..efdd57fd46 100644 --- a/packages/nodes-base/nodes/Aws/Cognito/descriptions/GroupDescription.ts +++ b/packages/nodes-base/nodes/Aws/Cognito/descriptions/GroupDescription.ts @@ -1,7 +1,7 @@ import type { IExecuteSingleFunctions, IHttpRequestOptions, INodeProperties } from 'n8n-workflow'; import { NodeOperationError } from 'n8n-workflow'; -import { handleErrorPostReceive } from '../GenericFunctions'; +import { handleErrorPostReceive, processGroupsResponse } from '../GenericFunctions'; export const groupOperations: INodeProperties[] = [ { @@ -100,22 +100,7 @@ export const groupOperations: INodeProperties[] = [ }, }, output: { - postReceive: [ - handleErrorPostReceive, - { - type: 'set', - properties: { - value: '={{ $response.body.Groups }}', - }, - }, - { - type: 'set', - properties: { - value: - '={{ $response.body.Groups.length > 10 && $parameter.simplified ? $response.body.Groups.map(group => ({ CreatedDate: group.CreatedDate, Description: group.Description, GroupName: group.GroupName, LastModifiedDate: group.LastModifiedDate })) : $response.body.Groups }}', // Simplify if more than 10 fields - }, - }, - ], + postReceive: [handleErrorPostReceive, processGroupsResponse], }, }, action: 'Get many groups',