mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 05:28:59 +01: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 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();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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);
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 | 
			
		||||
@ -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];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -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;
 | 
			
		||||
 | 
			
		||||
@ -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)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user