1 | const Action = require ('./action');
|
2 |
|
3 | /**
|
4 | * @class LegacyFunctionAction
|
5 | *
|
6 | * Adapter that converts a legacy function(req, res) to an AbstractAction for
|
7 | * integration into Blueprint framework.
|
8 | */
|
9 | module.exports = Action.extend ({
|
10 | execute (req, res) {
|
11 | return new Promise ((resolve, reject) => {
|
12 | let len = this.action.length;
|
13 |
|
14 | switch (len) {
|
15 | case 2: {
|
16 | // The action does not have a callback parameter.
|
17 | this.action (req, res);
|
18 | resolve (null);
|
19 | break;
|
20 | }
|
21 |
|
22 | case 3: {
|
23 | // The action has a callback parameter.
|
24 | this.action (req, res, (err) => {
|
25 | if (!err) return resolve (null);
|
26 | return reject (err);
|
27 | });
|
28 |
|
29 | break;
|
30 | }
|
31 | }
|
32 | });
|
33 | }
|
34 | });
|