n8n/packages/nodes-base/nodes/Mattermost/v1/actions/router.ts
Jan Oberhauser bdb84130d6
feat(core): Add support for pairedItem (beta) (#3012)
*  Add pairedItem support

* 👕 Fix lint issue

* 🐛 Fix resolution in frontend

* 🐛 Fix resolution issue

* 🐛 Fix resolution in frontend

* 🐛 Fix another resolution issue in frontend

*  Try to automatically add pairedItem data if possible

*  Cleanup

*  Display expression errors in editor UI

* 🐛 Fix issue that it did not display errors in production

* 🐛 Fix auto-fix of missing pairedItem data

* 🐛 Fix frontend resolution for not executed nodes

*  Fail execution on pairedItem resolve issue and display information
about itemIndex and runIndex

*  Allow that pairedItem is only set to number if runIndex is 0

*  Improve Expression Errors

*  Remove no longer needed code

*  Make errors more helpful

*  Add additional errors

* 👕 Fix lint issue

*  Add pairedItem support to core nodes

*  Improve support in Merge-Node

*  Fix issue with not correctly converted incoming pairedItem data

* 🐛 Fix frontend resolve issue

* 🐛 Fix frontend parameter name display issue

*  Improve errors

* 👕 Fix lint issue

*  Improve errors

*  Make it possible to display parameter name in error messages

*  Improve error messages

*  Fix error message

*  Improve error messages

*  Add another error message

*  Simplify
2022-06-03 17:25:07 +02:00

55 lines
1.6 KiB
TypeScript

import {
IExecuteFunctions,
} from 'n8n-core';
import {
INodeExecutionData,
} from 'n8n-workflow';
import * as channel from './channel';
import * as message from './message';
import * as reaction from './reaction';
import * as user from './user';
import { Mattermost } from './Interfaces';
export async function router(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const items = this.getInputData();
const operationResult: INodeExecutionData[] = [];
for (let i = 0; i < items.length; i++) {
const resource = this.getNodeParameter<Mattermost>('resource', i);
let operation = this.getNodeParameter('operation', i);
if (operation === 'del') {
operation = 'delete';
} else if (operation === 'desactive') {
operation = 'deactive';
}
const mattermost = {
resource,
operation,
} as Mattermost;
try {
if (mattermost.resource === 'channel') {
operationResult.push(...await channel[mattermost.operation].execute.call(this, i));
} else if (mattermost.resource === 'message') {
operationResult.push(...await message[mattermost.operation].execute.call(this, i));
} else if (mattermost.resource === 'reaction') {
operationResult.push(...await reaction[mattermost.operation].execute.call(this, i));
} else if (mattermost.resource === 'user') {
operationResult.push(...await user[mattermost.operation].execute.call(this, i));
}
} catch (err) {
if (this.continueOnFail()) {
operationResult.push({json: this.getInputData(i)[0].json, error: err});
} else {
if (err.context) err.context.itemIndex = i;
throw err;
}
}
}
return [operationResult];
}