refs #5036 corrections
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Alexandre Riera 2023-01-27 08:52:33 +01:00
parent d69b204c4c
commit a12f629690
1 changed files with 34 additions and 36 deletions

View File

@ -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];
}