mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
server-ts: Convert etapi/bbranches
This commit is contained in:
parent
602b4988ae
commit
e4024408bd
@ -141,7 +141,7 @@ class BBranch extends AbstractBeccaEntity<BBranch> {
|
||||
*
|
||||
* @returns true if note has been deleted, false otherwise
|
||||
*/
|
||||
deleteBranch(deleteId: string, taskContext: TaskContext): boolean {
|
||||
deleteBranch(deleteId?: string, taskContext?: TaskContext): boolean {
|
||||
if (!deleteId) {
|
||||
deleteId = utils.randomString(10);
|
||||
}
|
||||
|
@ -1,11 +1,14 @@
|
||||
const becca = require('../becca/becca');
|
||||
const eu = require('./etapi_utils');
|
||||
const mappers = require('./mappers');
|
||||
const BBranch = require('../becca/entities/bbranch');
|
||||
const entityChangesService = require('../services/entity_changes');
|
||||
const v = require('./validators');
|
||||
import { Router } from "express";
|
||||
|
||||
function register(router) {
|
||||
import becca = require('../becca/becca');
|
||||
import eu = require('./etapi_utils');
|
||||
import mappers = require('./mappers');
|
||||
import BBranch = require('../becca/entities/bbranch');
|
||||
import entityChangesService = require('../services/entity_changes');
|
||||
import v = require('./validators');
|
||||
import { BranchRow } from "../becca/entities/rows";
|
||||
|
||||
function register(router: Router) {
|
||||
eu.route(router, 'get', '/etapi/branches/:branchId', (req, res, next) => {
|
||||
const branch = eu.getAndCheckBranch(req.params.branchId);
|
||||
|
||||
@ -21,16 +24,16 @@ function register(router) {
|
||||
};
|
||||
|
||||
eu.route(router, 'post', '/etapi/branches', (req, res, next) => {
|
||||
const params = {};
|
||||
|
||||
eu.validateAndPatch(params, req.body, ALLOWED_PROPERTIES_FOR_CREATE_BRANCH);
|
||||
const _params = {};
|
||||
eu.validateAndPatch(_params, req.body, ALLOWED_PROPERTIES_FOR_CREATE_BRANCH);
|
||||
const params: BranchRow = _params as BranchRow;
|
||||
|
||||
const existing = becca.getBranchFromChildAndParent(params.noteId, params.parentNoteId);
|
||||
|
||||
if (existing) {
|
||||
existing.notePosition = params.notePosition;
|
||||
existing.prefix = params.prefix;
|
||||
existing.isExpanded = params.isExpanded;
|
||||
existing.notePosition = params.notePosition as number;
|
||||
existing.prefix = params.prefix as string;
|
||||
existing.isExpanded = params.isExpanded as boolean;
|
||||
existing.save();
|
||||
|
||||
return res.status(200).json(mappers.mapBranchToPojo(existing));
|
||||
@ -39,7 +42,7 @@ function register(router) {
|
||||
const branch = new BBranch(params).save();
|
||||
|
||||
res.status(201).json(mappers.mapBranchToPojo(branch));
|
||||
} catch (e) {
|
||||
} catch (e: any) {
|
||||
throw new eu.EtapiError(400, eu.GENERIC_CODE, e.message);
|
||||
}
|
||||
}
|
||||
@ -81,6 +84,6 @@ function register(router) {
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
export = {
|
||||
register
|
||||
};
|
@ -65,7 +65,7 @@ const etapiAuthRoutes = require('../etapi/auth');
|
||||
const etapiAppInfoRoutes = require('../etapi/app_info');
|
||||
const etapiAttachmentRoutes = require('../etapi/attachments');
|
||||
const etapiAttributeRoutes = require('../etapi/attributes');
|
||||
const etapiBranchRoutes = require('../etapi/branches.js');
|
||||
const etapiBranchRoutes = require('../etapi/branches');
|
||||
const etapiNoteRoutes = require('../etapi/notes.js');
|
||||
const etapiSpecialNoteRoutes = require('../etapi/special_notes');
|
||||
const etapiSpecRoute = require('../etapi/spec.js');
|
||||
|
Loading…
x
Reference in New Issue
Block a user