add api.runAsyncOnBackendWithManualTransactionHandling() variant and add toast warnings about improper usage.

This commit is contained in:
zadam
2023-10-29 00:51:23 +02:00
parent 4660c154e9
commit 48e98b2ac3
3 changed files with 64 additions and 18 deletions

View File

@@ -4,12 +4,16 @@ const scriptService = require('../../services/script');
const attributeService = require('../../services/attributes');
const becca = require('../../becca/becca');
const syncService = require('../../services/sync');
const sql = require('../../services/sql');
// The async/await here is very confusing, because the body.script may, but may not be async. If it is async, then we
// need to await it and make the complete response including metadata available in a Promise, so that the route detects
// this and does result.then().
async function exec(req) {
try {
const {body} = req;
const result = await scriptService.executeScript(
const execute = body => scriptService.executeScript(
body.script,
body.params,
body.startNoteId,
@@ -18,6 +22,10 @@ async function exec(req) {
body.originEntityId
);
const result = body.transactional
? sql.transactional(() => execute(body))
: await execute(body);
return {
success: true,
executionResult: result,