mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-21 02:56:40 -08:00
✨ Add functionality to Asana-Node and update operation
selection
This commit is contained in:
parent
4de2319a5a
commit
ccac2597f0
|
@ -21,6 +21,7 @@ export class Asana implements INodeType {
|
||||||
icon: 'file:asana.png',
|
icon: 'file:asana.png',
|
||||||
group: ['input'],
|
group: ['input'],
|
||||||
version: 1,
|
version: 1,
|
||||||
|
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
||||||
description: 'Access and edit Asana tasks',
|
description: 'Access and edit Asana tasks',
|
||||||
defaults: {
|
defaults: {
|
||||||
name: 'Asana',
|
name: 'Asana',
|
||||||
|
@ -36,42 +37,72 @@ export class Asana implements INodeType {
|
||||||
],
|
],
|
||||||
properties: [
|
properties: [
|
||||||
{
|
{
|
||||||
displayName: 'Operation',
|
displayName: 'Resource',
|
||||||
name: 'operation',
|
name: 'resource',
|
||||||
type: 'options',
|
type: 'options',
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
name: 'Create Task',
|
name: 'Task',
|
||||||
value: 'createTask',
|
value: 'task',
|
||||||
description: 'Creates a task',
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Delete Task',
|
name: 'User',
|
||||||
value: 'deleteTask',
|
value: 'user',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
default: 'task',
|
||||||
|
description: 'The resource to operate on.',
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// ----------------------------------
|
||||||
|
// task
|
||||||
|
// ----------------------------------
|
||||||
|
{
|
||||||
|
displayName: 'Operation',
|
||||||
|
name: 'operation',
|
||||||
|
type: 'options',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'task',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'Create',
|
||||||
|
value: 'create',
|
||||||
|
description: 'Create a task',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Delete',
|
||||||
|
value: 'delete',
|
||||||
description: 'Delete a task',
|
description: 'Delete a task',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Get Task',
|
name: 'Get',
|
||||||
value: 'getTask',
|
value: 'get',
|
||||||
description: 'Get data of task',
|
description: 'Get data of task',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Update Task',
|
name: 'Update',
|
||||||
value: 'updateTask',
|
value: 'update',
|
||||||
description: 'Update a task',
|
description: 'Update a task',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Search For Tasks',
|
name: 'Search',
|
||||||
value: 'searchForTasks',
|
value: 'search',
|
||||||
description: 'Search Tasks',
|
description: 'Search for tasks',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
default: 'createTask',
|
default: 'create',
|
||||||
description: 'The operation to perform.',
|
description: 'The operation to perform.',
|
||||||
},
|
},
|
||||||
|
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
// createTask
|
// task:create
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
{
|
{
|
||||||
displayName: 'Workspace',
|
displayName: 'Workspace',
|
||||||
|
@ -86,7 +117,10 @@ export class Asana implements INodeType {
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
operation: [
|
operation: [
|
||||||
'createTask',
|
'create',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'task',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -94,14 +128,17 @@ export class Asana implements INodeType {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Name',
|
displayName: 'Name',
|
||||||
name: 'taskName',
|
name: 'name',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
default: '',
|
default: '',
|
||||||
required: true,
|
required: true,
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
operation: [
|
operation: [
|
||||||
'createTask',
|
'create',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'task',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -109,18 +146,21 @@ export class Asana implements INodeType {
|
||||||
},
|
},
|
||||||
|
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
// deleteTask
|
// delete
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
{
|
{
|
||||||
displayName: 'Task ID',
|
displayName: 'Task ID',
|
||||||
name: 'taskId',
|
name: 'id',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
default: '',
|
default: '',
|
||||||
required: true,
|
required: true,
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
operation: [
|
operation: [
|
||||||
'deleteTask',
|
'delete',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'task',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -128,18 +168,21 @@ export class Asana implements INodeType {
|
||||||
},
|
},
|
||||||
|
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
// getTask
|
// get
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
{
|
{
|
||||||
displayName: 'Task ID',
|
displayName: 'Task ID',
|
||||||
name: 'taskId',
|
name: 'id',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
default: '',
|
default: '',
|
||||||
required: true,
|
required: true,
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
operation: [
|
operation: [
|
||||||
'getTask',
|
'get',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'task',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -147,18 +190,21 @@ export class Asana implements INodeType {
|
||||||
},
|
},
|
||||||
|
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
// updateTask
|
// update
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
{
|
{
|
||||||
displayName: 'Task ID',
|
displayName: 'Task ID',
|
||||||
name: 'taskId',
|
name: 'id',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
default: '',
|
default: '',
|
||||||
required: true,
|
required: true,
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
operation: [
|
operation: [
|
||||||
'updateTask',
|
'update',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'task',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -167,7 +213,7 @@ export class Asana implements INodeType {
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
// searchForTasks
|
// search
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
{
|
{
|
||||||
displayName: 'Workspace',
|
displayName: 'Workspace',
|
||||||
|
@ -182,7 +228,10 @@ export class Asana implements INodeType {
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
operation: [
|
operation: [
|
||||||
'searchForTasks',
|
'search',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'task',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -195,7 +244,10 @@ export class Asana implements INodeType {
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
operation: [
|
operation: [
|
||||||
'searchForTasks',
|
'search',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'task',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -226,18 +278,20 @@ export class Asana implements INodeType {
|
||||||
},
|
},
|
||||||
|
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
// createTask/updateTask
|
// create/update
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
{
|
{
|
||||||
displayName: 'Other Properties',
|
displayName: 'Other Properties',
|
||||||
name: 'otherProperties',
|
name: 'otherProperties',
|
||||||
type: 'collection',
|
type: 'collection',
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
hide: {
|
show: {
|
||||||
|
resource: [
|
||||||
|
'task',
|
||||||
|
],
|
||||||
operation: [
|
operation: [
|
||||||
'deleteTask',
|
'create',
|
||||||
'getTask',
|
'update',
|
||||||
'searchForTasks',
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -253,7 +307,7 @@ export class Asana implements INodeType {
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
'/operation': [
|
'/operation': [
|
||||||
'updateTask',
|
'update',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -294,6 +348,86 @@ export class Asana implements INodeType {
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// ----------------------------------
|
||||||
|
// user
|
||||||
|
// ----------------------------------
|
||||||
|
{
|
||||||
|
displayName: 'Operation',
|
||||||
|
name: 'operation',
|
||||||
|
type: 'options',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'user',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'Get All',
|
||||||
|
value: 'getAll',
|
||||||
|
description: 'Data of all users',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Get',
|
||||||
|
value: 'get',
|
||||||
|
description: 'Get data of user',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
default: 'get',
|
||||||
|
description: 'The operation to perform.',
|
||||||
|
},
|
||||||
|
|
||||||
|
// ----------------------------------
|
||||||
|
// user:get
|
||||||
|
// ----------------------------------
|
||||||
|
{
|
||||||
|
displayName: 'Id',
|
||||||
|
name: 'userId',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
required: true,
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: [
|
||||||
|
'get',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'user',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
description: 'An identifier for the user to get data of. Can be one of an<br />email address,the globally unique identifier for the user,<br />or the keyword me to indicate the current user making the request.',
|
||||||
|
},
|
||||||
|
|
||||||
|
// ----------------------------------
|
||||||
|
// user:getAll
|
||||||
|
// ----------------------------------
|
||||||
|
{
|
||||||
|
displayName: 'Workspace',
|
||||||
|
name: 'workspace',
|
||||||
|
type: 'options',
|
||||||
|
typeOptions: {
|
||||||
|
loadOptionsMethod: 'getWorkspaces',
|
||||||
|
},
|
||||||
|
options: [],
|
||||||
|
default: '',
|
||||||
|
required: true,
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: [
|
||||||
|
'getAll',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'user',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
description: 'The workspace in which to get users.',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -339,6 +473,7 @@ export class Asana implements INodeType {
|
||||||
throw new Error('No credentials got returned!');
|
throw new Error('No credentials got returned!');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const resource = this.getNodeParameter('resource', 0) as string;
|
||||||
const operation = this.getNodeParameter('operation', 0) as string;
|
const operation = this.getNodeParameter('operation', 0) as string;
|
||||||
|
|
||||||
let endpoint = '';
|
let endpoint = '';
|
||||||
|
@ -351,67 +486,92 @@ export class Asana implements INodeType {
|
||||||
body = {};
|
body = {};
|
||||||
qs = {};
|
qs = {};
|
||||||
|
|
||||||
if (operation === 'createTask') {
|
if (resource === 'task') {
|
||||||
// ----------------------------------
|
if (operation === 'create') {
|
||||||
// createTask
|
// ----------------------------------
|
||||||
// ----------------------------------
|
// create
|
||||||
|
// ----------------------------------
|
||||||
|
|
||||||
requestMethod = 'POST';
|
requestMethod = 'POST';
|
||||||
endpoint = 'tasks';
|
endpoint = 'tasks';
|
||||||
// endpoint = this.getNodeParameter('folderCreate', i) as string;
|
|
||||||
|
|
||||||
body.name = this.getNodeParameter('taskName', 0) as string;
|
body.name = this.getNodeParameter('name', i) as string;
|
||||||
// body.notes = this.getNodeParameter('taskNotes', 0) as string;
|
// body.notes = this.getNodeParameter('taskNotes', 0) as string;
|
||||||
body.workspace = this.getNodeParameter('workspace', 0) as string;
|
body.workspace = this.getNodeParameter('workspace', i) as string;
|
||||||
|
|
||||||
const otherProperties = this.getNodeParameter('otherProperties', i) as IDataObject;
|
const otherProperties = this.getNodeParameter('otherProperties', i) as IDataObject;
|
||||||
Object.assign(body, otherProperties);
|
Object.assign(body, otherProperties);
|
||||||
|
|
||||||
} else if (operation === 'deleteTask') {
|
} else if (operation === 'delete') {
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
// deleteTask
|
// delete
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
|
|
||||||
requestMethod = 'DELETE';
|
requestMethod = 'DELETE';
|
||||||
endpoint = 'tasks/' + this.getNodeParameter('taskId', i) as string;
|
endpoint = 'tasks/' + this.getNodeParameter('id', i) as string;
|
||||||
|
|
||||||
} else if (operation === 'getTask') {
|
} else if (operation === 'get') {
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
// getTask
|
// get
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
|
|
||||||
requestMethod = 'GET';
|
requestMethod = 'GET';
|
||||||
endpoint = 'tasks/' + this.getNodeParameter('taskId', i) as string;
|
endpoint = 'tasks/' + this.getNodeParameter('id', i) as string;
|
||||||
|
|
||||||
} else if (operation === 'updateTask') {
|
} else if (operation === 'update') {
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
// getTask
|
// update
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
|
|
||||||
requestMethod = 'PUT';
|
requestMethod = 'PUT';
|
||||||
endpoint = 'tasks/' + this.getNodeParameter('taskId', i) as string;
|
endpoint = 'tasks/' + this.getNodeParameter('id', i) as string;
|
||||||
|
|
||||||
|
const otherProperties = this.getNodeParameter('otherProperties', i) as IDataObject;
|
||||||
|
Object.assign(body, otherProperties);
|
||||||
|
|
||||||
|
} else if (operation === 'search') {
|
||||||
|
// ----------------------------------
|
||||||
|
// search
|
||||||
|
// ----------------------------------
|
||||||
|
|
||||||
const otherProperties = this.getNodeParameter('otherProperties', i) as IDataObject;
|
const workspaceId = this.getNodeParameter('workspace', i) as string;
|
||||||
Object.assign(body, otherProperties);
|
|
||||||
|
|
||||||
} else if (operation === 'searchForTasks') {
|
requestMethod = 'GET';
|
||||||
// ----------------------------------
|
endpoint = `workspaces/${workspaceId}/tasks/search`;
|
||||||
// searchForTasks
|
|
||||||
// ----------------------------------
|
|
||||||
|
|
||||||
const workspaceId = this.getNodeParameter('workspace', i) as string;
|
const searchTaskProperties = this.getNodeParameter('searchTaskProperties', i) as IDataObject;
|
||||||
|
Object.assign(qs, searchTaskProperties);
|
||||||
|
|
||||||
requestMethod = 'GET';
|
} else {
|
||||||
endpoint = `workspaces/${workspaceId}/tasks/search`;
|
throw new Error(`The operation "${operation}" is not known!`);
|
||||||
|
}
|
||||||
|
} else if (resource === 'user') {
|
||||||
|
if (operation === 'get') {
|
||||||
|
// ----------------------------------
|
||||||
|
// get
|
||||||
|
// ----------------------------------
|
||||||
|
|
||||||
const searchTaskProperties = this.getNodeParameter('searchTaskProperties', i) as IDataObject;
|
const userId = this.getNodeParameter('userId', i) as string;
|
||||||
Object.assign(qs, searchTaskProperties);
|
|
||||||
|
requestMethod = 'GET';
|
||||||
|
endpoint = `users/${userId}`;
|
||||||
|
|
||||||
|
} else if (operation === 'getAll') {
|
||||||
|
// ----------------------------------
|
||||||
|
// getAll
|
||||||
|
// ----------------------------------
|
||||||
|
|
||||||
|
const workspaceId = this.getNodeParameter('workspace', i) as string;
|
||||||
|
|
||||||
|
requestMethod = 'GET';
|
||||||
|
endpoint = `workspaces/${workspaceId}/users`;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
throw new Error(`The operation "${operation}" is not known!`);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`The operation "${operation}" is not known!`);
|
throw new Error(`The resource "${resource}" is not known!`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const responseData = await asanaApiRequest.call(this, requestMethod, endpoint, body);
|
const responseData = await asanaApiRequest.call(this, requestMethod, endpoint, body);
|
||||||
|
|
||||||
returnData.push(responseData.data as IDataObject);
|
returnData.push(responseData.data as IDataObject);
|
||||||
|
|
Loading…
Reference in a new issue