🔀 Merge branch 'Kiprosh-trello-attachment'

This commit is contained in:
Jan Oberhauser 2020-01-17 12:21:16 -06:00
commit 0b68362341

View file

@ -39,6 +39,10 @@ export class Trello implements INodeType {
name: 'resource',
type: 'options',
options: [
{
name: "Attachment",
value: "attachment"
},
{
name: 'Board',
value: 'board',
@ -1213,6 +1217,274 @@ export class Trello implements INodeType {
],
},
// ----------------------------------
// attachment
// ----------------------------------
{
displayName: 'Operation',
name: 'operation',
type: 'options',
displayOptions: {
show: {
resource: [
'attachment',
],
},
},
options: [
{
name: 'Create',
value: 'create',
description: 'Create a new board',
},
{
name: 'Delete',
value: 'delete',
description: 'Delete a board',
},
{
name: 'Get',
value: 'get',
description: 'Get the data of an attachments',
},
{
name: 'Get All',
value: 'getAll',
description: 'Returns all attachments for the card',
}
],
default: 'getAll',
description: 'The operation to perform.',
},
// ----------------------------------
// attachment:create
// ----------------------------------
{
displayName: 'Card ID',
name: 'cardId',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
operation: [
'create',
],
resource: [
'attachment',
],
},
},
description: 'The ID of the card to add attachment to.',
},
{
displayName: 'Source URL',
name: 'url',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
operation: [
'create',
],
resource: [
'attachment',
],
},
},
description: 'The URL of the attachment to add.',
},
{
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
placeholder: 'Add Field',
displayOptions: {
show: {
operation: [
'create',
],
resource: [
'attachment',
],
},
},
default: {},
options: [
{
displayName: 'MIME Type',
name: 'mimeType',
type: 'string',
default: '',
placeholder: 'image/png',
description: 'The MIME type of the attachment to add.',
},
{
displayName: 'Name',
name: 'name',
type: 'string',
default: '',
description: 'The name of the attachment to add.',
},
],
},
// ----------------------------------
// attachment:delete
// ----------------------------------
{
displayName: 'Card ID',
name: 'cardId',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
operation: [
'delete',
],
resource: [
'attachment',
],
},
},
description: 'The ID of the card to get delete.',
},
{
displayName: 'Attachment ID',
name: 'id',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
operation: [
'delete',
],
resource: [
'attachment',
],
},
},
description: 'The ID of the attachment to delete.',
},
// ----------------------------------
// attachment:getAll
// ----------------------------------
{
displayName: 'Card ID',
name: 'cardId',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
operation: [
'getAll',
],
resource: [
'attachment',
],
},
},
description: 'The ID of the card to get attachments.',
},
{
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
placeholder: 'Add Field',
displayOptions: {
show: {
operation: [
'getAll',
],
resource: [
'attachment',
],
},
},
default: {},
options: [
{
displayName: 'Fields',
name: 'fields',
type: 'string',
default: 'all',
description: 'Fields to return. Either "all" or a comma-separated list of fields.',
},
],
},
// ----------------------------------
// attachment:get
// ----------------------------------
{
displayName: 'Card ID',
name: 'cardId',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
operation: [
'get',
],
resource: [
'attachment',
],
},
},
description: 'The ID of the card to get attachment.',
},
{
displayName: 'Attachment ID',
name: 'id',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
operation: [
'get',
],
resource: [
'attachment',
],
},
},
description: 'The ID of the attachment to get.',
},
{
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
placeholder: 'Add Field',
displayOptions: {
show: {
operation: [
'get',
],
resource: [
'attachment',
],
},
},
default: {},
options: [
{
displayName: 'Fields',
name: 'fields',
type: 'string',
default: 'all',
description: 'Fields to return. Either "all" or a comma-separated list of fields.',
},
],
},
],
};
@ -1420,13 +1692,81 @@ export class Trello implements INodeType {
throw new Error(`The operation "${operation}" is not known!`);
}
} else if (resource === 'attachment') {
if (operation === 'create') {
// ----------------------------------
// create
// ----------------------------------
requestMethod = 'POST';
const cardId = this.getNodeParameter('cardId', i) as string;
const url = this.getNodeParameter('url', i) as string;
Object.assign(qs, {
url,
});
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
Object.assign(qs, additionalFields);
endpoint = `cards/${cardId}/attachments`;
} else if (operation === 'delete') {
// ----------------------------------
// delete
// ----------------------------------
requestMethod = 'DELETE';
const cardId = this.getNodeParameter('cardId', i) as string;
const id = this.getNodeParameter('id', i) as string;
endpoint = `cards/${cardId}/attachments/${id}`;
} else if (operation === 'get') {
// ----------------------------------
// get
// ----------------------------------
requestMethod = 'GET';
const cardId = this.getNodeParameter('cardId', i) as string;
const id = this.getNodeParameter('id', i) as string;
endpoint = `cards/${cardId}/attachments/${id}`;
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
Object.assign(qs, additionalFields);
} else if (operation === 'getAll') {
// ----------------------------------
// getAll
// ----------------------------------
requestMethod = 'GET';
const cardId = this.getNodeParameter('cardId', i) as string;
endpoint = `cards/${cardId}/attachments`;
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
Object.assign(qs, additionalFields);
} else {
throw new Error(`The operation "${operation}" is not known!`);
}
} else {
throw new Error(`The resource "${resource}" is not known!`);
}
const responseData = await apiRequest.call(this, requestMethod, endpoint, body, qs);
returnData.push(responseData as IDataObject);
if (Array.isArray(responseData)) {
returnData.push.apply(returnData, responseData as IDataObject[]);
} else {
returnData.push(responseData as IDataObject);
}
}
return [this.helpers.returnJsonArray(returnData)];