1
0
Fork 0
mirror of synced 2024-06-01 10:09:48 +12:00
budibase/qa-core/src/public-api/api/apis/TableAPI.ts

41 lines
1.2 KiB
TypeScript
Raw Normal View History

2023-11-18 04:06:01 +13:00
import { Table, SearchInputParams, CreateTableParams } from "../../../types"
import { HeadersInit, Response } from "node-fetch"
import { generateTable } from "../../fixtures/tables"
import BudibasePublicAPIClient from "../BudibasePublicAPIClient"
export default class TableAPI {
headers?: HeadersInit
client: BudibasePublicAPIClient
constructor(client: BudibasePublicAPIClient) {
this.client = client
}
async seed() {
return this.create(generateTable())
}
async create(body: CreateTableParams): Promise<[Response, Table]> {
const [response, json] = await this.client.post(`/tables`, {
body,
})
return [response, json.data]
}
async read(id: string): Promise<[Response, Table]> {
const [response, json] = await this.client.get(`/tables/${id}`)
return [response, json.data]
}
async search(body: SearchInputParams): Promise<[Response, [Table]]> {
const [response, json] = await this.client.post(`/tables/search`, { body })
return [response, json.data]
}
async update(id: string, body: Table): Promise<[Response, Table]> {
const [response, json] = await this.client.put(`/tables/${id}`, { body })
return [response, json.data]
}
}