#125, implementation of inheritable relations

This commit is contained in:
azivner
2018-07-29 18:39:10 +02:00
parent 170d317589
commit ed1381103a
8 changed files with 58 additions and 14 deletions

View File

@@ -36,9 +36,23 @@ async function createRelation(sourceNoteId, name, targetNoteId) {
}).save();
}
async function getEffectiveRelations(noteId) {
return await repository.getEntities(`
WITH RECURSIVE tree(noteId) AS (
SELECT ?
UNION
SELECT branches.parentNoteId FROM branches
JOIN tree ON branches.noteId = tree.noteId
JOIN notes ON notes.noteId = branches.parentNoteId
WHERE notes.isDeleted = 0 AND branches.isDeleted = 0
)
SELECT relations.* FROM relations JOIN tree ON relations.sourceNoteId = tree.noteId WHERE relations.isDeleted = 0 AND relations.name IN ('runOnNoteView')`, [noteId]);
}
module.exports = {
BUILTIN_RELATIONS,
getNotesWithRelation,
getNoteWithRelation,
createRelation,
BUILTIN_RELATIONS
getEffectiveRelations
};

View File

@@ -139,8 +139,14 @@ function sanitizeVariableName(str) {
return str.replace(/[^a-z0-9_]/gim, "");
}
async function getScriptBundleForNoteId(noteId) {
const note = await repository.getNote(noteId);
return await getScriptBundle(note);
}
module.exports = {
executeNote,
executeScript,
getScriptBundle
getScriptBundle,
getScriptBundleForNoteId
};