🔀 Feature/mattermost extended (#588)

This commit is contained in:
Ricardo Espinoza
2020-05-22 17:10:52 -04:00
committed by GitHub
parent 4241cd2ed6
commit ab1dcf64b9

View File

@@ -98,9 +98,9 @@ export class Mattermost implements INodeType {
description: 'Soft-deletes a channel', description: 'Soft-deletes a channel',
}, },
{ {
name: 'Members', name: 'Member',
value: 'members', value: 'members',
description: 'Returns the members of a channel.', description: 'Get a page of members for a channel.',
}, },
{ {
name: 'Restore', name: 'Restore',
@@ -317,6 +317,23 @@ export class Mattermost implements INodeType {
}, },
description: 'The Mattermost Team.', description: 'The Mattermost Team.',
}, },
{
displayName: 'Resolve Data',
name: 'resolveData',
type: 'boolean',
displayOptions: {
show: {
resource: [
'channel',
],
operation: [
'members',
],
},
},
default: true,
description: 'By default the response only contain the ID of the user.<br />If this option gets activated it will resolve the user automatically.',
},
{ {
displayName: 'Return All', displayName: 'Return All',
name: 'returnAll', name: 'returnAll',
@@ -950,6 +967,11 @@ export class Mattermost implements INodeType {
value: 'getByEmail', value: 'getByEmail',
description: 'Get a user by email', description: 'Get a user by email',
}, },
{
name: 'Get By ID',
value: 'getById',
description: 'Get a user by id',
},
], ],
default: '', default: '',
description: 'The operation to perform.', description: 'The operation to perform.',
@@ -1113,6 +1135,54 @@ export class Mattermost implements INodeType {
default: '', default: '',
description: `User's email`, description: `User's email`,
}, },
// ----------------------------------
// user:getById
// ----------------------------------
{
displayName: 'User IDs',
name: 'userIds',
type: 'string',
required: true,
displayOptions: {
show: {
resource: [
'user',
],
operation: [
'getById',
],
},
},
default: '',
description: `User's ID`,
},
{
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
placeholder: 'Add Field',
displayOptions: {
show: {
resource: [
'user',
],
operation: [
'getById',
],
},
},
default: {},
options: [
{
displayName: 'Since',
name: 'since',
type: 'dateTime',
default: '',
description: 'Only return users that have been modified since the given Unix timestamp (in milliseconds).',
},
],
},
], ],
}; };
@@ -1245,6 +1315,10 @@ export class Mattermost implements INodeType {
let resource: string; let resource: string;
let requestMethod = 'POST'; let requestMethod = 'POST';
let returnAll = false; let returnAll = false;
let userIds: string[] = [];
resource = this.getNodeParameter('resource', 0) as string;
operation = this.getNodeParameter('operation', 0) as string;
// For Post // For Post
let body: IDataObject; let body: IDataObject;
@@ -1256,9 +1330,6 @@ export class Mattermost implements INodeType {
body = {}; body = {};
qs = {}; qs = {};
resource = this.getNodeParameter('resource', i) as string;
operation = this.getNodeParameter('operation', i) as string;
if (resource === 'channel') { if (resource === 'channel') {
if (operation === 'create') { if (operation === 'create') {
// ---------------------------------- // ----------------------------------
@@ -1509,6 +1580,25 @@ export class Mattermost implements INodeType {
endpoint = `users/email/${email}`; endpoint = `users/email/${email}`;
} }
if (operation === 'getById') {
// ----------------------------------
// user:getById
// ----------------------------------
userIds = (this.getNodeParameter('userIds', i) as string).split(',') as string[];
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
if (additionalFields.since) {
qs.since = new Date(additionalFields.since as string).getTime();
}
requestMethod = 'POST';
endpoint = 'users/ids';
//@ts-ignore
body = userIds;
}
} }
else { else {
throw new Error(`The resource "${resource}" is not known!`); throw new Error(`The resource "${resource}" is not known!`);
@@ -1519,6 +1609,18 @@ export class Mattermost implements INodeType {
responseData = await apiRequestAllItems.call(this, requestMethod, endpoint, body, qs); responseData = await apiRequestAllItems.call(this, requestMethod, endpoint, body, qs);
} else { } else {
responseData = await apiRequest.call(this, requestMethod, endpoint, body, qs); responseData = await apiRequest.call(this, requestMethod, endpoint, body, qs);
if (resource === 'channel' && operation === 'members') {
const resolveData = this.getNodeParameter('resolveData', i) as boolean;
if (resolveData) {
const userIds: string[] = [];
for (const data of responseData) {
userIds.push(data.user_id);
}
if (userIds.length > 0) {
responseData = await apiRequest.call(this, 'POST', 'users/ids', userIds , qs);
}
}
}
} }
if (Array.isArray(responseData)) { if (Array.isArray(responseData)) {
returnData.push.apply(returnData, responseData); returnData.push.apply(returnData, responseData);