mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-14 08:34:07 -08:00
b03e358a12
* 👕 Enable `consistent-type-imports` for nodes-base
* 👕 Apply to nodes-base
* ⏪ Undo unrelated changes
* 🚚 Move to `.eslintrc.js` in nodes-base
* ⏪ Revert "Enable `consistent-type-imports` for nodes-base"
This reverts commit 529ad72b05
.
* 👕 Fix severity
58 lines
1.8 KiB
TypeScript
58 lines
1.8 KiB
TypeScript
import type { IExecuteFunctions } from 'n8n-core';
|
|
|
|
import type { IDataObject, 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 type { Mattermost } from './Interfaces';
|
|
|
|
export async function router(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
|
const items = this.getInputData();
|
|
const operationResult: INodeExecutionData[] = [];
|
|
let responseData: IDataObject | IDataObject[] = [];
|
|
|
|
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') {
|
|
responseData = await channel[mattermost.operation].execute.call(this, i);
|
|
} else if (mattermost.resource === 'message') {
|
|
responseData = await message[mattermost.operation].execute.call(this, i);
|
|
} else if (mattermost.resource === 'reaction') {
|
|
responseData = await reaction[mattermost.operation].execute.call(this, i);
|
|
} else if (mattermost.resource === 'user') {
|
|
responseData = await user[mattermost.operation].execute.call(this, i);
|
|
}
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
this.helpers.returnJsonArray(responseData),
|
|
{ itemData: { item: i } },
|
|
);
|
|
operationResult.push(...executionData);
|
|
} 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];
|
|
}
|