Skip to content

Commit

Permalink
⚡ Add project field when creating a task
Browse files Browse the repository at this point in the history
  • Loading branch information
RicardoE105 committed Jan 29, 2021
1 parent 48362f5 commit e1b08ce
Show file tree
Hide file tree
Showing 2 changed files with 215 additions and 4 deletions.
211 changes: 211 additions & 0 deletions packages/nodes-base/nodes/Asana/Asana.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ export class Asana implements INodeType {
name: 'Task Tag',
value: 'taskTag',
},
{
name: 'Task Project',
value: 'taskProject',
},
{
name: 'User',
value: 'user',
Expand Down Expand Up @@ -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.',
},
],
},

Expand Down Expand Up @@ -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
// ----------------------------------
Expand Down Expand Up @@ -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') {
// ----------------------------------
Expand Down
8 changes: 4 additions & 4 deletions packages/nodes-base/nodes/Asana/GenericFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [];

Expand All @@ -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
Expand All @@ -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;
Expand Down

0 comments on commit e1b08ce

Please sign in to comment.