diff --git a/loopback/server/connectors/vn-mysql.js b/loopback/server/connectors/vn-mysql.js index 55cc4edb3..b1c002363 100644 --- a/loopback/server/connectors/vn-mysql.js +++ b/loopback/server/connectors/vn-mysql.js @@ -5,6 +5,38 @@ const EnumFactory = require('loopback-connector-mysql').EnumFactory; const Transaction = require('loopback-connector').Transaction; const fs = require('fs'); +const limitSet = new Set([ + 'save', + 'updateOrCreate', + 'replaceOrCreate', + 'replaceById', + 'update' +]); + +const opOpts = { + update: [ + 'update', + 'replaceById', + // |insert + 'save', + 'updateOrCreate', + 'replaceOrCreate' + ], + delete: [ + 'destroy', + 'destroyAll' + ], + insert: [ + 'create' + ] +}; + +const opMap = new Map(); +for (const op in opOpts) { + for (const met of opOpts[op]) + opMap.set(met, op); +} + class VnMySQL extends MySQL { /** * Promisified version of execute(). @@ -299,41 +331,8 @@ class VnMySQL extends MySQL { const data = ctx.data; const idName = this.idName(model); - const limitSet = new Set([ - 'save', - 'updateOrCreate', - 'replaceOrCreate', - 'replaceById', - 'updateAttributes', - 'update' - ]); - const limit = limitSet.has(method); - const opOpts = { - update: [ - 'update', - 'replaceById', - 'updateAttributes', - // |insert - 'save', - 'updateOrCreate', - 'replaceOrCreate' - ], - delete: [ - 'destroy', - 'destroyAll' - ], - insert: [ - 'create' - ] - }; - - const opMap = new Map(); - for (const op in opOpts) { - for (const met of opOpts[op]) - opMap.set(met, op); - } const op = opMap.get(method); if (!where) { @@ -356,8 +355,7 @@ class VnMySQL extends MySQL { const res = await new Promise(resolve => { const fnArgs = args.slice(0, -2); - fnArgs.push(opts); - fnArgs.push((...args) => resolve(args)); + fnArgs.push(opts, (...args) => resolve(args)); super[method].apply(this, fnArgs); }); @@ -514,7 +512,7 @@ class VnMySQL extends MySQL { // Delete unchanged properties if (oldI) { Object.keys(oldI).forEach(prop => { - if (newI[prop] == oldI[prop]) { + if (newI[prop] === oldI[prop]) { delete newI[prop]; delete oldI[prop]; }