fixed issue with redis models

This commit is contained in:
2024-08-06 13:11:55 -04:00
parent e38504457c
commit 84db245f4a
20 changed files with 558 additions and 323 deletions
+20 -10
View File
@@ -12,9 +12,13 @@ function ModelPs(model){
}
function publish(prop, res, req){
if(!['add', 'create', 'update', 'remove'].includes(prop)) return;
try{
if(!['add', 'create', 'update', 'remove'].includes(prop)) return;
ps.publish(`model:${Model.name}:${prop}:${getIndex(res, req)}`, res);
ps.publish(`model:${Model.name}:${prop}:${getIndex(res, req)}`, res);
}catch(error){
console.log('ModelPs.publish ERROR', error)
}
}
return new Proxy(model, {
@@ -28,16 +32,22 @@ function ModelPs(model){
const targetValue = Reflect.get(target, propKey, receiver);
if (typeof targetValue === 'function') {
return function(...args){
try{
// let res = targetValue.apply(this, args); // (A)
let res = Reflect.apply(targetValue, this, args);
if(targetValue.constructor.name === 'AsyncFunction'){
res.then(function(res){
publish(propKey, res, ...args);
});
}else{
publish(propKey, res, ...args)
var res = Reflect.apply(targetValue, this, args);
if(targetValue.constructor.name === 'AsyncFunction'){
res.then(function(res){
publish(propKey, res, ...args);
}).catch(function(error){
console.log('toDo, publish errors...')
});
}else{
publish(propKey, res, ...args)
}
return res;
}catch(error){
console.log("grrrr")
}
return res;
}
} else {
return targetValue;