fix(vn-model): rewriteMethod
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
a477bb32ad
commit
7311e79273
|
@ -1,6 +1,8 @@
|
||||||
|
|
||||||
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
||||||
const UserError = require('vn-loopback/util/user-error');
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
|
const utils = require('loopback/lib/utils');
|
||||||
|
const {util} = require('webpack');
|
||||||
|
|
||||||
module.exports = function(Self) {
|
module.exports = function(Self) {
|
||||||
Self.ParameterizedSQL = ParameterizedSQL;
|
Self.ParameterizedSQL = ParameterizedSQL;
|
||||||
|
@ -164,23 +166,21 @@ module.exports = function(Self) {
|
||||||
|
|
||||||
function rewriteMethod(methodName) {
|
function rewriteMethod(methodName) {
|
||||||
const realMethod = this[methodName];
|
const realMethod = this[methodName];
|
||||||
return async(data, options, cb) => {
|
return function(...args) {
|
||||||
if (options instanceof Function) {
|
let cb;
|
||||||
cb = options;
|
const lastArg = args[args.length - 1];
|
||||||
options = null;
|
if (lastArg instanceof Function) {
|
||||||
}
|
cb = lastArg;
|
||||||
|
args.pop();
|
||||||
|
} else
|
||||||
|
cb = utils.createPromiseCallback();
|
||||||
|
|
||||||
try {
|
args.push(function(err, res) {
|
||||||
const result = await realMethod.call(this, data, options);
|
if (err) err = replaceErr(err, replaceErrFunc);
|
||||||
|
cb(err, res);
|
||||||
if (cb) cb(null, result);
|
});
|
||||||
else return result;
|
realMethod.apply(this, args);
|
||||||
} catch (err) {
|
return cb.promise;
|
||||||
let myErr = replaceErr(err, replaceErrFunc);
|
|
||||||
if (cb) cb(myErr);
|
|
||||||
else
|
|
||||||
throw myErr;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue