added regex to replace in method

This commit is contained in:
Guillermo Bonet 2022-11-11 14:42:51 +01:00
parent 60cbfc1730
commit 8f248f4425
1 changed files with 7 additions and 1 deletions

View File

@ -105,7 +105,13 @@ class PrintServer {
for (const row of res[0])
args[row.name] = row.value;
try {
let methodPath = this.method.replace('{id}', args.param);
let methodPath = this.method.replace(/{\w+}/g, function(match) {
const params = {id: args.param};
const key = match.substr(1, match.length - 2);
const value = params[key];
return value !== undefined ? value : match;
});
const response = await axios({
method: 'get',
url: `${conf.salix.url}/api/${methodPath}?access_token=${this.token}`,