server-ts: Port services/branches

This commit is contained in:
Elian Doran 2024-02-18 11:48:38 +02:00
parent 0d4fb42731
commit 9ea4fcd667
No known key found for this signature in database
5 changed files with 13 additions and 12 deletions

View File

@ -7,7 +7,7 @@ const treeService = require('../../services/tree');
const eraseService = require('../../services/erase'); const eraseService = require('../../services/erase');
const becca = require('../../becca/becca'); const becca = require('../../becca/becca');
const TaskContext = require('../../services/task_context'); const TaskContext = require('../../services/task_context');
const branchService = require('../../services/branches.js'); const branchService = require('../../services/branches');
const log = require('../../services/log'); const log = require('../../services/log');
const ValidationError = require('../../errors/validation_error'); const ValidationError = require('../../errors/validation_error');
const eventService = require("../../services/events"); const eventService = require("../../services/events");

View File

@ -17,7 +17,7 @@ const becca = require('../becca/becca');
const ws = require('./ws'); const ws = require('./ws');
const SpacedUpdate = require('./spaced_update.js'); const SpacedUpdate = require('./spaced_update.js');
const specialNotesService = require('./special_notes.js'); const specialNotesService = require('./special_notes.js');
const branchService = require('./branches.js'); const branchService = require('./branches');
const exportService = require('./export/zip.js'); const exportService = require('./export/zip.js');
const syncMutex = require('./sync_mutex'); const syncMutex = require('./sync_mutex');
const backupService = require('./backup'); const backupService = require('./backup');

View File

@ -1,7 +1,8 @@
const treeService = require('./tree'); import treeService = require('./tree');
const sql = require('./sql'); import sql = require('./sql');
import BBranch = require('../becca/entities/bbranch.js');
function moveBranchToNote(branchToMove, targetParentNoteId) { function moveBranchToNote(branchToMove: BBranch, targetParentNoteId: string) {
if (branchToMove.parentNoteId === targetParentNoteId) { if (branchToMove.parentNoteId === targetParentNoteId) {
return {success: true}; // no-op return {success: true}; // no-op
} }
@ -12,8 +13,8 @@ function moveBranchToNote(branchToMove, targetParentNoteId) {
return [200, validationResult]; return [200, validationResult];
} }
const maxNotePos = sql.getValue('SELECT MAX(notePosition) FROM branches WHERE parentNoteId = ? AND isDeleted = 0', [targetParentNoteId]); const maxNotePos = sql.getValue<number | null>('SELECT MAX(notePosition) FROM branches WHERE parentNoteId = ? AND isDeleted = 0', [targetParentNoteId]);
const newNotePos = maxNotePos === null ? 0 : maxNotePos + 10; const newNotePos = !maxNotePos ? 0 : maxNotePos + 10;
const newBranch = branchToMove.createClone(targetParentNoteId, newNotePos); const newBranch = branchToMove.createClone(targetParentNoteId, newNotePos);
newBranch.save(); newBranch.save();
@ -26,10 +27,10 @@ function moveBranchToNote(branchToMove, targetParentNoteId) {
}; };
} }
function moveBranchToBranch(branchToMove, targetParentBranch) { function moveBranchToBranch(branchToMove: BBranch, targetParentBranch: BBranch) {
const res = moveBranchToNote(branchToMove, targetParentBranch.noteId); const res = moveBranchToNote(branchToMove, targetParentBranch.noteId);
if (!res.success) { if (!("success" in res) || !res.success) {
return res; return res;
} }
@ -42,7 +43,7 @@ function moveBranchToBranch(branchToMove, targetParentBranch) {
return res; return res;
} }
module.exports = { export = {
moveBranchToBranch, moveBranchToBranch,
moveBranchToNote moveBranchToNote
}; };

View File

@ -2,7 +2,7 @@ const log = require('./log');
const revisionService = require('./revisions'); const revisionService = require('./revisions');
const becca = require('../becca/becca'); const becca = require('../becca/becca');
const cloningService = require('./cloning.js'); const cloningService = require('./cloning.js');
const branchService = require('./branches.js'); const branchService = require('./branches');
const utils = require('./utils'); const utils = require('./utils');
const eraseService = require("./erase"); const eraseService = require("./erase");

View File

@ -261,7 +261,7 @@ function setNoteToParent(noteId: string, prefix: string, parentNoteId: string) {
} }
} }
module.exports = { export = {
validateParentChild, validateParentChild,
sortNotes, sortNotes,
sortNotesIfNeeded, sortNotesIfNeeded,