1
0
Fork 0
mirror of synced 2024-07-01 20:41:03 +12:00

Fixing an issue where old apps did not send up the values of the default parameters, the server should be able to handle this, enrich them in if they aren't there.

This commit is contained in:
mike12345567 2022-01-20 19:06:08 +00:00
parent 6c22ccb149
commit 14ec6ac205
2 changed files with 14 additions and 5 deletions

View file

@ -15,8 +15,6 @@
queryBindings = [...queryBindings, {}]
}
$: console.log(bindings)
function deleteQueryBinding(idx) {
queryBindings.splice(idx, 1)
queryBindings = queryBindings

View file

@ -141,6 +141,16 @@ async function execute(ctx, opts = { rowsOnly: false }) {
const query = await db.get(ctx.params.queryId)
const datasource = await db.get(query.datasourceId)
const enrichedParameters = ctx.request.body.parameters || {}
// make sure parameters are fully enriched with defaults
if (query && query.parameters) {
for (let parameter of query.parameters) {
if (!enrichedParameters[parameter.name]) {
enrichedParameters[parameter.name] = parameter.default
}
}
}
// call the relevant CRUD method on the integration class
try {
const { rows, pagination, extra } = await Runner.run({
@ -149,7 +159,7 @@ async function execute(ctx, opts = { rowsOnly: false }) {
queryVerb: query.queryVerb,
fields: query.fields,
pagination: ctx.request.body.pagination,
parameters: ctx.request.body.parameters,
parameters: enrichedParameters,
transformer: query.transformer,
queryId: ctx.params.queryId,
})
@ -178,8 +188,9 @@ const removeDynamicVariables = async (db, queryId) => {
if (dynamicVariables) {
// delete dynamic variables from the datasource
const newVariables = dynamicVariables.filter(dv => dv.queryId !== queryId)
datasource.config.dynamicVariables = newVariables
datasource.config.dynamicVariables = dynamicVariables.filter(
dv => dv.queryId !== queryId
)
await db.put(datasource)
// invalidate the deleted variables