mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
more becca changes
This commit is contained in:
parent
e466c393eb
commit
219098ab53
@ -5,6 +5,7 @@ const log = require('../../services/log');
|
|||||||
const attributeService = require('../../services/attributes');
|
const attributeService = require('../../services/attributes');
|
||||||
const repository = require('../../services/repository');
|
const repository = require('../../services/repository');
|
||||||
const Attribute = require('../../entities/attribute');
|
const Attribute = require('../../entities/attribute');
|
||||||
|
const becca = require("../../services/becca/becca.js");
|
||||||
|
|
||||||
function getEffectiveNoteAttributes(req) {
|
function getEffectiveNoteAttributes(req) {
|
||||||
const note = repository.getNote(req.params.noteId);
|
const note = repository.getNote(req.params.noteId);
|
||||||
@ -100,15 +101,14 @@ function deleteNoteAttribute(req) {
|
|||||||
const noteId = req.params.noteId;
|
const noteId = req.params.noteId;
|
||||||
const attributeId = req.params.attributeId;
|
const attributeId = req.params.attributeId;
|
||||||
|
|
||||||
const attribute = repository.getAttribute(attributeId);
|
const attribute = becca.getAttribute(attributeId);
|
||||||
|
|
||||||
if (attribute) {
|
if (attribute) {
|
||||||
if (attribute.noteId !== noteId) {
|
if (attribute.noteId !== noteId) {
|
||||||
return [400, `Attribute ${attributeId} is not owned by ${noteId}`];
|
return [400, `Attribute ${attributeId} is not owned by ${noteId}`];
|
||||||
}
|
}
|
||||||
|
|
||||||
attribute.isDeleted = true;
|
attribute.markAttributeAsDeleted();
|
||||||
attribute.save();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ const cloningService = require('./cloning');
|
|||||||
const appInfo = require('./app_info');
|
const appInfo = require('./app_info');
|
||||||
const searchService = require('./search/services/search');
|
const searchService = require('./search/services/search');
|
||||||
const SearchContext = require("./search/search_context.js");
|
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.
|
* 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
|
* @param {string} noteId
|
||||||
* @returns {Note|null}
|
* @returns {Note|null}
|
||||||
*/
|
*/
|
||||||
this.getNote = repository.getNote;
|
this.getNote = becca.getNote;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method
|
* @method
|
||||||
* @param {string} branchId
|
* @param {string} branchId
|
||||||
* @returns {Branch|null}
|
* @returns {Branch|null}
|
||||||
*/
|
*/
|
||||||
this.getBranch = repository.getBranch;
|
this.getBranch = becca.getBranch;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method
|
* @method
|
||||||
* @param {string} attributeId
|
* @param {string} attributeId
|
||||||
* @returns {Attribute|null}
|
* @returns {Attribute|null}
|
||||||
*/
|
*/
|
||||||
this.getAttribute = repository.getAttribute;
|
this.getAttribute = becca.getAttribute;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves first entity from the SQL's result set.
|
* 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))
|
const noteIds = searchService.findResultsWithQuery(query, new SearchContext(searchParams))
|
||||||
.map(sr => sr.noteId);
|
.map(sr => sr.noteId);
|
||||||
|
|
||||||
return repository.getNotes(noteIds);
|
return becca.getNotes(noteIds);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -52,6 +52,10 @@ class Becca {
|
|||||||
return this.notes[noteId];
|
return this.notes[noteId];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getNotes(noteIds) {
|
||||||
|
return this.notes.filter(note => noteIds.includes(note.noteId));
|
||||||
|
}
|
||||||
|
|
||||||
getBranch(branchId) {
|
getBranch(branchId) {
|
||||||
return this.branches[branchId];
|
return this.branches[branchId];
|
||||||
}
|
}
|
||||||
|
@ -164,6 +164,12 @@ class Attribute extends AbstractEntity {
|
|||||||
utcDateModified: this.utcDateModified
|
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;
|
module.exports = Attribute;
|
||||||
|
@ -869,6 +869,8 @@ class Note extends AbstractEntity {
|
|||||||
|
|
||||||
markAsDeleted() {
|
markAsDeleted() {
|
||||||
sql.execute("UPDATE notes SET isDeleted = 1 WHERE noteId = ?", [this.noteId]);
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user