Add Table endpoints

This commit is contained in:
Pedro Silva 2022-10-17 18:20:40 +01:00
parent 9db8713ffb
commit eb1e85fb46
2 changed files with 40 additions and 0 deletions

View File

@ -1,14 +1,17 @@
import ApplicationApi from "./applications" import ApplicationApi from "./applications"
import AuthApi from "./auth" import AuthApi from "./auth"
import InternalAPIClient from "./InternalAPIClient" import InternalAPIClient from "./InternalAPIClient"
import TablesApi from "./tables"
export default class TestConfiguration<T> { export default class TestConfiguration<T> {
applications: ApplicationApi applications: ApplicationApi
auth: AuthApi auth: AuthApi
context: T context: T
tables: TablesApi
constructor(apiClient: InternalAPIClient) { constructor(apiClient: InternalAPIClient) {
this.applications = new ApplicationApi(apiClient) this.applications = new ApplicationApi(apiClient)
this.tables = new TablesApi(apiClient)
this.auth = new AuthApi(apiClient) this.auth = new AuthApi(apiClient)
this.context = <T>{} this.context = <T>{}
} }

View File

@ -0,0 +1,37 @@
import { Response } from "node-fetch"
import { Table } from "@budibase/types"
import InternalAPIClient from "./InternalAPIClient"
export default class TablesApi {
api: InternalAPIClient
constructor(apiClient: InternalAPIClient) {
this.api = apiClient
}
async getTables(): Promise<[Response, Table[]]> {
const response = await this.api.get(`/tables`)
const json = await response.json()
return [response, json]
}
async getTable(tableId: string): Promise<[Response, Table]> {
const response = await this.api.get(`/tables/${tableId}`)
const json = await response.json()
return [response, json]
}
async createTable(body: any): Promise<[Response, Table]> {
const response = await this.api.post(`/tables`, { body })
const json = await response.json()
return [response, json]
}
async deleteTable(tableId: string, revId: string): Promise<[Response, Table]> {
const response = await this.api.del(`/tables/${tableId}/${revId}`)
const json = await response.json()
return [response, json]
}
}