refs #4550 Added URL params

This commit is contained in:
Guillermo Bonet 2022-12-12 20:04:51 +01:00
parent 1a379e8091
commit 2552049afb
2 changed files with 21 additions and 6 deletions

View File

@ -43,12 +43,12 @@ class PrintServer {
}
}
async getToken() {
const salix = this.conf.salix
const salix = this.conf.salix;
let response = await axios.post(`${salix.url}/api/Accounts/login`, {
user: salix.user,
password: salix.password
});
this.token = response.data.token
this.token = response.data.token;
}
async onDbError(err) {
switch(err.code) {
@ -107,21 +107,35 @@ class PrintServer {
for (const row of res[0])
args[row.name] = row.value;
try {
// Path params
const usedParams = new Set();
let methodPath = this.method.replace(/{\w+}/g, function(match) {
const key = match.substr(1, match.length - 2);
const value = args[key];
usedParams.add(key);
return value !== undefined ? value : match;
});
// URL params
let params = {
access_token: this.token,
userFk: printJob.userFk
};
for (const key in args) {
if (!usedParams.has(key))
params[key] = args[key];
}
const urlParams = new URLSearchParams(params);
// Request
const response = await axios({
method: 'get',
url: `${conf.salix.url}/api/${methodPath}?access_token=${this.token}`,
url: `${conf.salix.url}/api/${methodPath}?${urlParams.toString()}`,
responseType: 'arraybuffer',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/pdf'
}
});
});
this.pdfData = response.data
}
catch (err) {

View File

@ -3,7 +3,8 @@ SELECT pq.id,
p.name printer,
pqa.name arg,
pqa.value,
r.method
r.method,
pq.workerFk userFk
FROM printQueue pq
JOIN report r ON r.id = pq.reportFk
JOIN printQueueArgs pqa ON pqa.printQueueFk = pq.id