Saving progress towards re-working CTX usage in automation steps.
This commit is contained in:
parent
4e294fbcd9
commit
c337a855cc
|
@ -160,8 +160,6 @@ exports.execute = async function (ctx) {
|
|||
)
|
||||
|
||||
const integration = new Integration(datasource.config)
|
||||
console.log(query)
|
||||
// ctx.body = {}
|
||||
// call the relevant CRUD method on the integration class
|
||||
ctx.body = formatResponse(await integration[query.queryVerb](enrichedQuery))
|
||||
// cleanup
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
const queryController = require("../../api/controllers/query")
|
||||
const { buildCtx } = require("./utils")
|
||||
|
||||
exports.definition = {
|
||||
name: "External Data Connector",
|
||||
|
@ -54,25 +55,20 @@ exports.run = async function ({ inputs, appId, emitter }) {
|
|||
|
||||
const { queryId, ...rest } = inputs.query
|
||||
|
||||
const ctx = {
|
||||
const ctx = buildCtx(appId, emitter, {
|
||||
body: {
|
||||
parameters: rest,
|
||||
},
|
||||
params: {
|
||||
queryId,
|
||||
},
|
||||
request: {
|
||||
body: {
|
||||
parameters: rest,
|
||||
},
|
||||
},
|
||||
appId,
|
||||
eventEmitter: emitter,
|
||||
}
|
||||
|
||||
await queryController.execute(ctx)
|
||||
})
|
||||
|
||||
try {
|
||||
await queryController.execute(ctx)
|
||||
return {
|
||||
response: ctx.body,
|
||||
success: ctx.status === 200,
|
||||
success: true,
|
||||
}
|
||||
} catch (err) {
|
||||
return {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
const scriptController = require("../../api/controllers/script")
|
||||
const { buildCtx } = require("./utils")
|
||||
|
||||
exports.definition = {
|
||||
name: "JS Scripting",
|
||||
|
@ -23,8 +24,7 @@ exports.definition = {
|
|||
properties: {
|
||||
value: {
|
||||
type: "string",
|
||||
description:
|
||||
"The result of the last statement of the executed script.",
|
||||
description: "The result of the return statement",
|
||||
},
|
||||
success: {
|
||||
type: "boolean",
|
||||
|
@ -46,21 +46,17 @@ exports.run = async function ({ inputs, appId, context, emitter }) {
|
|||
}
|
||||
}
|
||||
|
||||
const ctx = {
|
||||
request: {
|
||||
body: {
|
||||
script: inputs.code,
|
||||
context,
|
||||
},
|
||||
const ctx = buildCtx(appId, emitter, {
|
||||
body: {
|
||||
script: inputs.code,
|
||||
context,
|
||||
},
|
||||
user: { appId },
|
||||
eventEmitter: emitter,
|
||||
}
|
||||
})
|
||||
|
||||
try {
|
||||
await scriptController.execute(ctx)
|
||||
return {
|
||||
success: ctx.status === 200,
|
||||
success: true,
|
||||
value: ctx.body,
|
||||
}
|
||||
} catch (err) {
|
||||
|
|
|
@ -16,3 +16,24 @@ exports.getFetchResponse = async fetched => {
|
|||
}
|
||||
return { status, message }
|
||||
}
|
||||
|
||||
// need to make sure all ctx structures have the
|
||||
// throw added to them, so that controllers don't
|
||||
// throw a ctx.throw undefined when error occurs
|
||||
exports.buildCtx = (appId, emitter, { body, params } = {}) => {
|
||||
const ctx = {
|
||||
appId,
|
||||
user: { appId },
|
||||
eventEmitter: emitter,
|
||||
throw: (code, error) => {
|
||||
throw error
|
||||
},
|
||||
}
|
||||
if (body) {
|
||||
ctx.request = { body }
|
||||
}
|
||||
if (params) {
|
||||
ctx.params = params
|
||||
}
|
||||
return ctx
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue