feat(tasks): add GET API

This commit is contained in:
Elian Doran 2025-02-18 19:06:02 +02:00
parent c0e42e23a6
commit 98dff61305
No known key found for this signature in database
5 changed files with 31 additions and 0 deletions

View File

@ -12,6 +12,7 @@ import type { AttachmentRow, BlobRow, RevisionRow } from "./entities/rows.js";
import BBlob from "./entities/bblob.js";
import BRecentNote from "./entities/brecent_note.js";
import type AbstractBeccaEntity from "./entities/abstract_becca_entity.js";
import type BTask from "./entities/btask.js";
interface AttachmentOpts {
includeContentLength?: boolean;
@ -32,6 +33,7 @@ export default class Becca {
attributeIndex!: Record<string, BAttribute[]>;
options!: Record<string, BOption>;
etapiTokens!: Record<string, BEtapiToken>;
tasks!: Record<string, BTask>;
allNoteSetCache: NoteSet | null;
@ -48,6 +50,7 @@ export default class Becca {
this.attributeIndex = {};
this.options = {};
this.etapiTokens = {};
this.tasks = {};
this.dirtyNoteSetCache();
@ -213,6 +216,10 @@ export default class Becca {
return this.etapiTokens[etapiTokenId];
}
getTasks(): BTask[] {
return Object.values(this.tasks);
}
getEntity<T extends AbstractBeccaEntity<T>>(entityName: string, entityId: string): AbstractBeccaEntity<T> | null {
if (!entityName || !entityId) {
return null;

View File

@ -31,6 +31,7 @@ export default class BTask extends AbstractBeccaEntity<BOption> {
}
this.updateFromRow(row);
this.init();
}
get isDeleted() {
@ -43,6 +44,16 @@ export default class BTask extends AbstractBeccaEntity<BOption> {
this.title = row.title;
this.dueDate = row.dueDate;
this._isDeleted = !!row.isDeleted;
if (this.taskId) {
this.becca.tasks[this.taskId] = this;
}
}
init() {
if (this.taskId) {
this.becca.tasks[this.taskId] = this;
}
}
getPojo() {

5
src/routes/api/tasks.ts Normal file
View File

@ -0,0 +1,5 @@
import * as tasksService from "../../services/tasks.js";
export function getTasks() {
return tasksService.getTasks();
}

View File

@ -72,6 +72,7 @@ import etapiSpecRoute from "../etapi/spec.js";
import etapiBackupRoute from "../etapi/backup.js";
import apiDocsRoute from "./api_docs.js";
import * as tasksRoute from "./api/tasks.js";
const MAX_ALLOWED_FILE_SIZE_MB = 250;
const GET = "get",
@ -279,6 +280,8 @@ function register(app: express.Application) {
apiRoute(PATCH, "/api/etapi-tokens/:etapiTokenId", etapiTokensApiRoutes.patchToken);
apiRoute(DEL, "/api/etapi-tokens/:etapiTokenId", etapiTokensApiRoutes.deleteToken);
apiRoute(GET, "/api/tasks", tasksRoute.getTasks);
// in case of local electron, local calls are allowed unauthenticated, for server they need auth
const clipperMiddleware = isElectron ? [] : [auth.checkEtapiToken];

5
src/services/tasks.ts Normal file
View File

@ -0,0 +1,5 @@
import becca from "../becca/becca.js";
export function getTasks() {
return becca.getTasks();
}