n8n/packages/nodes-base/nodes/Example.node.ts
Jan Oberhauser d432eae601 👕 Fix lint issue
2020-10-23 09:19:45 +02:00

69 lines
1.3 KiB
TypeScript

import { IExecuteFunctions } from 'n8n-core';
import {
INodeExecutionData,
INodeType,
INodeTypeDescription,
} from 'n8n-workflow';
export class Example implements INodeType {
description: INodeTypeDescription = {
displayName: 'Example',
name: 'example',
group: ['input'],
version: 1,
description: 'Example',
defaults: {
name: 'Example',
color: '#0000FF',
},
inputs: ['main'],
outputs: ['main'],
properties: [
{
displayName: 'Age',
name: 'age',
type: 'number',
default: 0,
},
{
displayName: 'Brand Name',
name: 'brandName',
type: 'string',
default: '',
},
],
};
execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const items = this.getInputData();
if (items.length === 0) {
items.push({json: {}});
}
const returnData: INodeExecutionData[] = [];
let item: INodeExecutionData;
for (let i = 0; i < items.length; i++) {
const age = this.getNodeParameter('age', i) as number | undefined;
const brandName = this.getNodeParameter('brandName', i) as string | undefined;
item = items[i];
const newItem: INodeExecutionData = {
json: {
age: age || item.json.age,
brandName: brandName || item.json.brandName,
},
};
returnData.push(newItem);
}
return this.prepareOutputData(returnData);
}
}