@ -2,11 +2,10 @@ const sql = require('./sql');
const options = require ( './options' ) ;
const utils = require ( './utils' ) ;
const notes = require ( './notes' ) ;
const audit _category = require ( './audit_category' ) ;
const data _encryption = require ( './data_encryption' ) ;
const sync _table = require ( './sync_table' ) ;
async function createNewNote ( parentNoteId , note , browserId ) {
async function createNewNote ( parentNoteId , note ) {
const noteId = utils . newNoteId ( ) ;
const noteTreeId = utils . newNoteTreeId ( ) ;
@ -30,7 +29,6 @@ async function createNewNote(parentNoteId, note, browserId) {
}
await sql . doInTransaction ( async ( ) => {
await sql . addAudit ( audit _category . CREATE _NOTE , browserId , noteId ) ;
await sync _table . addNoteTreeSync ( noteTreeId ) ;
await sync _table . addNoteSync ( noteId ) ;
@ -168,8 +166,6 @@ async function updateNote(noteId, newNote, ctx) {
await protectNoteHistory ( noteId , ctx . getDataKeyOrNull ( ) , newNote . detail . is _protected ) ;
await addNoteAudits ( origNoteDetail , newNote . detail , ctx . browserId ) ;
await sql . execute ( "UPDATE notes SET note_title = ?, note_text = ?, is_protected = ?, date_modified = ? WHERE note_id = ?" , [
newNote . detail . note _title ,
newNote . detail . note _text ,
@ -195,28 +191,7 @@ async function updateNote(noteId, newNote, ctx) {
} ) ;
}
async function addNoteAudits ( origNote , newNote , browserId ) {
const noteId = newNote . note _id ;
if ( ! origNote || newNote . note _title !== origNote . note _title ) {
await sql . deleteRecentAudits ( audit _category . UPDATE _TITLE , browserId , noteId ) ;
await sql . addAudit ( audit _category . UPDATE _TITLE , browserId , noteId ) ;
}
if ( ! origNote || newNote . note _text !== origNote . note _text ) {
await sql . deleteRecentAudits ( audit _category . UPDATE _CONTENT , browserId , noteId ) ;
await sql . addAudit ( audit _category . UPDATE _CONTENT , browserId , noteId ) ;
}
if ( ! origNote || newNote . is _protected !== origNote . is _protected ) {
const origIsProtected = origNote ? origNote . is _protected : null ;
await sql . addAudit ( audit _category . PROTECTED , browserId , noteId , origIsProtected , newNote . is _protected ) ;
}
}
async function deleteNote ( noteTreeId , browserId ) {
async function deleteNote ( noteTreeId ) {
const now = utils . nowTimestamp ( ) ;
await sql . execute ( "UPDATE notes_tree SET is_deleted = 1, date_modified = ? WHERE note_tree_id = ?" , [ now , noteTreeId ] ) ;
await sync _table . addNoteTreeSync ( noteTreeId ) ;
@ -232,17 +207,14 @@ async function deleteNote(noteTreeId, browserId) {
const children = await sql . getResults ( "SELECT note_tree_id FROM notes_tree WHERE note_pid = ? AND is_deleted = 0" , [ noteId ] ) ;
for ( const child of children ) {
await deleteNote ( child . note _tree _id , browserId );
await deleteNote ( child . note _tree _id );
}
await sql . addAudit ( audit _category . DELETE _NOTE , browserId , noteTreeId ) ;
}
}
module . exports = {
createNewNote ,
updateNote ,
addNoteAudits ,
deleteNote ,
protectNoteRecursively
} ;