Some quick fixes to allow custom verbs.

This commit is contained in:
mike12345567 2021-02-02 17:28:11 +00:00
parent a0c8c20782
commit 2d82969350
5 changed files with 20 additions and 1 deletions

View File

@ -119,6 +119,16 @@ export const getBackendUiStore = () => {
return json return json
}, },
save: async (datasourceId, query) => { save: async (datasourceId, query) => {
const integrations = get(store).integrations
const dataSource = get(store).datasources.filter(ds => ds._id === datasourceId)
// check if readable attribute is found
if (dataSource.length !== 0) {
const integration = integrations[dataSource[0].source]
const readable = integration.query[query.queryVerb].readable
if (readable) {
query.readable = readable
}
}
query.datasourceId = datasourceId query.datasourceId = datasourceId
const response = await api.post(`/api/queries`, query) const response = await api.post(`/api/queries`, query)
const json = await response.json() const json = await response.json()

View File

@ -35,7 +35,7 @@
return [...acc, ...viewsArr] return [...acc, ...viewsArr]
}, []) }, [])
$: queries = $backendUiStore.queries $: queries = $backendUiStore.queries
.filter(query => query.queryVerb === "read") .filter(query => query.queryVerb === "read" || query.readable)
.map(query => ({ .map(query => ({
label: query.name, label: query.name,
name: query.name, name: query.name,

View File

@ -26,6 +26,7 @@ function generateQueryValidation() {
name: Joi.string().required(), name: Joi.string().required(),
fields: Joi.object().required(), fields: Joi.object().required(),
datasourceId: Joi.string().required(), datasourceId: Joi.string().required(),
readable: Joi.boolean(),
parameters: Joi.array().items(Joi.object({ parameters: Joi.array().items(Joi.object({
name: Joi.string(), name: Joi.string(),
default: Joi.string() default: Joi.string()

View File

@ -37,6 +37,7 @@ const SCHEMA = {
read: { read: {
type: QUERY_TYPES.FIELDS, type: QUERY_TYPES.FIELDS,
customisable: true, customisable: true,
readable: true,
fields: { fields: {
table: { table: {
type: FIELD_TYPES.STRING, type: FIELD_TYPES.STRING,
@ -50,6 +51,7 @@ const SCHEMA = {
scan: { scan: {
type: QUERY_TYPES.FIELDS, type: QUERY_TYPES.FIELDS,
customisable: true, customisable: true,
readable: true,
fields: { fields: {
table: { table: {
type: FIELD_TYPES.STRING, type: FIELD_TYPES.STRING,
@ -63,6 +65,7 @@ const SCHEMA = {
get: { get: {
type: QUERY_TYPES.FIELDS, type: QUERY_TYPES.FIELDS,
customisable: true, customisable: true,
readable: true,
fields: { fields: {
table: { table: {
type: FIELD_TYPES.STRING, type: FIELD_TYPES.STRING,

View File

@ -302,6 +302,11 @@ describe("Cover a few complex use cases", () => {
expect(validity).toBe(true) expect(validity).toBe(true)
}) })
it("should make sure object functions check out valid", () => {
const validity = isValid("{{ JSONstringify obj }}")
expect(validity).toBe(true)
})
it("should be able to solve an example from docs", async () => { it("should be able to solve an example from docs", async () => {
const output = await processString(`{{first ( split "a-b-c" "-") 2}}`, {}) const output = await processString(`{{first ( split "a-b-c" "-") 2}}`, {})
expect(output).toBe(`a,b`) expect(output).toBe(`a,b`)