From 7311e7927353497ee8382f1dd044ce4c2181d0dc Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 6 Jun 2023 15:07:54 +0200 Subject: [PATCH] fix(vn-model): rewriteMethod --- loopback/common/models/vn-model.js | 32 +++++++++++++++--------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/loopback/common/models/vn-model.js b/loopback/common/models/vn-model.js index f469e893a..37328247b 100644 --- a/loopback/common/models/vn-model.js +++ b/loopback/common/models/vn-model.js @@ -1,6 +1,8 @@ const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; const UserError = require('vn-loopback/util/user-error'); +const utils = require('loopback/lib/utils'); +const {util} = require('webpack'); module.exports = function(Self) { Self.ParameterizedSQL = ParameterizedSQL; @@ -164,23 +166,21 @@ module.exports = function(Self) { function rewriteMethod(methodName) { const realMethod = this[methodName]; - return async(data, options, cb) => { - if (options instanceof Function) { - cb = options; - options = null; - } + return function(...args) { + let cb; + const lastArg = args[args.length - 1]; + if (lastArg instanceof Function) { + cb = lastArg; + args.pop(); + } else + cb = utils.createPromiseCallback(); - try { - const result = await realMethod.call(this, data, options); - - if (cb) cb(null, result); - else return result; - } catch (err) { - let myErr = replaceErr(err, replaceErrFunc); - if (cb) cb(myErr); - else - throw myErr; - } + args.push(function(err, res) { + if (err) err = replaceErr(err, replaceErrFunc); + cb(err, res); + }); + realMethod.apply(this, args); + return cb.promise; }; }