From feee4032d527f4b9e91e6e3ba5c2613db7d17252 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 5 Dec 2024 15:46:23 +0000 Subject: [PATCH] Update query endpoints --- packages/frontend-core/src/api/queries.ts | 40 +++++++++++------------ 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/packages/frontend-core/src/api/queries.ts b/packages/frontend-core/src/api/queries.ts index 02b1dc38ec..b088e4487c 100644 --- a/packages/frontend-core/src/api/queries.ts +++ b/packages/frontend-core/src/api/queries.ts @@ -1,9 +1,15 @@ import { + DeleteQueryResponse, ExecuteQueryRequest, - ExecuteQueryResponse, + ExecuteV2QueryResponse, + FetchQueriesResponse, + FindQueryResponse, + ImportRestQueryRequest, + ImportRestQueryResponse, PreviewQueryRequest, PreviewQueryResponse, - Query, + SaveQueryRequest, + SaveQueryResponse, } from "@budibase/types" import { BaseAPIClient } from "./types" @@ -11,15 +17,15 @@ export interface QueryEndpoints { executeQuery: ( queryId: string, opts?: ExecuteQueryRequest - ) => Promise[]> - fetchQueryDefinition: (queryId: string) => Promise - getQueries: () => Promise - saveQuery: (query: Query) => Promise - deleteQuery: (id: string, rev: string) => Promise + ) => Promise + fetchQueryDefinition: (queryId: string) => Promise + getQueries: () => Promise + saveQuery: (query: SaveQueryRequest) => Promise + deleteQuery: (id: string, rev: string) => Promise previewQuery: (query: PreviewQueryRequest) => Promise - - // Missing request or response types - importQueries: (datasourceId: string, data: any) => Promise + importQueries: ( + data: ImportRestQueryRequest + ) => Promise } export const buildQueryEndpoints = (API: BaseAPIClient): QueryEndpoints => ({ @@ -30,10 +36,7 @@ export const buildQueryEndpoints = (API: BaseAPIClient): QueryEndpoints => ({ * @param parameters parameters for the query */ executeQuery: async (queryId, { pagination, parameters } = {}) => { - return await API.post< - ExecuteQueryRequest, - ExecuteQueryResponse | Record[] - >({ + return await API.post({ url: `/api/v2/queries/${queryId}`, body: { parameters, @@ -86,16 +89,11 @@ export const buildQueryEndpoints = (API: BaseAPIClient): QueryEndpoints => ({ /** * 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({ url: "/api/queries/import", - body: { - datasourceId, - data, - }, + body: data, }) },