Add task:update - Todoist (#2409)

*  Add task:update

*  Minor improvements

Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
This commit is contained in:
Ricardo Espinoza 2021-11-04 22:21:35 -04:00 committed by GitHub
parent f6dae26532
commit e84846dcf9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 121 additions and 9 deletions

View file

@ -44,7 +44,6 @@ export async function todoistApiRequest(
//@ts-ignore
options.headers['Authorization'] = `Bearer ${credentials.apiKey}`;
return this.helpers.request!(options);
} else {
//@ts-ignore

View file

@ -16,7 +16,7 @@ import {
} from './GenericFunctions';
interface IBodyCreateTask {
content: string;
content?: string;
description?: string;
project_id?: number;
section_id?: number;
@ -146,6 +146,11 @@ export class Todoist implements INodeType {
value: 'reopen',
description: 'Reopen a task',
},
{
name: 'Update',
value: 'update',
description: 'Update a task',
},
],
default: 'create',
description: 'The operation to perform.',
@ -228,6 +233,7 @@ export class Todoist implements INodeType {
'close',
'get',
'reopen',
'update',
],
},
},
@ -398,6 +404,76 @@ export class Todoist implements INodeType {
},
],
},
{
displayName: 'Update Fields',
name: 'updateFields',
type: 'collection',
placeholder: 'Add Field',
default: {},
displayOptions: {
show: {
resource: [
'task',
],
operation: [
'update',
],
},
},
options: [
{
displayName: 'Content',
name: 'content',
type: 'string',
default: '',
description: 'Task content',
},
{
displayName: 'Description',
name: 'description',
type: 'string',
default: '',
description: 'A description for the task.',
},
{
displayName: 'Due Date Time',
name: 'dueDateTime',
type: 'dateTime',
default: '',
description: 'Specific date and time in RFC3339 format in UTC.',
},
{
displayName: 'Due String',
name: 'dueString',
type: 'string',
default: '',
description: 'Human defined task due date (ex.: “next Monday”, “Tomorrow”). Value is set using local (not UTC) time.',
},
{
displayName: 'Labels',
name: 'labels',
type: 'multiOptions',
typeOptions: {
loadOptionsMethod: 'getLabels',
},
default: [],
required: false,
description: 'Labels',
},
{
displayName: 'Priority',
name: 'priority',
type: 'number',
typeOptions: {
numberStepSize: 1,
maxValue: 4,
minValue: 1,
},
default: 1,
description: 'Task priority from 1 (normal) to 4 (urgent).',
},
],
},
],
};
@ -573,6 +649,43 @@ export class Todoist implements INodeType {
responseData = { success: true };
}
if (operation === 'update') {
//https://developer.todoist.com/rest/v1/#update-a-task
const id = this.getNodeParameter('taskId', i) as string;
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
const body: IBodyCreateTask = {};
if (updateFields.content) {
body.content = updateFields.content as string;
}
if (updateFields.priority) {
body.priority = parseInt(updateFields.priority as string, 10);
}
if (updateFields.description) {
body.description = updateFields.description as string;
}
if (updateFields.dueDateTime) {
body.due_datetime = updateFields.dueDateTime as string;
}
if (updateFields.dueString) {
body.due_string = updateFields.dueString as string;
}
if (updateFields.labels !== undefined &&
Array.isArray(updateFields.labels) &&
updateFields.labels.length !== 0) {
body.label_ids = updateFields.labels as number[];
}
await todoistApiRequest.call(this, 'POST', `/tasks/${id}`, body);
responseData = { success: true };
}
}
if (Array.isArray(responseData)) {
returnData.push.apply(returnData, responseData as IDataObject[]);