64 lines
2.2 KiB
JavaScript
64 lines
2.2 KiB
JavaScript
import { fetchTodoistTasks, closeTodoistTask, deleteTodoistTask } from './todoist.js';
|
|
import { fetchTickTickTasks, closeTickTickTask, deleteTickTickTask } from './ticktick.js';
|
|
import { fetchNotionTasks, archiveNotionTask, deleteNotionTask } from './notion.js';
|
|
export async function fetchAllTasks(providers) {
|
|
const all = [];
|
|
const errors = [];
|
|
if (providers.todoist.enabled && providers.todoist.token) {
|
|
try {
|
|
const tasks = await fetchTodoistTasks(providers.todoist);
|
|
all.push(...tasks);
|
|
}
|
|
catch (e) {
|
|
errors.push(`Todoist: ${e.message}`);
|
|
}
|
|
}
|
|
if (providers.ticktick.enabled && providers.ticktick.token) {
|
|
try {
|
|
const tasks = await fetchTickTickTasks(providers.ticktick);
|
|
all.push(...tasks);
|
|
}
|
|
catch (e) {
|
|
errors.push(`TickTick: ${e.message}`);
|
|
}
|
|
}
|
|
if (providers.notion.enabled && providers.notion.token) {
|
|
try {
|
|
const tasks = await fetchNotionTasks(providers.notion);
|
|
all.push(...tasks);
|
|
}
|
|
catch (e) {
|
|
errors.push(`Notion: ${e.message}`);
|
|
}
|
|
}
|
|
if (errors.length > 0 && all.length === 0) {
|
|
throw new Error(errors.join('; '));
|
|
}
|
|
return all;
|
|
}
|
|
export async function completeTask(task, token) {
|
|
if (task.source === 'todoist')
|
|
await closeTodoistTask(task.id, token);
|
|
else if (task.source === 'ticktick')
|
|
await closeTickTickTask(task.id, token);
|
|
else if (task.source === 'notion')
|
|
await archiveNotionTask(task.id, token);
|
|
}
|
|
export async function deleteTask(task, token) {
|
|
if (task.source === 'todoist')
|
|
await deleteTodoistTask(task.id, token);
|
|
else if (task.source === 'ticktick')
|
|
await deleteTickTickTask(task.id, token);
|
|
else if (task.source === 'notion')
|
|
await deleteNotionTask(task.id, token);
|
|
}
|
|
export function getTokenForSource(source, providers) {
|
|
if (source === 'todoist')
|
|
return providers.todoist.token;
|
|
if (source === 'ticktick')
|
|
return providers.ticktick.token;
|
|
if (source === 'notion')
|
|
return providers.notion.token;
|
|
return '';
|
|
}
|