syncification

This commit is contained in:
zadam
2020-06-20 12:31:38 +02:00
parent 30062d687f
commit 88348c560c
97 changed files with 1673 additions and 1700 deletions

View File

@@ -5,15 +5,15 @@ const attributeService = require('../../services/attributes');
const repository = require('../../services/repository');
const syncService = require('../../services/sync');
async function exec(req) {
function exec(req) {
try {
const result = await scriptService.executeScript(req.body.script, req.body.params, req.body.startNoteId,
const result = scriptService.executeScript(req.body.script, req.body.params, req.body.startNoteId,
req.body.currentNoteId, req.body.originEntityName, req.body.originEntityId);
return {
success: true,
executionResult: result,
maxSyncId: await syncService.getMaxSyncId()
maxSyncId: syncService.getMaxSyncId()
};
}
catch (e) {
@@ -21,21 +21,21 @@ async function exec(req) {
}
}
async function run(req) {
const note = await repository.getNote(req.params.noteId);
function run(req) {
const note = repository.getNote(req.params.noteId);
const result = await scriptService.executeNote(note, { originEntity: note });
const result = scriptService.executeNote(note, { originEntity: note });
return { executionResult: result };
}
async function getBundlesWithLabel(label, value) {
const notes = await attributeService.getNotesWithLabel(label, value);
function getBundlesWithLabel(label, value) {
const notes = attributeService.getNotesWithLabel(label, value);
const bundles = [];
for (const note of notes) {
const bundle = await scriptService.getScriptBundleForFrontend(note);
const bundle = scriptService.getScriptBundleForFrontend(note);
if (bundle) {
bundles.push(bundle);
@@ -45,20 +45,20 @@ async function getBundlesWithLabel(label, value) {
return bundles;
}
async function getStartupBundles() {
return await getBundlesWithLabel("run", "frontendStartup");
function getStartupBundles() {
return getBundlesWithLabel("run", "frontendStartup");
}
async function getWidgetBundles() {
return await getBundlesWithLabel("widget");
function getWidgetBundles() {
return getBundlesWithLabel("widget");
}
async function getRelationBundles(req) {
function getRelationBundles(req) {
const noteId = req.params.noteId;
const note = await repository.getNote(noteId);
const note = repository.getNote(noteId);
const relationName = req.params.relationName;
const attributes = await note.getAttributes();
const attributes = note.getAttributes();
const filtered = attributes.filter(attr => attr.type === 'relation' && attr.name === relationName);
const targetNoteIds = filtered.map(relation => relation.value);
const uniqueNoteIds = Array.from(new Set(targetNoteIds));
@@ -66,13 +66,13 @@ async function getRelationBundles(req) {
const bundles = [];
for (const noteId of uniqueNoteIds) {
const note = await repository.getNote(noteId);
const note = repository.getNote(noteId);
if (!note.isJavaScript() || note.getScriptEnv() !== 'frontend') {
continue;
}
const bundle = await scriptService.getScriptBundleForFrontend(note);
const bundle = scriptService.getScriptBundleForFrontend(note);
if (bundle) {
bundles.push(bundle);
@@ -82,10 +82,10 @@ async function getRelationBundles(req) {
return bundles;
}
async function getBundle(req) {
const note = await repository.getNote(req.params.noteId);
function getBundle(req) {
const note = repository.getNote(req.params.noteId);
return await scriptService.getScriptBundleForFrontend(note);
return scriptService.getScriptBundleForFrontend(note);
}
module.exports = {
@@ -95,4 +95,4 @@ module.exports = {
getWidgetBundles,
getRelationBundles,
getBundle
};
};