1
0
Fork 0
mirror of synced 2024-05-16 18:33:53 +12:00
budibase/qa-core/src/public-api/api/apis/RowAPI.ts
Adria Navarro 92f411bf77 Prettier
2023-11-20 21:48:49 +01:00

57 lines
1.4 KiB
TypeScript

import { CreateRowParams, Row, SearchInputParams, State } from "../../../types"
import { HeadersInit, Response } from "node-fetch"
import BudibasePublicAPIClient from "../BudibasePublicAPIClient"
import * as fixtures from "../../fixtures"
export default class RowAPI {
client: BudibasePublicAPIClient
headers?: HeadersInit
state: State
constructor(client: BudibasePublicAPIClient, state: State) {
this.state = state
this.client = client
}
async seed(tableId: string) {
return this.create(fixtures.rows.generateRow({ tableId }))
}
async create(body: CreateRowParams): Promise<[Response, Row]> {
const [response, json] = await this.client.post(
`/tables/${this.state.tableId}/rows`,
{
body,
}
)
return [response, json.data]
}
async read(id: string): Promise<[Response, Row]> {
const [response, json] = await this.client.get(
`/tables/${this.state.tableId}/rows/${id}`
)
return [response, json.data]
}
async search(body: SearchInputParams): Promise<[Response, [Row]]> {
const [response, json] = await this.client.post(
`/tables/${this.state.tableId}/rows/search`,
{ body }
)
return [response, json.data]
}
async update(id: string, body: Row): Promise<[Response, Row]> {
const [response, json] = await this.client.put(
`/tables/${this.state.tableId}/rows/${id}`,
{
body,
}
)
return [response, json.data]
}
}