mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-28 10:32:27 +08:00
feat(tasks): create backend model for task
This commit is contained in:
parent
50d37bbcb1
commit
c0e42e23a6
@ -11,9 +11,10 @@ import BOption from "./entities/boption.js";
|
|||||||
import BEtapiToken from "./entities/betapi_token.js";
|
import BEtapiToken from "./entities/betapi_token.js";
|
||||||
import cls from "../services/cls.js";
|
import cls from "../services/cls.js";
|
||||||
import entityConstructor from "../becca/entity_constructor.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 type AbstractBeccaEntity from "./entities/abstract_becca_entity.js";
|
||||||
import ws from "../services/ws.js";
|
import ws from "../services/ws.js";
|
||||||
|
import BTask from "./entities/btask.js";
|
||||||
|
|
||||||
const beccaLoaded = new Promise<void>(async (res, rej) => {
|
const beccaLoaded = new Promise<void>(async (res, rej) => {
|
||||||
const sqlInit = (await import("../services/sql_init.js")).default;
|
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`)) {
|
for (const row of sql.getRows<EtapiTokenRow>(`SELECT etapiTokenId, name, tokenHash, utcDateCreated, utcDateModified FROM etapi_tokens WHERE isDeleted = 0`)) {
|
||||||
new BEtapiToken(row);
|
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) {
|
for (const noteId in becca.notes) {
|
||||||
|
58
src/becca/entities/btask.ts
Normal file
58
src/becca/entities/btask.ts
Normal file
@ -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
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -136,3 +136,12 @@ export interface NoteRow {
|
|||||||
utcDateModified: string;
|
utcDateModified: string;
|
||||||
content?: string | Buffer;
|
content?: string | Buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface TaskRow {
|
||||||
|
taskId: string;
|
||||||
|
parentNoteId: string;
|
||||||
|
title: string;
|
||||||
|
dueDate?: string;
|
||||||
|
isDone: boolean;
|
||||||
|
isDeleted: boolean;
|
||||||
|
}
|
||||||
|
@ -9,6 +9,7 @@ import BNote from "./entities/bnote.js";
|
|||||||
import BOption from "./entities/boption.js";
|
import BOption from "./entities/boption.js";
|
||||||
import BRecentNote from "./entities/brecent_note.js";
|
import BRecentNote from "./entities/brecent_note.js";
|
||||||
import BRevision from "./entities/brevision.js";
|
import BRevision from "./entities/brevision.js";
|
||||||
|
import BTask from "./entities/btask.js";
|
||||||
|
|
||||||
type EntityClass = new (row?: any) => AbstractBeccaEntity<any>;
|
type EntityClass = new (row?: any) => AbstractBeccaEntity<any>;
|
||||||
|
|
||||||
@ -21,7 +22,8 @@ const ENTITY_NAME_TO_ENTITY: Record<string, ConstructorData<any> & EntityClass>
|
|||||||
notes: BNote,
|
notes: BNote,
|
||||||
options: BOption,
|
options: BOption,
|
||||||
recent_notes: BRecentNote,
|
recent_notes: BRecentNote,
|
||||||
revisions: BRevision
|
revisions: BRevision,
|
||||||
|
tasks: BTask
|
||||||
};
|
};
|
||||||
|
|
||||||
function getEntityFromEntityName(entityName: keyof typeof ENTITY_NAME_TO_ENTITY) {
|
function getEntityFromEntityName(entityName: keyof typeof ENTITY_NAME_TO_ENTITY) {
|
||||||
|
@ -888,7 +888,7 @@ class ConsistencyChecks {
|
|||||||
return `${tableName}: ${count}`;
|
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(", ")}`);
|
log.info(`Table counts: ${tables.map((tableName) => getTableRowCount(tableName)).join(", ")}`);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user