renaming note_tree to branch

This commit is contained in:
azivner
2018-03-24 21:39:15 -04:00
parent 511fb89af0
commit 4c472ce78b
45 changed files with 540 additions and 508 deletions

View File

@@ -19,12 +19,12 @@ router.put('/:childNoteId/clone-to/:parentNoteId', auth.checkApiAuth, wrap(async
return;
}
const maxNotePos = await sql.getValue('SELECT MAX(notePosition) FROM note_tree 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;
await sql.doInTransaction(async () => {
const noteTree = {
noteTreeId: utils.newNoteTreeId(),
const branch = {
branchId: utils.newBranchId(),
noteId: childNoteId,
parentNoteId: parentNoteId,
prefix: prefix,
@@ -34,22 +34,22 @@ router.put('/:childNoteId/clone-to/:parentNoteId', auth.checkApiAuth, wrap(async
isDeleted: 0
};
await sql.replace("note_tree", noteTree);
await sql.replace("branches", branch);
await sync_table.addNoteTreeSync(noteTree.noteTreeId, sourceId);
await sync_table.addBranchSync(branch.branchId, sourceId);
await sql.execute("UPDATE note_tree SET isExpanded = 1 WHERE noteId = ?", [parentNoteId]);
await sql.execute("UPDATE branches SET isExpanded = 1 WHERE noteId = ?", [parentNoteId]);
});
res.send({ success: true });
}));
router.put('/:noteId/clone-after/:afterNoteTreeId', auth.checkApiAuth, wrap(async (req, res, next) => {
router.put('/:noteId/clone-after/:afterBranchId', auth.checkApiAuth, wrap(async (req, res, next) => {
const noteId = req.params.noteId;
const afterNoteTreeId = req.params.afterNoteTreeId;
const afterBranchId = req.params.afterBranchId;
const sourceId = req.headers.source_id;
const afterNote = await tree.getNoteTree(afterNoteTreeId);
const afterNote = await tree.getBranch(afterBranchId);
if (!await tree.validateParentChild(res, afterNote.parentNoteId, noteId)) {
return;
@@ -58,13 +58,13 @@ router.put('/:noteId/clone-after/:afterNoteTreeId', auth.checkApiAuth, wrap(asyn
await sql.doInTransaction(async () => {
// we don't change dateModified so other changes are prioritized in case of conflict
// also we would have to sync all those modified note trees otherwise hash checks would fail
await sql.execute("UPDATE note_tree SET notePosition = notePosition + 1 WHERE parentNoteId = ? AND notePosition > ? AND isDeleted = 0",
await sql.execute("UPDATE branches SET notePosition = notePosition + 1 WHERE parentNoteId = ? AND notePosition > ? AND isDeleted = 0",
[afterNote.parentNoteId, afterNote.notePosition]);
await sync_table.addNoteReorderingSync(afterNote.parentNoteId, sourceId);
const noteTree = {
noteTreeId: utils.newNoteTreeId(),
const branch = {
branchId: utils.newBranchId(),
noteId: noteId,
parentNoteId: afterNote.parentNoteId,
notePosition: afterNote.notePosition + 1,
@@ -73,9 +73,9 @@ router.put('/:noteId/clone-after/:afterNoteTreeId', auth.checkApiAuth, wrap(asyn
isDeleted: 0
};
await sql.replace("note_tree", noteTree);
await sql.replace("branches", branch);
await sync_table.addNoteTreeSync(noteTree.noteTreeId, sourceId);
await sync_table.addBranchSync(branch.branchId, sourceId);
});
res.send({ success: true });