🔀 Merge branch 'RicardoE105-feature/mattermost-node'

This commit is contained in:
Jan Oberhauser 2019-12-06 22:35:03 +01:00
commit 373bb66ce4

View file

@ -49,6 +49,10 @@ export class Mattermost implements INodeType {
name: 'Message', name: 'Message',
value: 'message', value: 'message',
}, },
{
name: 'User',
value: 'user',
},
], ],
default: 'message', default: 'message',
description: 'The resource to operate on.', description: 'The resource to operate on.',
@ -81,11 +85,15 @@ export class Mattermost implements INodeType {
value: 'create', value: 'create',
description: 'Create a new channel', description: 'Create a new channel',
}, },
{
name: 'Statistics',
value: 'statistics',
description: 'Get statistics for a channel.',
},
], ],
default: 'create', default: 'create',
description: 'The operation to perform.', description: 'The operation to perform.',
}, },
{ {
displayName: 'Operation', displayName: 'Operation',
name: 'operation', name: 'operation',
@ -98,6 +106,11 @@ export class Mattermost implements INodeType {
}, },
}, },
options: [ options: [
{
name: 'Delete',
value: 'delete',
description: 'Soft deletes a post, by marking the post as deleted in the database.',
},
{ {
name: 'Post', name: 'Post',
value: 'post', value: 'post',
@ -253,13 +266,58 @@ export class Mattermost implements INodeType {
}, },
description: 'The ID of the user to invite into channel.', description: 'The ID of the user to invite into channel.',
}, },
// ----------------------------------
// channel:statistics
// ----------------------------------
{
displayName: 'Channel ID',
name: 'channelId',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getChannels',
},
options: [],
default: '',
required: true,
displayOptions: {
show: {
operation: [
'statistics'
],
resource: [
'channel',
],
},
},
description: 'The ID of the channel to get the statistics from.',
},
// ---------------------------------- // ----------------------------------
// message // message
// ---------------------------------- // ----------------------------------
// ----------------------------------
// message:delete
// ----------------------------------
{
displayName: 'Post ID',
name: 'postId',
type: 'string',
required: true,
displayOptions: {
show: {
resource: [
'message',
],
operation: [
'delete',
],
},
},
default: '',
description: 'ID of the post to delete',
},
// ---------------------------------- // ----------------------------------
// message:post // message:post
// ---------------------------------- // ----------------------------------
@ -520,6 +578,51 @@ export class Mattermost implements INodeType {
}, },
], ],
}, },
// ----------------------------------
// user
// ----------------------------------
{
displayName: 'Operation',
name: 'operation',
type: 'options',
displayOptions: {
show: {
resource: [
'user',
],
},
},
options: [
{
name: 'Desactive',
value: 'desactive',
description: 'Deactivates the user and revokes all its sessions by archiving its user object.',
},
],
default: '',
description: 'The operation to perform.',
},
// ----------------------------------
// user:desactivate
// ----------------------------------
{
displayName: 'User ID',
name: 'userId',
type: 'string',
required: true,
displayOptions: {
show: {
resource: [
'user',
],
operation: [
'desactive',
],
},
},
default: '',
description: 'User GUID'
},
], ],
}; };
@ -663,9 +766,25 @@ export class Mattermost implements INodeType {
endpoint = `channels/${channelId}/members`; endpoint = `channels/${channelId}/members`;
} else if (operation === 'statistics') {
// ----------------------------------
// channel:statistics
// ----------------------------------
requestMethod = 'GET';
const channelId = this.getNodeParameter('channelId', i) as string;
endpoint = `channels/${channelId}/stats`;
} }
} else if (resource === 'message') { } else if (resource === 'message') {
if (operation === 'post') { if (operation === 'delete') {
// ----------------------------------
// message:delete
// ----------------------------------
const postId = this.getNodeParameter('postId', i) as string;
requestMethod = 'DELETE';
endpoint = `posts/${postId}`;
} else if (operation === 'post') {
// ---------------------------------- // ----------------------------------
// message:post // message:post
// ---------------------------------- // ----------------------------------
@ -701,7 +820,17 @@ export class Mattermost implements INodeType {
const otherOptions = this.getNodeParameter('otherOptions', i) as IDataObject; const otherOptions = this.getNodeParameter('otherOptions', i) as IDataObject;
Object.assign(body, otherOptions); Object.assign(body, otherOptions);
} }
} else { } else if (resource === 'user') {
if (operation === 'desactive') {
// ----------------------------------
// user:desactive
// ----------------------------------
const userId = this.getNodeParameter('userId', i) as string;
requestMethod = 'DELETE';
endpoint = `users/${userId}`;
}
}
else {
throw new Error(`The resource "${resource}" is not known!`); throw new Error(`The resource "${resource}" is not known!`);
} }