Add project field when creating a task on Asana Node (#1386)

This commit is contained in:
Ricardo Espinoza 2021-01-30 12:34:49 -05:00 committed by GitHub
parent 46fe96b72c
commit 05df13a887
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 215 additions and 4 deletions

View file

@ -106,6 +106,10 @@ export class Asana implements INodeType {
name: 'Task Tag',
value: 'taskTag',
},
{
name: 'Task Project',
value: 'taskProject',
},
{
name: 'User',
value: 'user',
@ -921,6 +925,16 @@ export class Asana implements INodeType {
default: '',
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',
},
// ----------------------------------
// 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
// ----------------------------------
@ -1952,7 +2121,49 @@ export class Asana implements INodeType {
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 (operation === 'get') {
// ----------------------------------

View file

@ -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[] = [];
@ -95,12 +95,12 @@ export async function asanaApiRequestAllItems(this: IExecuteFunctions | ILoadOpt
return returnData;
}
export async function getWorkspaces(this: ILoadOptionsFunctions): Promise < INodePropertyOptions[] > {
export async function getWorkspaces(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const endpoint = '/workspaces';
const responseData = await asanaApiRequestAllItems.call(this, 'GET', endpoint, {});
const returnData: INodePropertyOptions[] = [];
for(const workspaceData of responseData) {
for (const workspaceData of responseData) {
if (workspaceData.resource_type !== 'workspace') {
// Not sure if for some reason also ever other resources
// 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; }
return 0;