fix: refs #6276 loggable & userId
gitea/salix/pipeline/pr-dev There was a failure building this commit
Details
gitea/salix/pipeline/pr-dev There was a failure building this commit
Details
This commit is contained in:
parent
2940c68516
commit
8ad69a62b9
|
@ -1,6 +1,7 @@
|
||||||
const LoopBackContext = require('loopback-context');
|
const LoopBackContext = require('loopback-context');
|
||||||
async function handleObserve(ctx) {
|
async function handleObserve(ctx) {
|
||||||
ctx.options.httpCtx = LoopBackContext.getCurrentContext();
|
const httpCtx = LoopBackContext.getCurrentContext();
|
||||||
|
ctx.options.userId = httpCtx?.active?.accessToken?.userId;
|
||||||
}
|
}
|
||||||
module.exports = function(Self) {
|
module.exports = function(Self) {
|
||||||
let Mixin = {
|
let Mixin = {
|
||||||
|
|
|
@ -275,7 +275,7 @@ class VnMySQL extends MySQL {
|
||||||
}
|
}
|
||||||
|
|
||||||
invokeMethod(method, args, model, ctx, opts, cb) {
|
invokeMethod(method, args, model, ctx, opts, cb) {
|
||||||
if (!this.isLoggable(model))
|
if (!this.isLoggable(model) && !opts?.userId)
|
||||||
return super[method].apply(this, args);
|
return super[method].apply(this, args);
|
||||||
|
|
||||||
this.invokeMethodP(method, [...args], model, ctx, opts)
|
this.invokeMethodP(method, [...args], model, ctx, opts)
|
||||||
|
@ -287,11 +287,11 @@ class VnMySQL extends MySQL {
|
||||||
let tx;
|
let tx;
|
||||||
if (!opts.transaction) {
|
if (!opts.transaction) {
|
||||||
tx = await Transaction.begin(this, {});
|
tx = await Transaction.begin(this, {});
|
||||||
opts = Object.assign({transaction: tx, httpCtx: opts.httpCtx}, opts);
|
opts = Object.assign({transaction: tx}, opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const userId = opts.httpCtx && opts.httpCtx.active?.accessToken?.userId;
|
const {userId} = opts;
|
||||||
if (userId) {
|
if (userId) {
|
||||||
const user = await Model.app.models.VnUser.findById(userId, {fields: ['name']}, opts);
|
const user = await Model.app.models.VnUser.findById(userId, {fields: ['name']}, opts);
|
||||||
await this.executeP(`CALL account.myUser_loginWithName(?)`, [user.name], opts);
|
await this.executeP(`CALL account.myUser_loginWithName(?)`, [user.name], opts);
|
||||||
|
|
|
@ -43,7 +43,7 @@ module.exports = Self => {
|
||||||
Self.updateTracking = async(ctx, saleFk, originalQuantity, code, isChecked, buyFk, isScanned = null, options) => {
|
Self.updateTracking = async(ctx, saleFk, originalQuantity, code, isChecked, buyFk, isScanned = null, options) => {
|
||||||
const userId = ctx.req.accessToken.userId;
|
const userId = ctx.req.accessToken.userId;
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const myOptions = {};
|
const myOptions = {userId};
|
||||||
let tx;
|
let tx;
|
||||||
|
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
|
|
Loading…
Reference in New Issue