@ -14,8 +14,7 @@ const TaskContext = require('../../services/task_context');
* /
* /
async function moveBranchToParent ( req ) {
async function moveBranchToParent ( req ) {
const branchId = req . params . branchId ;
const { branchId , parentNoteId } = req . params ;
const parentNoteId = req . params . parentNoteId ;
const noteToMove = await tree . getBranch ( branchId ) ;
const noteToMove = await tree . getBranch ( branchId ) ;
@ -26,7 +25,7 @@ async function moveBranchToParent(req) {
}
}
const maxNotePos = await sql . getValue ( 'SELECT MAX(notePosition) FROM branches WHERE parentNoteId = ? AND isDeleted = 0' , [ parentNoteId ] ) ;
const maxNotePos = await sql . getValue ( 'SELECT MAX(notePosition) FROM branches WHERE parentNoteId = ? AND isDeleted = 0' , [ parentNoteId ] ) ;
const newNotePos = maxNotePos === null ? 0 : maxNotePos + 1 ;
const newNotePos = maxNotePos === null ? 0 : maxNotePos + 1 0 ;
const branch = await repository . getBranch ( branchId ) ;
const branch = await repository . getBranch ( branchId ) ;
branch . parentNoteId = parentNoteId ;
branch . parentNoteId = parentNoteId ;
@ -37,8 +36,7 @@ async function moveBranchToParent(req) {
}
}
async function moveBranchBeforeNote ( req ) {
async function moveBranchBeforeNote ( req ) {
const branchId = req . params . branchId ;
const { branchId , beforeBranchId } = req . params ;
const beforeBranchId = req . params . beforeBranchId ;
const noteToMove = await tree . getBranch ( branchId ) ;
const noteToMove = await tree . getBranch ( branchId ) ;
const beforeNote = await tree . getBranch ( beforeBranchId ) ;
const beforeNote = await tree . getBranch ( beforeBranchId ) ;
@ -51,7 +49,7 @@ async function moveBranchBeforeNote(req) {
// we don't change utcDateModified so other changes are prioritized in case of conflict
// we don't change utcDateModified so other changes are prioritized in case of conflict
// also we would have to sync all those modified branches otherwise hash checks would fail
// also we would have to sync all those modified branches otherwise hash checks would fail
await sql . execute ( "UPDATE branches SET notePosition = notePosition + 1 WHERE parentNoteId = ? AND notePosition >= ? AND isDeleted = 0",
await sql . execute ( "UPDATE branches SET notePosition = notePosition + 1 0 WHERE parentNoteId = ? AND notePosition >= ? AND isDeleted = 0",
[ beforeNote . parentNoteId , beforeNote . notePosition ] ) ;
[ beforeNote . parentNoteId , beforeNote . notePosition ] ) ;
await sync _table . addNoteReorderingSync ( beforeNote . parentNoteId ) ;
await sync _table . addNoteReorderingSync ( beforeNote . parentNoteId ) ;
@ -65,8 +63,7 @@ async function moveBranchBeforeNote(req) {
}
}
async function moveBranchAfterNote ( req ) {
async function moveBranchAfterNote ( req ) {
const branchId = req . params . branchId ;
const { branchId , afterBranchId } = req . params ;
const afterBranchId = req . params . afterBranchId ;
const noteToMove = await tree . getBranch ( branchId ) ;
const noteToMove = await tree . getBranch ( branchId ) ;
const afterNote = await tree . getBranch ( afterBranchId ) ;
const afterNote = await tree . getBranch ( afterBranchId ) ;
@ -79,22 +76,21 @@ async function moveBranchAfterNote(req) {
// we don't change utcDateModified so other changes are prioritized in case of conflict
// we don't change utcDateModified so other changes are prioritized in case of conflict
// also we would have to sync all those modified branches otherwise hash checks would fail
// also we would have to sync all those modified branches otherwise hash checks would fail
await sql . execute ( "UPDATE branches SET notePosition = notePosition + 1 WHERE parentNoteId = ? AND notePosition > ? AND isDeleted = 0",
await sql . execute ( "UPDATE branches SET notePosition = notePosition + 1 0 WHERE parentNoteId = ? AND notePosition > ? AND isDeleted = 0",
[ afterNote . parentNoteId , afterNote . notePosition ] ) ;
[ afterNote . parentNoteId , afterNote . notePosition ] ) ;
await sync _table . addNoteReorderingSync ( afterNote . parentNoteId ) ;
await sync _table . addNoteReorderingSync ( afterNote . parentNoteId ) ;
const branch = await repository . getBranch ( branchId ) ;
const branch = await repository . getBranch ( branchId ) ;
branch . parentNoteId = afterNote . parentNoteId ;
branch . parentNoteId = afterNote . parentNoteId ;
branch . notePosition = afterNote . notePosition + 1 ;
branch . notePosition = afterNote . notePosition + 1 0 ;
await branch . save ( ) ;
await branch . save ( ) ;
return { success : true } ;
return { success : true } ;
}
}
async function setExpanded ( req ) {
async function setExpanded ( req ) {
const branchId = req . params . branchId ;
const { branchId , expanded } = req . params ;
const expanded = req . params . expanded ;
await sql . execute ( "UPDATE branches SET isExpanded = ? WHERE branchId = ?" , [ expanded , branchId ] ) ;
await sql . execute ( "UPDATE branches SET isExpanded = ? WHERE branchId = ?" , [ expanded , branchId ] ) ;
// we don't sync expanded label
// we don't sync expanded label