Skip to content

Build your personal knowledge base with Trilium Notes

feat(tasks): create backend model for task

Elian Doranc0e42e23a692
diff --git a/src/becca/becca_loader.ts b/src/becca/becca_loader.ts
index 8397b2dec7..862e3e8be6 100644
--- a/src/becca/becca_loader.ts
+++ b/src/becca/becca_loader.ts
@@ -11,9 +11,10 @@ import BOption from "./entities/boption.js";
import BEtapiToken from "./entities/betapi_token.js";
import cls from "../services/cls.js";
import entityConstructor from "../becca/entity_constructor.js";
-import type { AttributeRow, BranchRow, EtapiTokenRow, NoteRow, OptionRow } from "./entities/rows.js";
+import type { AttributeRow, BranchRow, EtapiTokenRow, NoteRow, OptionRow, TaskRow } from "./entities/rows.js";
import type AbstractBeccaEntity from "./entities/abstract_becca_entity.js";
import ws from "../services/ws.js";
+import BTask from "./entities/btask.js";
const beccaLoaded = new Promise<void>(async (res, rej) => {
const sqlInit = (await import("../services/sql_init.js")).default;
@@ -63,6 +64,10 @@ function load() {
for (const row of sql.getRows<EtapiTokenRow>(`SELECT etapiTokenId, name, tokenHash, utcDateCreated, utcDateModified FROM etapi_tokens WHERE isDeleted = 0`)) {
new BEtapiToken(row);
}
+
+ for (const row of sql.getRows<TaskRow>(`SELECT taskId, parentNoteId, title, dueDate, isDone, isDeleted FROM tasks WHERE isDeleted = 0`)) {
+ new BTask(row);
+ }
});
for (const noteId in becca.notes) {
diff --git a/src/becca/entities/btask.ts b/src/becca/entities/btask.ts
new file mode 100644
index 0000000000..a0c8ce2322
--- /dev/null
+++ b/src/becca/entities/btask.ts
@@ -0,0 +1,58 @@
+import AbstractBeccaEntity from "./abstract_becca_entity.js";
+import type BOption from "./boption.js";
+import type { TaskRow } from "./rows.js";
+
+export default class BTask extends AbstractBeccaEntity<BOption> {
+
+ static get entityName() {
+ return "tasks";
+ }
+
+ static get primaryKeyName() {
+ return "taskId";
+ }
+
+ static get hashedProperties() {
+ return [ "taskId", "parentNoteId", "title", "dueDate", "isDone", "isDeleted" ];
+ }
+
+ taskId!: string;
+ parentNoteId!: string;
+ title!: string;
+ dueDate?: string;
+ isDone!: boolean;
+ private _isDeleted?: boolean;
+
+ constructor(row?: TaskRow) {
+ super();
+
+ if (!row) {
+ return;
+ }
+
+ this.updateFromRow(row);
+ }
+
+ get isDeleted() {
+ return !!this._isDeleted;
+ }
+
+ updateFromRow(row: TaskRow) {
+ this.taskId = row.taskId;
+ this.parentNoteId = row.parentNoteId;
+ this.title = row.title;
+ this.dueDate = row.dueDate;
+ this._isDeleted = !!row.isDeleted;
+ }
+
+ getPojo() {
+ return {
+ taskId: this.taskId,
+ parentNoteId: this.parentNoteId,
+ title: this.title,
+ dueDate: this.dueDate,
+ isDeleted: this.isDeleted
+ };
+ }
+
+}
diff --git a/src/becca/entities/rows.ts b/src/becca/entities/rows.ts
index 89fa369538..08a296c7a7 100644
--- a/src/becca/entities/rows.ts
+++ b/src/becca/entities/rows.ts
@@ -136,3 +136,12 @@ export interface NoteRow {
utcDateModified: string;
content?: string | Buffer;
}
+
+export interface TaskRow {
+ taskId: string;
+ parentNoteId: string;
+ title: string;
+ dueDate?: string;
+ isDone: boolean;
+ isDeleted: boolean;
+}
diff --git a/src/becca/entity_constructor.ts b/src/becca/entity_constructor.ts
index 18f7a14c7e..5e9d3e0133 100644
--- a/src/becca/entity_constructor.ts
+++ b/src/becca/entity_constructor.ts
@@ -9,6 +9,7 @@ import BNote from "./entities/bnote.js";
import BOption from "./entities/boption.js";
import BRecentNote from "./entities/brecent_note.js";
import BRevision from "./entities/brevision.js";
+import BTask from "./entities/btask.js";
type EntityClass = new (row?: any) => AbstractBeccaEntity<any>;
@@ -21,7 +22,8 @@ const ENTITY_NAME_TO_ENTITY: Record<string, ConstructorData<any> & EntityClass>
notes: BNote,
options: BOption,
recent_notes: BRecentNote,
- revisions: BRevision
+ revisions: BRevision,
+ tasks: BTask
};
function getEntityFromEntityName(entityName: keyof typeof ENTITY_NAME_TO_ENTITY) {
diff --git a/src/services/consistency_checks.ts b/src/services/consistency_checks.ts
index 8e7da9c9ed..ae678f8078 100644
--- a/src/services/consistency_checks.ts
+++ b/src/services/consistency_checks.ts
@@ -888,7 +888,7 @@ class ConsistencyChecks {
return `${tableName}: ${count}`;
}
- const tables = ["notes", "revisions", "attachments", "branches", "attributes", "etapi_tokens", "blobs"];
+ const tables = ["notes", "revisions", "attachments", "branches", "attributes", "etapi_tokens", "blobs", "tasks"];
log.info(`Table counts: ${tables.map((tableName) => getTableRowCount(tableName)).join(", ")}`);
}