mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-31 04:02:26 +08:00
feat(tasks): add POST API
This commit is contained in:
parent
98dff61305
commit
17f9fa7e89
@ -16,7 +16,7 @@ export default class BTask extends AbstractBeccaEntity<BOption> {
|
|||||||
return [ "taskId", "parentNoteId", "title", "dueDate", "isDone", "isDeleted" ];
|
return [ "taskId", "parentNoteId", "title", "dueDate", "isDone", "isDeleted" ];
|
||||||
}
|
}
|
||||||
|
|
||||||
taskId!: string;
|
taskId?: string;
|
||||||
parentNoteId!: string;
|
parentNoteId!: string;
|
||||||
title!: string;
|
title!: string;
|
||||||
dueDate?: string;
|
dueDate?: string;
|
||||||
@ -43,6 +43,7 @@ export default class BTask extends AbstractBeccaEntity<BOption> {
|
|||||||
this.parentNoteId = row.parentNoteId;
|
this.parentNoteId = row.parentNoteId;
|
||||||
this.title = row.title;
|
this.title = row.title;
|
||||||
this.dueDate = row.dueDate;
|
this.dueDate = row.dueDate;
|
||||||
|
this.isDone = !!row.isDeleted;
|
||||||
this._isDeleted = !!row.isDeleted;
|
this._isDeleted = !!row.isDeleted;
|
||||||
|
|
||||||
if (this.taskId) {
|
if (this.taskId) {
|
||||||
|
@ -138,10 +138,10 @@ export interface NoteRow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface TaskRow {
|
export interface TaskRow {
|
||||||
taskId: string;
|
taskId?: string;
|
||||||
parentNoteId: string;
|
parentNoteId: string;
|
||||||
title: string;
|
title: string;
|
||||||
dueDate?: string;
|
dueDate?: string;
|
||||||
isDone: boolean;
|
isDone?: boolean;
|
||||||
isDeleted: boolean;
|
isDeleted?: boolean;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
|
import type { Request } from "express";
|
||||||
import * as tasksService from "../../services/tasks.js";
|
import * as tasksService from "../../services/tasks.js";
|
||||||
|
|
||||||
export function getTasks() {
|
export function getTasks() {
|
||||||
return tasksService.getTasks();
|
return tasksService.getTasks();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function createNewTask(req: Request) {
|
||||||
|
return tasksService.createNewTask(req.body);
|
||||||
|
}
|
||||||
|
@ -281,6 +281,7 @@ function register(app: express.Application) {
|
|||||||
apiRoute(DEL, "/api/etapi-tokens/:etapiTokenId", etapiTokensApiRoutes.deleteToken);
|
apiRoute(DEL, "/api/etapi-tokens/:etapiTokenId", etapiTokensApiRoutes.deleteToken);
|
||||||
|
|
||||||
apiRoute(GET, "/api/tasks", tasksRoute.getTasks);
|
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
|
// in case of local electron, local calls are allowed unauthenticated, for server they need auth
|
||||||
const clipperMiddleware = isElectron ? [] : [auth.checkEtapiToken];
|
const clipperMiddleware = isElectron ? [] : [auth.checkEtapiToken];
|
||||||
|
@ -1,5 +1,21 @@
|
|||||||
import becca from "../becca/becca.js";
|
import becca from "../becca/becca.js";
|
||||||
|
import BTask from "../becca/entities/btask.js";
|
||||||
|
|
||||||
export function getTasks() {
|
export function getTasks() {
|
||||||
return becca.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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user