Add label API

This commit is contained in:
trojanh 2020-01-20 20:58:51 +05:30
parent d28a3f7387
commit b944ed5f6b

View file

@ -55,6 +55,10 @@ export class Trello implements INodeType {
name: "Checklist",
value: "checklist",
},
{
name: "Label",
value: "label"
}
{
name: 'List',
value: 'list',
@ -2000,8 +2004,373 @@ export class Trello implements INodeType {
],
},
],
// ----------------------------------
// label
// ----------------------------------
{
displayName: 'Operation',
name: 'operation',
type: 'options',
displayOptions: {
show: {
resource: [
'label',
],
},
},
options: [
{
name: 'Add to Card',
value: 'addLabel',
description: 'Add a label to a card.',
},
{
name: 'Create',
value: 'create',
description: 'Create a new label',
},
{
name: 'Delete',
value: 'delete',
description: 'Delete a label',
},
{
name: 'Get',
value: 'get',
description: 'Get the data of a label',
},
{
name: 'Get All',
value: 'getAll',
description: 'Returns all label for the board',
},
{
name: 'Remove From Card',
value: 'removeLabel',
description: 'Remove a label from a card.',
},
{
name: 'Update',
value: 'update',
description: 'Update a label.',
}
],
default: 'getAll',
description: 'The operation to perform.',
},
// ----------------------------------
// label:create
// ----------------------------------
{
displayName: 'Board ID',
name: 'boardId',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
operation: [
'create',
],
resource: [
'label',
],
},
},
description: 'The ID of the board to create the label on.',
},
{
displayName: 'Name',
name: 'name',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
operation: [
'create',
],
resource: [
'label',
],
},
},
description: 'Name for the label.',
},
{
displayName: 'Color',
name: 'color',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
operation: [
'create',
],
resource: [
'label',
],
},
},
description: 'The color for the label. See [fields](https://developers.trello.com/reference#label-object) for color options.',
},
// ----------------------------------
// label:delete
// ----------------------------------
{
displayName: 'Label ID',
name: 'id',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
operation: [
'delete',
],
resource: [
'label',
],
},
},
description: 'The ID of the label to delete.',
},
// ----------------------------------
// label:getAll
// ----------------------------------
{
displayName: 'Board ID',
name: 'boardId',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
operation: [
'getAll',
],
resource: [
'label',
],
},
},
description: 'The ID of the board to get label.',
},
{
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
placeholder: 'Add Field',
displayOptions: {
show: {
operation: [
'getAll',
],
resource: [
'label',
],
},
},
default: {},
options: [
{
displayName: 'Fields',
name: 'fields',
type: 'string',
default: 'all',
description: 'Fields to return. Either "all" or a comma-separated list of fields.',
},
],
},
// ----------------------------------
// label:get
// ----------------------------------
{
displayName: 'Label ID',
name: 'id',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
operation: [
'get',
],
resource: [
'label',
],
},
},
description: 'Get information about a label by ID.',
},
{
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
placeholder: 'Add Field',
displayOptions: {
show: {
operation: [
'get',
],
resource: [
'label',
],
},
},
default: {},
options: [
{
displayName: 'Fields',
name: 'fields',
type: 'string',
default: 'all',
description: 'Fields to return. Either "all" or a comma-separated list of fields.',
},
],
},
// ----------------------------------
// label:addLabel
// ----------------------------------
{
displayName: 'Card ID',
name: 'cardId',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
operation: [
'addLabel',
],
resource: [
'label',
],
},
},
description: 'The ID of the card to get label.',
},
{
displayName: 'Label ID',
name: 'id',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
operation: [
'addLabel',
],
resource: [
'label',
],
},
},
description: 'The ID of the label to add.',
},
// ----------------------------------
// label:removeLabel
// ----------------------------------
{
displayName: 'Card ID',
name: 'cardId',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
operation: [
'removeLabel',
],
resource: [
'label',
],
},
},
description: 'The ID of the card to remove label from.',
},
{
displayName: 'Label ID',
name: 'id',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
operation: [
'removeLabel',
],
resource: [
'label',
],
},
},
description: 'The ID of the label to remove.',
},
// ----------------------------------
// label:update
// ----------------------------------
{
displayName: 'Label ID',
name: 'id',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
operation: [
'update',
],
resource: [
'label',
],
},
},
description: 'The ID of the label to update.',
},
{
displayName: 'Update Fields',
name: 'updateFields',
type: 'collection',
placeholder: 'Add Field',
displayOptions: {
show: {
operation: [
'update',
],
resource: [
'label',
],
},
},
default: {},
options: [
{
displayName: 'Name',
name: 'name',
type: 'string',
default: '',
description: 'Name of the label.',
},
{
displayName: 'Color',
name: 'color',
type: 'string',
default: '',
description: 'The color for the label. See [fields](https://developers.trello.com/reference#label-object) for color options.',
}
],
},
],
};
@ -2384,6 +2753,111 @@ export class Trello implements INodeType {
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
Object.assign(qs, additionalFields);
} else {
throw new Error(`The operation "${operation}" is not known!`);
}
} else if (resource === 'label') {
if (operation === 'create') {
// ----------------------------------
// create
// ----------------------------------
requestMethod = 'POST';
const idBoard = this.getNodeParameter('boardId', i) as string;
const name = this.getNodeParameter('name', i) as string;
const color = this.getNodeParameter('color', i) as string;
Object.assign(qs, {
idBoard,
name,
color
});
endpoint = "labels";
} else if (operation === 'delete') {
// ----------------------------------
// delete
// ----------------------------------
requestMethod = 'DELETE';
const id = this.getNodeParameter('id', i) as string;
endpoint = `labels/${id}`;
} else if (operation === 'get') {
// ----------------------------------
// get
// ----------------------------------
requestMethod = 'GET';
const id = this.getNodeParameter('id', i) as string;
endpoint = `labels/${id}`;
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
Object.assign(qs, additionalFields);
} else if (operation === 'getAll') {
// ----------------------------------
// getAll
// ----------------------------------
requestMethod = 'GET';
const idBoard = this.getNodeParameter('boardId', i) as string;
endpoint = `board/${idBoard}/labels`;
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
Object.assign(qs, additionalFields);
} else if (operation === 'update') {
// ----------------------------------
// update
// ----------------------------------
requestMethod = 'PUT';
const id = this.getNodeParameter('id', i) as string;
endpoint = `labels/${id}`;
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
Object.assign(qs, updateFields);
} else if (operation === 'addLabel') {
// ----------------------------------
// addLabel
// ----------------------------------
requestMethod = 'POST';
const cardId = this.getNodeParameter('cardId', i) as string;
const id = this.getNodeParameter('id', i) as string;
qs.value = id;
endpoint = `/cards/${cardId}/idLabels`;
} else if (operation === 'removeLabel') {
// ----------------------------------
// addLabel
// ----------------------------------
requestMethod = 'DELETE';
const cardId = this.getNodeParameter('cardId', i) as string;
const id = this.getNodeParameter('id', i) as string;
endpoint = `/cards/${cardId}/idLabels/${id}`;
} else {
throw new Error(`The operation "${operation}" is not known!`);
}