fix(Todoist Node): Make Section Name optional in Move Task operation (#10732)

This commit is contained in:
aya 2024-09-25 17:29:44 +03:00 committed by GitHub
parent af9e227ad4
commit 799006a3cc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 68 additions and 6 deletions

View file

@ -11,7 +11,7 @@ export class Todoist extends VersionedNodeType {
name: 'todoist',
icon: 'file:todoist.svg',
group: ['output'],
defaultVersion: 2,
defaultVersion: 2.1,
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
description: 'Consume Todoist API',
};
@ -19,6 +19,7 @@ export class Todoist extends VersionedNodeType {
const nodeVersions: IVersionedNodeType['nodeVersions'] = {
1: new TodoistV1(baseDescription),
2: new TodoistV2(baseDescription),
2.1: new TodoistV2(baseDescription),
};
super(nodeVersions, baseDescription);

View file

@ -34,6 +34,7 @@ export interface Command {
uuid: string;
temp_id?: string;
args: {
parent_id?: string;
id?: number;
section_id?: number;
project_id?: number | string;
@ -251,7 +252,10 @@ export class MoveHandler implements OperationHandler {
async handleOperation(ctx: Context, itemIndex: number): Promise<TodoistResponse> {
//https://api.todoist.com/sync/v9/sync
const taskId = ctx.getNodeParameter('taskId', itemIndex) as number;
const section = ctx.getNodeParameter('section', itemIndex) as number;
const projectId = ctx.getNodeParameter('project', itemIndex, undefined, {
extractValue: true,
}) as number;
const nodeVersion = ctx.getNode().typeVersion;
const body: SyncRequest = {
commands: [
@ -260,14 +264,28 @@ export class MoveHandler implements OperationHandler {
uuid: uuid(),
args: {
id: taskId,
section_id: section,
// Set section_id only if node version is below 2.1
...(nodeVersion < 2.1
? { section_id: ctx.getNodeParameter('section', itemIndex) as number }
: {}),
},
},
],
};
await todoistSyncRequest.call(ctx, body);
if (nodeVersion >= 2.1) {
const options = ctx.getNodeParameter('options', itemIndex, {}) as IDataObject;
// Only one of parent_id, section_id, or project_id must be set to move the task
if (options.parent) {
body.commands[0].args.parent_id = options.parent as string;
} else if (options.section) {
body.commands[0].args.section_id = options.section as number;
} else {
body.commands[0].args.project_id = projectId;
}
}
await todoistSyncRequest.call(ctx, body);
return { success: true };
}
}

View file

@ -36,7 +36,7 @@ const versionDescription: INodeTypeDescription = {
name: 'todoist',
icon: 'file:todoist.svg',
group: ['output'],
version: 2,
version: [2, 2.1],
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
description: 'Consume Todoist API',
defaults: {
@ -207,7 +207,7 @@ const versionDescription: INodeTypeDescription = {
operation: ['create', 'move', 'sync'],
},
},
description: 'The project you want to operate on. Choose from the list, or specify an ID.',
description: 'The destination project. Choose from the list, or specify an ID.',
},
{
displayName: 'Section Name or ID',
@ -222,11 +222,54 @@ const versionDescription: INodeTypeDescription = {
resource: ['task'],
operation: ['move'],
},
hide: {
'@version': [{ _cnd: { gte: 2.1 } }],
},
},
default: '',
description:
'Section to which you want move the task. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
},
{
displayName: 'Additional Fields',
name: 'options',
type: 'collection',
placeholder: 'Add option',
default: {},
displayOptions: {
show: {
resource: ['task'],
operation: ['move'],
'@version': [{ _cnd: { gte: 2.1 } }],
},
},
options: [
{
displayName: 'Section Name or ID',
name: 'section',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getSections',
loadOptionsDependsOn: ['project', 'options.parent'],
},
default: '',
description:
'The destination section. The task becomes the last root task of the section. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
},
{
displayName: 'Parent Name or ID',
name: 'parent',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getItems',
loadOptionsDependsOn: ['project', 'options.section'],
},
default: '',
description:
'The destination parent task. The task becomes the last child task of the parent task. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
},
],
},
{
displayName: 'Label Names or IDs',
name: 'labels',