Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/ticktick.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ async function handleTasks() {
process.exit(1);
}
return await tasks.update(args.positional[0], {
projectId: args.options.project,
title: args.options.title,
content: args.options.content,
dueDate: args.options.due,
Expand Down
16 changes: 11 additions & 5 deletions lib/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ export async function update(taskId, options = {}, deps = {}) {
parseReminder = coreFunctions.parseReminder,
parsePriority = coreFunctions.parsePriority,
} = deps;
const resolvedTaskId = await resolveTaskId(taskId, null, deps);
const projectId = options.projectId || null;
const resolvedTaskId = await resolveTaskId(taskId, projectId, deps);
const input = { id: resolvedTaskId };

if (options.title) input.title = options.title;
Expand All @@ -145,16 +146,21 @@ export async function update(taskId, options = {}, deps = {}) {
}

const task = await apiRequest('POST', `/task/${encodeURIComponent(resolvedTaskId)}`, input, deps);
// API returns 204 No Content on success, re-fetch if we need details
return {
success: true,
task: {
task: task ? {
id: shortId(task.id),
fullId: task.id,
projectId: shortId(task.projectId),
title: task.title,
dueDate: task.dueDate,
priority: formatPriority(task.priority),
tags: task.tags || [],
} : {
id: shortId(resolvedTaskId),
fullId: resolvedTaskId,
title: input.title || '(updated)',
},
};
}
Expand Down Expand Up @@ -466,7 +472,7 @@ async function resolveTaskId(taskId, projectId = null, deps = {}) {
// Search within specific project
try {
const data = await apiRequest('GET', `/project/${encodeURIComponent(projectId)}/data`, undefined, deps);
const match = data.tasks.find((t) => t.id.startsWith(taskId));
const match = (data && data.tasks || []).find((t) => t && t.id && t.id.startsWith(taskId));
if (match) {
return match.id;
}
Expand All @@ -478,10 +484,10 @@ async function resolveTaskId(taskId, projectId = null, deps = {}) {
// Search all projects
const projects = await apiRequest('GET', '/project', undefined, deps);

for (const project of projects) {
for (const project of (projects || [])) {
try {
const data = await apiRequest('GET', `/project/${encodeURIComponent(project.id)}/data`, undefined, deps);
const match = data.tasks.find((t) => t.id.startsWith(taskId));
const match = (data && data.tasks || []).find((t) => t && t.id && t.id.startsWith(taskId));
if (match) {
return match.id;
}
Expand Down
8 changes: 4 additions & 4 deletions test/tasks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ describe('tasks.due', () => {
return {};
});

const result = await tasks.due(7, makeDeps(mockApiRequest));
const result = await tasks.due(7, {}, makeDeps(mockApiRequest));

assert.equal(result.days, 7);
// Should include tomorrow and next week, but not next month, no due date, or completed
Expand Down Expand Up @@ -528,7 +528,7 @@ describe('tasks.due', () => {
return {};
});

const result = await tasks.due(7, makeDeps(mockApiRequest));
const result = await tasks.due(7, {}, makeDeps(mockApiRequest));

assert.equal(result.tasks[0].title, 'Day 1');
assert.equal(result.tasks[1].title, 'Day 2');
Expand All @@ -543,7 +543,7 @@ describe('tasks.due', () => {
return {};
});

const result = await tasks.due(undefined, makeDeps(mockApiRequest));
const result = await tasks.due(undefined, {}, makeDeps(mockApiRequest));

assert.equal(result.days, 7);
});
Expand All @@ -567,7 +567,7 @@ describe('tasks.due', () => {
return {};
});

const result = await tasks.due(7, makeDeps(mockApiRequest));
const result = await tasks.due(7, {}, makeDeps(mockApiRequest));

// Overdue tasks should be included - they're the most urgent
assert.equal(result.count, 2);
Expand Down