From 219098ab53f52da01d295d5a421292cc3aaeb93c Mon Sep 17 00:00:00 2001 From: zadam Date: Mon, 26 Apr 2021 22:24:55 +0200 Subject: [PATCH] more becca changes --- src/routes/api/attributes.js | 6 +++--- src/services/backend_script_api.js | 9 +++++---- src/services/becca/becca.js | 4 ++++ src/services/becca/entities/attribute.js | 6 ++++++ src/services/becca/entities/note.js | 2 ++ 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/routes/api/attributes.js b/src/routes/api/attributes.js index 31f7025aa..7eeb7e669 100644 --- a/src/routes/api/attributes.js +++ b/src/routes/api/attributes.js @@ -5,6 +5,7 @@ const log = require('../../services/log'); const attributeService = require('../../services/attributes'); const repository = require('../../services/repository'); const Attribute = require('../../entities/attribute'); +const becca = require("../../services/becca/becca.js"); function getEffectiveNoteAttributes(req) { const note = repository.getNote(req.params.noteId); @@ -100,15 +101,14 @@ function deleteNoteAttribute(req) { const noteId = req.params.noteId; const attributeId = req.params.attributeId; - const attribute = repository.getAttribute(attributeId); + const attribute = becca.getAttribute(attributeId); if (attribute) { if (attribute.noteId !== noteId) { return [400, `Attribute ${attributeId} is not owned by ${noteId}`]; } - attribute.isDeleted = true; - attribute.save(); + attribute.markAttributeAsDeleted(); } } diff --git a/src/services/backend_script_api.js b/src/services/backend_script_api.js index a6a118781..daa8c3066 100644 --- a/src/services/backend_script_api.js +++ b/src/services/backend_script_api.js @@ -14,6 +14,7 @@ const cloningService = require('./cloning'); const appInfo = require('./app_info'); const searchService = require('./search/services/search'); const SearchContext = require("./search/search_context.js"); +const becca = require("./becca/becca.js"); /** * This is the main backend API interface for scripts. It's published in the local "api" object. @@ -58,21 +59,21 @@ function BackendScriptApi(currentNote, apiParams) { * @param {string} noteId * @returns {Note|null} */ - this.getNote = repository.getNote; + this.getNote = becca.getNote; /** * @method * @param {string} branchId * @returns {Branch|null} */ - this.getBranch = repository.getBranch; + this.getBranch = becca.getBranch; /** * @method * @param {string} attributeId * @returns {Attribute|null} */ - this.getAttribute = repository.getAttribute; + this.getAttribute = becca.getAttribute; /** * Retrieves first entity from the SQL's result set. @@ -113,7 +114,7 @@ function BackendScriptApi(currentNote, apiParams) { const noteIds = searchService.findResultsWithQuery(query, new SearchContext(searchParams)) .map(sr => sr.noteId); - return repository.getNotes(noteIds); + return becca.getNotes(noteIds); }; /** diff --git a/src/services/becca/becca.js b/src/services/becca/becca.js index 8118a7252..6505191bc 100644 --- a/src/services/becca/becca.js +++ b/src/services/becca/becca.js @@ -52,6 +52,10 @@ class Becca { return this.notes[noteId]; } + getNotes(noteIds) { + return this.notes.filter(note => noteIds.includes(note.noteId)); + } + getBranch(branchId) { return this.branches[branchId]; } diff --git a/src/services/becca/entities/attribute.js b/src/services/becca/entities/attribute.js index 0f9e69b61..47f3e528c 100644 --- a/src/services/becca/entities/attribute.js +++ b/src/services/becca/entities/attribute.js @@ -164,6 +164,12 @@ class Attribute extends AbstractEntity { utcDateModified: this.utcDateModified }); } + + markAttributeAsDeleted() { + sql.execute("UPDATE attributes SET isDeleted = 1 WHERE attributeId = ?", [this.attributeId]); + + // FIXME: this needs to be published into entity_changes (for sync and becca cleanup) + } } module.exports = Attribute; diff --git a/src/services/becca/entities/note.js b/src/services/becca/entities/note.js index ff5b47558..b023bc8ec 100644 --- a/src/services/becca/entities/note.js +++ b/src/services/becca/entities/note.js @@ -869,6 +869,8 @@ class Note extends AbstractEntity { markAsDeleted() { sql.execute("UPDATE notes SET isDeleted = 1 WHERE noteId = ?", [this.noteId]); + + // FIXME: this needs to be published into entity_changes (for sync and becca cleanup) } }