undelete note WIP

This commit is contained in:
zadam
2020-01-03 13:14:43 +01:00
parent c1d0a1e07b
commit 14f3c783f2
7 changed files with 300 additions and 130 deletions

View File

@@ -71,6 +71,16 @@ async function deleteNote(req) {
}
}
async function undeleteNote(req) {
const note = await repository.getNote(req.params.noteId);
const taskContext = TaskContext.getInstance(utils.randomString(), 'undelete-notes');
await noteService.undeleteNote(note, note.deleteId, taskContext);
await taskContext.taskSucceeded();
}
async function sortNotes(req) {
const noteId = req.params.noteId;
@@ -172,6 +182,7 @@ module.exports = {
getNote,
updateNote,
deleteNote,
undeleteNote,
createNote,
sortNotes,
protectSubtree,

View File

@@ -2,6 +2,7 @@
const sql = require('../../services/sql');
const protectedSessionService = require('../../services/protected_session');
const noteService = require('../../services/notes');
async function getRecentChanges() {
const recentChanges = await sql.getRows(
@@ -60,17 +61,10 @@ async function getRecentChanges() {
else {
const deleteId = change.current_deleteId;
const undeletedParentCount = await sql.getValue(`
SELECT COUNT(parentNote.noteId)
FROM branches
JOIN notes AS parentNote ON parentNote.noteId = branches.parentNoteId
WHERE branches.noteId = ?
AND branches.isDeleted = 1
AND branches.deleteId = ?
AND parentNote.isDeleted = 0`, [change.noteId, deleteId]);
const undeletedParentBranches = await noteService.getUndeletedParentBranches(change.noteId, deleteId);
// note (and the subtree) can be undeleted if there's at least one undeleted parent (whose branch would be undeleted by this op)
change.canBeUndeleted = undeletedParentCount > 0;
change.canBeUndeleted = undeletedParentBranches.length > 0;
}
}
}