Skip to content

Build your personal knowledge base with Trilium Notes

more becca changes

zadam219098ab53f5
diff --git a/src/routes/api/attributes.js b/src/routes/api/attributes.js
index 31f7025aa2..7eeb7e6697 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 a6a1187818..daa8c30663 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 8118a72524..6505191bc3 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 0f9e69b618..47f3e528cc 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 ff5b475589..b023bc8ece 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)
}
}