Skip to content

Commit

Permalink
Merge branch 'master' into 'master'
Browse files Browse the repository at this point in the history
adding functionName to custom methods for checking

See merge request oecloud.io/oe-common-mixins!6
  • Loading branch information
Atul committed Jun 3, 2020
2 parents 0b8c8f5 + 39d5b32 commit 454022f
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ module.exports = function (app) {
function callWithVersion(fn, model, id, data, options, cb) {
var Model = loopback.findModel(model);
if (!isMixinEnabled(model, 'VersionMixin')) {
if (fn.name === 'updateOrCreate' || fn.name === 'save') {
var functionName = fn.functionName || fn.name;
if (functionName === 'updateOrCreate' || functionName === 'save') {
return fn.call(this, model, data, options, cb);
}

Expand Down Expand Up @@ -109,6 +110,7 @@ module.exports = function (app) {
_updateAttributes[this.name] = connector.updateAttributes;
connector.updateAttributes = function (model, id, data, options, cb) {
var fn = _updateAttributes[this.dataSource.name];
fn.functionName = 'updateAttributes';
callWithVersion.call(this, fn, model, id, data, options, cb);
};
}
Expand All @@ -118,6 +120,7 @@ module.exports = function (app) {
_save[this.name] = connector.save;
connector.save = function (model, data, options, cb) {
var fn = _save[this.dataSource.name];
fn.functionName = 'save';
if ( !cb && typeof options === 'function' ) {
cb = options;
options = {};
Expand All @@ -133,6 +136,7 @@ module.exports = function (app) {
_destroyAll[this.name] = connector.destroyAll;
connector.destroyAll = function (model, where, options, cb) {
var fn = _destroyAll[this.dataSource.name];
fn.functionName = 'destroyAll';
convertDestroyToUpdate.call(this, fn, model, where, options, cb);
};
}
Expand All @@ -141,6 +145,7 @@ module.exports = function (app) {
_replaceById[this.name] = connector.replaceById;
connector.replaceById = function (model, id, data, options, cb) {
var fn = _replaceById[this.dataSource.name];
fn.functionName = 'replaceById';
callWithVersion.call(this, fn, model, id, data, options, cb);
};
}
Expand All @@ -158,6 +163,7 @@ module.exports = function (app) {
_upsert[this.name] = connector.updateOrCreate;
connector.updateOrCreate = function (model, data, options, cb) {
var fn = _upsert[this.dataSource.name];
fn.functionName = 'updateOrCreate';
var Model = loopback.findModel(model);
var idField = oeutils.idName(Model);
callWithVersion.call(this, fn, model, data[idField], data, options, cb);
Expand Down Expand Up @@ -216,5 +222,3 @@ module.exports = function (app) {
return _embedCreate.call(this, targetModelData, options, cb);
};
};


0 comments on commit 454022f

Please sign in to comment.