Update query endpoints

This commit is contained in:
Andrew Kingston 2024-12-05 15:46:23 +00:00
parent 8992a1d902
commit feee4032d5
No known key found for this signature in database
1 changed files with 19 additions and 21 deletions

View File

@ -1,9 +1,15 @@
import { import {
DeleteQueryResponse,
ExecuteQueryRequest, ExecuteQueryRequest,
ExecuteQueryResponse, ExecuteV2QueryResponse,
FetchQueriesResponse,
FindQueryResponse,
ImportRestQueryRequest,
ImportRestQueryResponse,
PreviewQueryRequest, PreviewQueryRequest,
PreviewQueryResponse, PreviewQueryResponse,
Query, SaveQueryRequest,
SaveQueryResponse,
} from "@budibase/types" } from "@budibase/types"
import { BaseAPIClient } from "./types" import { BaseAPIClient } from "./types"
@ -11,15 +17,15 @@ export interface QueryEndpoints {
executeQuery: ( executeQuery: (
queryId: string, queryId: string,
opts?: ExecuteQueryRequest opts?: ExecuteQueryRequest
) => Promise<ExecuteQueryResponse | Record<string, any>[]> ) => Promise<ExecuteV2QueryResponse>
fetchQueryDefinition: (queryId: string) => Promise<Query> fetchQueryDefinition: (queryId: string) => Promise<FindQueryResponse>
getQueries: () => Promise<Query[]> getQueries: () => Promise<FetchQueriesResponse>
saveQuery: (query: Query) => Promise<Query> saveQuery: (query: SaveQueryRequest) => Promise<SaveQueryResponse>
deleteQuery: (id: string, rev: string) => Promise<void> deleteQuery: (id: string, rev: string) => Promise<DeleteQueryResponse>
previewQuery: (query: PreviewQueryRequest) => Promise<PreviewQueryResponse> previewQuery: (query: PreviewQueryRequest) => Promise<PreviewQueryResponse>
importQueries: (
// Missing request or response types data: ImportRestQueryRequest
importQueries: (datasourceId: string, data: any) => Promise<any> ) => Promise<ImportRestQueryResponse>
} }
export const buildQueryEndpoints = (API: BaseAPIClient): QueryEndpoints => ({ export const buildQueryEndpoints = (API: BaseAPIClient): QueryEndpoints => ({
@ -30,10 +36,7 @@ export const buildQueryEndpoints = (API: BaseAPIClient): QueryEndpoints => ({
* @param parameters parameters for the query * @param parameters parameters for the query
*/ */
executeQuery: async (queryId, { pagination, parameters } = {}) => { executeQuery: async (queryId, { pagination, parameters } = {}) => {
return await API.post< return await API.post<ExecuteQueryRequest, ExecuteV2QueryResponse>({
ExecuteQueryRequest,
ExecuteQueryResponse | Record<string, any>[]
>({
url: `/api/v2/queries/${queryId}`, url: `/api/v2/queries/${queryId}`,
body: { body: {
parameters, parameters,
@ -86,16 +89,11 @@ export const buildQueryEndpoints = (API: BaseAPIClient): QueryEndpoints => ({
/** /**
* Imports a set of queries into a certain datasource * Imports a set of queries into a certain datasource
* @param datasourceId the datasource ID to import queries into
* @param data the data string of the content to import
*/ */
importQueries: async (datasourceId, data) => { importQueries: async data => {
return await API.post({ return await API.post({
url: "/api/queries/import", url: "/api/queries/import",
body: { body: data,
datasourceId,
data,
},
}) })
}, },