mirror of
https://github.com/n8n-io/n8n.git
synced 2024-09-20 23:07:32 -07:00
⚡ Add project field when creating a task on Asana Node (#1386)
This commit is contained in:
parent
46fe96b72c
commit
05df13a887
|
@ -106,6 +106,10 @@ export class Asana implements INodeType {
|
||||||
name: 'Task Tag',
|
name: 'Task Tag',
|
||||||
value: 'taskTag',
|
value: 'taskTag',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'Task Project',
|
||||||
|
value: 'taskProject',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'User',
|
name: 'User',
|
||||||
value: 'user',
|
value: 'user',
|
||||||
|
@ -921,6 +925,16 @@ export class Asana implements INodeType {
|
||||||
default: '',
|
default: '',
|
||||||
description: 'The task notes',
|
description: 'The task notes',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Project IDs',
|
||||||
|
name: 'projects',
|
||||||
|
type: 'multiOptions',
|
||||||
|
typeOptions: {
|
||||||
|
loadOptionsMethod: 'getProjects',
|
||||||
|
},
|
||||||
|
default: [],
|
||||||
|
description: 'The project to filter tasks on.',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -1093,6 +1107,161 @@ export class Asana implements INodeType {
|
||||||
description: 'The ID of the comment to be removed',
|
description: 'The ID of the comment to be removed',
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// ----------------------------------
|
||||||
|
// taskProject
|
||||||
|
// ----------------------------------
|
||||||
|
{
|
||||||
|
displayName: 'Operation',
|
||||||
|
name: 'operation',
|
||||||
|
type: 'options',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'taskProject',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'Add',
|
||||||
|
value: 'add',
|
||||||
|
description: 'Add a task to a project',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Remove',
|
||||||
|
value: 'remove',
|
||||||
|
description: 'Remove a task from a project',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
default: 'add',
|
||||||
|
description: 'The operation to perform.',
|
||||||
|
},
|
||||||
|
// ----------------------------------
|
||||||
|
// taskProject:add
|
||||||
|
// ----------------------------------
|
||||||
|
{
|
||||||
|
displayName: 'Task ID',
|
||||||
|
name: 'id',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
required: true,
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: [
|
||||||
|
'add',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'taskProject',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
description: 'The ID of the task to add the project to',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Project ID',
|
||||||
|
name: 'project',
|
||||||
|
type: 'options',
|
||||||
|
typeOptions: {
|
||||||
|
loadOptionsMethod: 'getProjects',
|
||||||
|
},
|
||||||
|
default: '',
|
||||||
|
required: true,
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: [
|
||||||
|
'add',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'taskProject',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
description: 'The project where the task will be added',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Additional Fields',
|
||||||
|
name: 'additionalFields',
|
||||||
|
type: 'collection',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'taskProject',
|
||||||
|
],
|
||||||
|
operation: [
|
||||||
|
'add',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
default: {},
|
||||||
|
description: 'Other properties to set',
|
||||||
|
placeholder: 'Add Field',
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
displayName: 'Insert After',
|
||||||
|
name: 'insert_after',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
description: 'A task in the project to insert the task after, or null to insert at the beginning of the list.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Insert Before',
|
||||||
|
name: 'insert_before',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
description: 'A task in the project to insert the task before, or null to insert at the end of the list.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Section',
|
||||||
|
name: 'section',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
description: 'A section in the project to insert the task into. The task will be inserted at the bottom of the section.',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
|
||||||
|
// ----------------------------------
|
||||||
|
// taskProject:remove
|
||||||
|
// ----------------------------------
|
||||||
|
{
|
||||||
|
displayName: 'Task ID',
|
||||||
|
name: 'id',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
required: true,
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: [
|
||||||
|
'remove',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'taskProject',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
description: 'The ID of the task to add the project to',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Project ID',
|
||||||
|
name: 'project',
|
||||||
|
type: 'options',
|
||||||
|
typeOptions: {
|
||||||
|
loadOptionsMethod: 'getProjects',
|
||||||
|
},
|
||||||
|
default: '',
|
||||||
|
required: true,
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: [
|
||||||
|
'remove',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'taskProject',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
description: 'The project where the task will be removed from',
|
||||||
|
},
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
// taskTag
|
// taskTag
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
|
@ -1952,7 +2121,49 @@ export class Asana implements INodeType {
|
||||||
responseData = { success: true };
|
responseData = { success: true };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (resource === 'taskProject') {
|
||||||
|
if (operation === 'add') {
|
||||||
|
|
||||||
|
// ----------------------------------
|
||||||
|
// taskProject:add
|
||||||
|
// ----------------------------------
|
||||||
|
|
||||||
|
const taskId = this.getNodeParameter('id', i) as string;
|
||||||
|
|
||||||
|
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||||
|
|
||||||
|
requestMethod = 'POST';
|
||||||
|
|
||||||
|
endpoint = `/tasks/${taskId}/addProject`;
|
||||||
|
|
||||||
|
body.project = this.getNodeParameter('project', i) as string;
|
||||||
|
|
||||||
|
Object.assign(body, additionalFields);
|
||||||
|
|
||||||
|
responseData = await asanaApiRequest.call(this, requestMethod, endpoint, body, qs);
|
||||||
|
|
||||||
|
responseData = { success: true };
|
||||||
|
}
|
||||||
|
|
||||||
|
if (operation === 'remove') {
|
||||||
|
|
||||||
|
// ----------------------------------
|
||||||
|
// taskProject:remove
|
||||||
|
// ----------------------------------
|
||||||
|
|
||||||
|
const taskId = this.getNodeParameter('id', i) as string;
|
||||||
|
|
||||||
|
requestMethod = 'POST';
|
||||||
|
|
||||||
|
endpoint = `/tasks/${taskId}/removeProject`;
|
||||||
|
|
||||||
|
body.project = this.getNodeParameter('project', i) as string;
|
||||||
|
|
||||||
|
responseData = await asanaApiRequest.call(this, requestMethod, endpoint, body, qs);
|
||||||
|
|
||||||
|
responseData = { success: true };
|
||||||
|
}
|
||||||
|
}
|
||||||
if (resource === 'user') {
|
if (resource === 'user') {
|
||||||
if (operation === 'get') {
|
if (operation === 'get') {
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
|
|
|
@ -76,7 +76,7 @@ export async function asanaApiRequest(this: IHookFunctions | IExecuteFunctions |
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function asanaApiRequestAllItems(this: IExecuteFunctions | ILoadOptionsFunctions ,method: string, endpoint: string, body: any = {}, query: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
export async function asanaApiRequestAllItems(this: IExecuteFunctions | ILoadOptionsFunctions, method: string, endpoint: string, body: any = {}, query: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
||||||
|
|
||||||
const returnData: IDataObject[] = [];
|
const returnData: IDataObject[] = [];
|
||||||
|
|
||||||
|
@ -95,12 +95,12 @@ export async function asanaApiRequestAllItems(this: IExecuteFunctions | ILoadOpt
|
||||||
return returnData;
|
return returnData;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getWorkspaces(this: ILoadOptionsFunctions): Promise < INodePropertyOptions[] > {
|
export async function getWorkspaces(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||||
const endpoint = '/workspaces';
|
const endpoint = '/workspaces';
|
||||||
const responseData = await asanaApiRequestAllItems.call(this, 'GET', endpoint, {});
|
const responseData = await asanaApiRequestAllItems.call(this, 'GET', endpoint, {});
|
||||||
|
|
||||||
const returnData: INodePropertyOptions[] = [];
|
const returnData: INodePropertyOptions[] = [];
|
||||||
for(const workspaceData of responseData) {
|
for (const workspaceData of responseData) {
|
||||||
if (workspaceData.resource_type !== 'workspace') {
|
if (workspaceData.resource_type !== 'workspace') {
|
||||||
// Not sure if for some reason also ever other resources
|
// Not sure if for some reason also ever other resources
|
||||||
// get returned but just in case filter them out
|
// get returned but just in case filter them out
|
||||||
|
@ -113,7 +113,7 @@ export async function getWorkspaces(this: ILoadOptionsFunctions): Promise < INod
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
returnData.sort((a, b) => {
|
returnData.sort((a, b) => {
|
||||||
if (a.name < b.name) { return -1; }
|
if (a.name < b.name) { return -1; }
|
||||||
if (a.name > b.name) { return 1; }
|
if (a.name > b.name) { return 1; }
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in a new issue