I am trying to call a certain function based on variables that I pass in (scamId and actorId), and the only issue is that when I try to pass in intent2 as an argument, it does not seem to find what it needs from my repository. I got this little function builder script from How to execute a JavaScript function when I have its name as a string and I have used it for some other things and it works great, but I'm not sure how to pass in intent2 and have it create the function correctly. It works when the statement is not overloaded like if intent2 = "stuff", but not when I have it in the format below.
For example, return statement would be equivalent to if everything worked correctly -
return this.intentS1A1Repository.findOne({where: { intent: intentBase }});
const info = this
// how can I format this intent2 so that it works?
const intent2 = {
where:
{ intent: intentBase }
}
const getIntent = "intentS" + scamId + "A" + actorId + "Repository.findOne";
await getIntentFunctionBuilder(getIntent, info, intent2);
async function getIntentFunctionBuilder(functionName: string, context: any, args: any) {
args = Array.prototype.slice.call(arguments, 2);
var namespaces = functionName.split(".");
var func = namespaces.pop();
for(var i = 0; i < namespaces.length; i++) {
context = context[namespaces[i]];
}
return await context[func].apply(context, args);
}
Any help would be much appreciated!