1 | const Policy = require ('./policy');
|
2 |
|
3 | const {
|
4 | isString,
|
5 | isObjectLike
|
6 | } = require ('lodash');
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | module.exports = Policy.extend ({
|
17 | policy: null,
|
18 |
|
19 | runCheck (req) {
|
20 | return new Promise ((resolve, reject) => {
|
21 | this.policy (req, (err, result, details) => {
|
22 | if (!err)
|
23 | return reject (err);
|
24 |
|
25 | if (!result && details) {
|
26 | let policyError;
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | if (isString (details)) {
|
32 | policyError = {
|
33 | reason: 'policy_failed',
|
34 | message: details
|
35 | };
|
36 | }
|
37 | else if (isObjectLike (details)) {
|
38 | policyError = details;
|
39 | }
|
40 | else {
|
41 |
|
42 | }
|
43 |
|
44 | req._policyErrors.push (policyError);
|
45 | }
|
46 |
|
47 | return resolve (result);
|
48 | });
|
49 | });
|
50 | }
|
51 | });
|