n8n/packages/nodes-base/nodes/N8nTrainingCustomerDatastore/N8nTrainingCustomerDatastore.node.ts
agobrech 409a9ea357
fix: Add paired item to the most used nodes (#5220)
* PairedItem for N8n training

* Add paired item to ftp node

* Add paired item to rocketChat

* Add pairedItem to pushOver

* Add paired item to Matrix

* Add pairedItem to theHive

* Add paired item to Snowflake

* Add paired item to PhilipsHue

* Add pairedItem to supabase

* Add paired item to Odoo

* fix odoo & add paired item to grist

* add pairedItem to Linkedin

* add pairedItem Zulip

* add pairedItem PhatomBuster

* add pairedItem to TodoistV2

* Add pairedItem HomeAssistant

* Add pairedItem to DropContact

* Add pairedItem to Aws SES

* Add pairedItem to microsoftOutlook

* Add pairedItem to AwsS3

* Add pairedItem to Aws DynamoDB

* 🐛 fix Dropcontact enrich operation paired item support

* 🐛 fix Dropcontact insert/update operation paired items

* 🐛 fix Supabase paired item support

* 🐛 fix Supabase paired item support

* 🐛 fix N8nTrainingCustomerDatastore paired item support

* 🎨 remove unused imports

* 🐛 fix MicrosoftOutlook paired item support

* 🐛 fix AwsS3 paired item support

---------

Co-authored-by: Marcus <marcus@n8n.io>
2023-01-31 20:39:20 +01:00

148 lines
3.4 KiB
TypeScript

import type { IExecuteFunctions } from 'n8n-core';
import type { INodeExecutionData, INodeType, INodeTypeDescription } from 'n8n-workflow';
const data = [
{
id: '23423532',
name: 'Jay Gatsby',
email: 'gatsby@west-egg.com',
notes: 'Keeps asking about a green light??',
country: 'US',
created: '1925-04-10',
},
{
id: '23423533',
name: 'José Arcadio Buendía',
email: 'jab@macondo.co',
notes: 'Lots of people named after him. Very confusing',
country: 'CO',
created: '1967-05-05',
},
{
id: '23423534',
name: 'Max Sendak',
email: 'info@in-and-out-of-weeks.org',
notes: 'Keeps rolling his terrible eyes',
country: 'US',
created: '1963-04-09',
},
{
id: '23423535',
name: 'Zaphod Beeblebrox',
email: 'captain@heartofgold.com',
notes: 'Felt like I was talking to more than one person',
country: null,
created: '1979-10-12',
},
{
id: '23423536',
name: 'Edmund Pevensie',
email: 'edmund@narnia.gov',
notes: 'Passionate sailor',
country: 'UK',
created: '1950-10-16',
},
];
export class N8nTrainingCustomerDatastore implements INodeType {
description: INodeTypeDescription = {
displayName: 'Customer Datastore (n8n training)',
name: 'n8nTrainingCustomerDatastore',
icon: 'file:n8nTrainingCustomerDatastore.svg',
group: ['transform'],
version: 1,
subtitle: '={{$parameter["operation"]}}',
description: 'Dummy node used for n8n training',
defaults: {
name: 'Customer Datastore (n8n training)',
},
inputs: ['main'],
outputs: ['main'],
properties: [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
options: [
{
name: 'Get One Person',
value: 'getOnePerson',
},
{
name: 'Get All People',
value: 'getAllPeople',
},
],
default: 'getOnePerson',
},
{
displayName: 'Return All',
name: 'returnAll',
type: 'boolean',
displayOptions: {
show: {
operation: ['getAllPeople'],
},
},
default: false,
description: 'Whether to return all results or only up to a given limit',
},
{
displayName: 'Limit',
name: 'limit',
type: 'number',
displayOptions: {
show: {
operation: ['getAllPeople'],
returnAll: [false],
},
},
typeOptions: {
minValue: 1,
maxValue: 10,
},
default: 5,
description: 'Max number of results to return',
},
],
};
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const items = this.getInputData();
const returnData: INodeExecutionData[] = [];
const length = items.length;
const operation = this.getNodeParameter('operation', 0);
let responseData;
for (let i = 0; i < length; i++) {
if (operation === 'getOnePerson') {
responseData = data[0];
}
if (operation === 'getAllPeople') {
const returnAll = this.getNodeParameter('returnAll', i);
if (returnAll) {
responseData = data;
} else {
const limit = this.getNodeParameter('limit', i);
responseData = data.slice(0, limit);
}
}
if (Array.isArray(responseData)) {
const executionData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray(responseData),
{ itemData: { item: i } },
);
returnData.push.apply(returnData, executionData);
} else if (responseData !== undefined) {
returnData.push({ json: responseData });
}
}
return this.prepareOutputData(returnData);
}
}