Files
Automata/packages/nodes-base/nodes/Mattermost/v1/actions/channel/search/execute.ts
Matthew Walther 1b993e4022 feat(Mattermost Node): Add support for Channel Search (#2687)
* Squashed commit of the following:

commit 9f76bdca9b4af4fd3ee429d1c381c3ed5529434c
Author: Matt Walther <matt@mashio.net>
Date:   Sun Jan 16 16:40:34 2022 -0600

    Mattermost Channel Search

* Add more boilerplate so Search action renders

* Changed order of search to make the operations alphabetical

*  Add pagination

Co-authored-by: Jonathan Bennetts <jonathan.bennetts@gmail.com>
Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
2022-03-19 19:57:53 +01:00

32 lines
855 B
TypeScript

import {
IExecuteFunctions,
} from 'n8n-core';
import {
IDataObject,
INodeExecutionData,
} from 'n8n-workflow';
import {
apiRequest,
} from '../../../transport';
export async function search(this: IExecuteFunctions, index: number): Promise<INodeExecutionData[]> {
const body = {} as IDataObject;
const qs = {} as IDataObject;
const requestMethod = 'POST';
const teamId = this.getNodeParameter('teamId', index);
const returnAll = this.getNodeParameter('returnAll', 0);
const endpoint = `teams/${teamId}/channels/search`;
body.term = this.getNodeParameter('term', index) as string;
let responseData = await apiRequest.call(this, requestMethod, endpoint, body, qs);
if (!returnAll) {
const limit = this.getNodeParameter('limit', 0);
responseData = responseData.slice(0, limit);
}
return this.helpers.returnJsonArray(responseData);
}