1
0
Fork 0
mirror of synced 2024-05-16 18:33:53 +12:00
budibase/qa-core/src/public-api/api/apis/TableAPI.ts
2023-11-17 16:06:01 +01:00

41 lines
1.2 KiB
TypeScript

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]
}
}