Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIO-8544: Replace async callbacks with async/await #204

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 16 additions & 20 deletions src/server/actions/save/save.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { each, set, has, get } from 'lodash';
const async = require('async');
const debug = require('debug')('formio:actions:save');
const error = require('debug')('formio:error');
const SaveAction = {
Expand Down Expand Up @@ -278,26 +277,23 @@ const SaveAction = {
debug('Saving to resource: ' + action.settings.resource);
const saveTo = SaveAction.saveToForm(scope, action.settings.resource);
if (saveTo) {
if (!saveTo.handlers) {
error('Cannot find resource handlers.');
return next('Cannot find resource handlers.');
try {
if (!saveTo.handlers) {
error('Cannot find resource handlers.');
return next('Cannot find resource handlers.');
}
const handlers = req.method === 'PUT' ? saveTo.handlers.update : saveTo.handlers.create;
const childReq = scope.utils.childRequest(req);
childReq.body = SaveAction.childSubmission(scope, req, res, childReq.body);
for (const handler of handlers) {
await handler(childReq, res);
}
SaveAction.childResponse(scope, req, res);
return next();
} catch (err) {
error(err);
return next(err);
}
const handlers = req.method === 'PUT' ? saveTo.handlers.update : saveTo.handlers.create;
const childReq = scope.utils.childRequest(req);
childReq.body = SaveAction.childSubmission(scope, req, res, childReq.body);
return async.series(
handlers.map((handler) => async.apply(handler, childReq, res)),
(err) => {
if (err) {
error(err);
return next(err);
}

// Set the child response based on the response of the subform.
SaveAction.childResponse(scope, req, res);
next();
},
);
}
}

Expand Down
Loading