Skip to content

Build your personal knowledge base with Trilium Notes

feat(tasks): add POST API

Elian Doran17f9fa7e895d
diff --git a/src/becca/entities/btask.ts b/src/becca/entities/btask.ts
index d84d09e7e5..64ae3d9547 100644
--- a/src/becca/entities/btask.ts
+++ b/src/becca/entities/btask.ts
@@ -16,7 +16,7 @@ export default class BTask extends AbstractBeccaEntity<BOption> {
return [ "taskId", "parentNoteId", "title", "dueDate", "isDone", "isDeleted" ];
}
- taskId!: string;
+ taskId?: string;
parentNoteId!: string;
title!: string;
dueDate?: string;
@@ -43,6 +43,7 @@ export default class BTask extends AbstractBeccaEntity<BOption> {
this.parentNoteId = row.parentNoteId;
this.title = row.title;
this.dueDate = row.dueDate;
+ this.isDone = !!row.isDeleted;
this._isDeleted = !!row.isDeleted;
if (this.taskId) {
diff --git a/src/becca/entities/rows.ts b/src/becca/entities/rows.ts
index 08a296c7a7..c9e67de563 100644
--- a/src/becca/entities/rows.ts
+++ b/src/becca/entities/rows.ts
@@ -138,10 +138,10 @@ export interface NoteRow {
}
export interface TaskRow {
- taskId: string;
+ taskId?: string;
parentNoteId: string;
title: string;
dueDate?: string;
- isDone: boolean;
- isDeleted: boolean;
+ isDone?: boolean;
+ isDeleted?: boolean;
}
diff --git a/src/routes/api/tasks.ts b/src/routes/api/tasks.ts
index ac4d0a5b8b..33516ef28f 100644
--- a/src/routes/api/tasks.ts
+++ b/src/routes/api/tasks.ts
@@ -1,5 +1,10 @@
+import type { Request } from "express";
import * as tasksService from "../../services/tasks.js";
export function getTasks() {
return tasksService.getTasks();
}
+
+export function createNewTask(req: Request) {
+ return tasksService.createNewTask(req.body);
+}
diff --git a/src/routes/routes.ts b/src/routes/routes.ts
index 8eaa1f96bb..6cff1e0330 100644
--- a/src/routes/routes.ts
+++ b/src/routes/routes.ts
@@ -281,6 +281,7 @@ function register(app: express.Application) {
apiRoute(DEL, "/api/etapi-tokens/:etapiTokenId", etapiTokensApiRoutes.deleteToken);
apiRoute(GET, "/api/tasks", tasksRoute.getTasks);
+ apiRoute(PST, "/api/tasks", tasksRoute.createNewTask);
// in case of local electron, local calls are allowed unauthenticated, for server they need auth
const clipperMiddleware = isElectron ? [] : [auth.checkEtapiToken];
diff --git a/src/services/tasks.ts b/src/services/tasks.ts
index 58fa6d8bb1..6a2f937100 100644
--- a/src/services/tasks.ts
+++ b/src/services/tasks.ts
@@ -1,5 +1,21 @@
import becca from "../becca/becca.js";
+import BTask from "../becca/entities/btask.js";
export function getTasks() {
return becca.getTasks();
}
+
+interface CreateTaskParams {
+ parentNoteId: string;
+ title: string;
+ dueDate?: string;
+}
+
+export function createNewTask(params: CreateTaskParams) {
+ const task = new BTask(params);
+ task.save();
+
+ return {
+ task
+ }
+}