Add api types
This commit is contained in:
parent
7d17717895
commit
21b9bf36fd
|
@ -14,16 +14,20 @@ import { events, HTTPError } from "@budibase/backend-core"
|
|||
import {
|
||||
BulkImportRequest,
|
||||
BulkImportResponse,
|
||||
CsvToJsonRequest,
|
||||
CsvToJsonResponse,
|
||||
FetchTablesResponse,
|
||||
MigrateRequest,
|
||||
MigrateResponse,
|
||||
Row,
|
||||
SaveTableRequest,
|
||||
SaveTableResponse,
|
||||
Table,
|
||||
TableResponse,
|
||||
TableSourceType,
|
||||
UserCtx,
|
||||
ValidateNewTableImportRequest,
|
||||
ValidateTableImportRequest,
|
||||
ValidateTableImportResponse,
|
||||
} from "@budibase/types"
|
||||
import sdk from "../../../sdk"
|
||||
import { jsonFromCsvString } from "../../../utilities/csv"
|
||||
|
@ -144,7 +148,9 @@ export async function bulkImport(
|
|||
ctx.body = { message: `Bulk rows created.` }
|
||||
}
|
||||
|
||||
export async function csvToJson(ctx: UserCtx) {
|
||||
export async function csvToJson(
|
||||
ctx: UserCtx<CsvToJsonRequest, CsvToJsonResponse>
|
||||
) {
|
||||
const { csvString } = ctx.request.body
|
||||
|
||||
const result = await jsonFromCsvString(csvString)
|
||||
|
@ -153,8 +159,10 @@ export async function csvToJson(ctx: UserCtx) {
|
|||
ctx.body = result
|
||||
}
|
||||
|
||||
export async function validateNewTableImport(ctx: UserCtx) {
|
||||
const { rows, schema }: { rows: unknown; schema: unknown } = ctx.request.body
|
||||
export async function validateNewTableImport(
|
||||
ctx: UserCtx<ValidateNewTableImportRequest, ValidateTableImportResponse>
|
||||
) {
|
||||
const { rows, schema } = ctx.request.body
|
||||
|
||||
if (isRows(rows) && isSchema(schema)) {
|
||||
ctx.status = 200
|
||||
|
@ -164,8 +172,10 @@ export async function validateNewTableImport(ctx: UserCtx) {
|
|||
}
|
||||
}
|
||||
|
||||
export async function validateExistingTableImport(ctx: UserCtx) {
|
||||
const { rows, tableId }: { rows: Row[]; tableId?: string } = ctx.request.body
|
||||
export async function validateExistingTableImport(
|
||||
ctx: UserCtx<ValidateTableImportRequest, ValidateTableImportResponse>
|
||||
) {
|
||||
const { rows, tableId } = ctx.request.body
|
||||
|
||||
let schema = null
|
||||
if (tableId) {
|
||||
|
|
|
@ -37,7 +37,7 @@ export interface PaginatedSearchRowResponse
|
|||
PaginationResponse {}
|
||||
|
||||
export interface ExportRowsRequest {
|
||||
rows: string[]
|
||||
rows?: string[]
|
||||
columns?: string[]
|
||||
query?: SearchFilters
|
||||
sort?: string
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Row, Table, TableRequest, View } from "../../../documents"
|
||||
import { Row, Table, TableRequest, TableSchema, View } from "../../../documents"
|
||||
import { ViewV2Enriched } from "../../../sdk"
|
||||
|
||||
export type TableViewsResponse = { [key: string]: View | ViewV2Enriched }
|
||||
|
@ -32,3 +32,28 @@ export interface MigrateRequest {
|
|||
export interface MigrateResponse {
|
||||
message: string
|
||||
}
|
||||
|
||||
export interface ValidateNewTableImportRequest {
|
||||
rows: Row[]
|
||||
schema: TableSchema
|
||||
}
|
||||
|
||||
export interface ValidateTableImportRequest {
|
||||
tableId?: string
|
||||
rows: Row[]
|
||||
}
|
||||
|
||||
export interface ValidateTableImportResponse {
|
||||
schemaValidation: {
|
||||
[field: string]: boolean
|
||||
}
|
||||
allValid: boolean
|
||||
invalidColumns: Array<string>
|
||||
errors: Record<string, string>
|
||||
}
|
||||
|
||||
export interface CsvToJsonRequest {
|
||||
csvString: string
|
||||
}
|
||||
|
||||
export type CsvToJsonResponse = any[]
|
||||
|
|
Loading…
Reference in New Issue