From f7f0560a9f757a10b4d365a94800de1c1697d97a Mon Sep 17 00:00:00 2001 From: azivner Date: Sun, 13 Jan 2019 11:56:50 +0100 Subject: [PATCH] simplification of script bundles on backend --- src/routes/api/script.js | 11 +++++++++-- src/services/repository.js | 5 ----- src/services/script.js | 8 +------- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/routes/api/script.js b/src/routes/api/script.js index b00e4ccb5..1479b24b9 100644 --- a/src/routes/api/script.js +++ b/src/routes/api/script.js @@ -53,14 +53,21 @@ async function getRelationBundles(req) { const bundles = []; for (const noteId of uniqueNoteIds) { - bundles.push(await scriptService.getScriptBundleForNoteId(noteId)); + const note = await repository.getNote(noteId); + const bundle = await scriptService.getScriptBundle(note); + + if (bundle) { + bundles.push(bundle); + } } return bundles; } async function getBundle(req) { - return await scriptService.getScriptBundleForNoteId(req.params.noteId); + const note = await repository.getNote(req.params.noteId); + + return await scriptService.getScriptBundle(note); } module.exports = { diff --git a/src/services/repository.js b/src/services/repository.js index ee844d97d..44f8dbe06 100644 --- a/src/services/repository.js +++ b/src/services/repository.js @@ -47,11 +47,6 @@ async function getBranch(branchId) { return await getEntity("SELECT * FROM branches WHERE branchId = ?", [branchId]); } -/** @returns {Image|null} */ -async function getImage(imageId) { - return await getEntity("SELECT * FROM images WHERE imageId = ?", [imageId]); -} - /** @returns {Attribute|null} */ async function getAttribute(attributeId) { return await getEntity("SELECT * FROM attributes WHERE attributeId = ?", [attributeId]); diff --git a/src/services/script.js b/src/services/script.js index 66d1c4b16..7e2209d90 100644 --- a/src/services/script.js +++ b/src/services/script.js @@ -153,14 +153,8 @@ 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, - getScriptBundleForNoteId + getScriptBundle }; \ No newline at end of file