Import internal
This commit is contained in:
parent
fd414dbe4b
commit
71159e4f4a
|
@ -15,7 +15,7 @@ import { handleRequest } from "../row/external"
|
|||
import { context, events } from "@budibase/backend-core"
|
||||
import { isRows, isSchema, parse } from "../../../utilities/schema"
|
||||
import {
|
||||
AutoReason,
|
||||
BulkImportRequest,
|
||||
Datasource,
|
||||
FieldSchema,
|
||||
Operation,
|
||||
|
@ -374,10 +374,10 @@ export async function destroy(ctx: UserCtx) {
|
|||
return tableToDelete
|
||||
}
|
||||
|
||||
export async function bulkImport(ctx: UserCtx) {
|
||||
export async function bulkImport(ctx: UserCtx<BulkImportRequest>) {
|
||||
const table = await sdk.tables.getTable(ctx.params.tableId)
|
||||
const { rows }: { rows: unknown } = ctx.request.body
|
||||
const schema: unknown = table.schema
|
||||
const { rows } = ctx.request.body
|
||||
const schema = table.schema
|
||||
|
||||
if (!rows || !isRows(rows) || !isSchema(schema)) {
|
||||
ctx.throw(400, "Provided data import information is invalid.")
|
||||
|
|
|
@ -8,6 +8,7 @@ import {
|
|||
import { isExternalTable, isSQL } from "../../../integrations/utils"
|
||||
import { events } from "@budibase/backend-core"
|
||||
import {
|
||||
BulkImportRequest,
|
||||
FetchTablesResponse,
|
||||
SaveTableRequest,
|
||||
SaveTableResponse,
|
||||
|
@ -97,7 +98,7 @@ export async function destroy(ctx: UserCtx) {
|
|||
builderSocket?.emitTableDeletion(ctx, deletedTable)
|
||||
}
|
||||
|
||||
export async function bulkImport(ctx: UserCtx) {
|
||||
export async function bulkImport(ctx: UserCtx<BulkImportRequest>) {
|
||||
const tableId = ctx.params.tableId
|
||||
await pickApi({ tableId }).bulkImport(ctx)
|
||||
// right now we don't trigger anything for bulk import because it
|
||||
|
|
|
@ -10,6 +10,7 @@ import {
|
|||
} from "../../../utilities/rowProcessor"
|
||||
import { runStaticFormulaChecks } from "./bulkFormula"
|
||||
import {
|
||||
BulkImportRequest,
|
||||
RenameColumn,
|
||||
SaveTableRequest,
|
||||
SaveTableResponse,
|
||||
|
@ -206,7 +207,7 @@ export async function destroy(ctx: any) {
|
|||
return tableToDelete
|
||||
}
|
||||
|
||||
export async function bulkImport(ctx: any) {
|
||||
export async function bulkImport(ctx: UserCtx<BulkImportRequest>) {
|
||||
const table = await sdk.tables.getTable(ctx.params.tableId)
|
||||
const { rows, identifierFields } = ctx.request.body
|
||||
await handleDataImport(ctx.user, table, rows, identifierFields)
|
||||
|
|
|
@ -20,7 +20,13 @@ import viewTemplate from "../view/viewBuilder"
|
|||
import { cloneDeep } from "lodash/fp"
|
||||
import { quotas } from "@budibase/pro"
|
||||
import { events, context } from "@budibase/backend-core"
|
||||
import { ContextUser, Datasource, SourceName, Table } from "@budibase/types"
|
||||
import {
|
||||
ContextUser,
|
||||
Datasource,
|
||||
Row,
|
||||
SourceName,
|
||||
Table,
|
||||
} from "@budibase/types"
|
||||
|
||||
export async function clearColumns(table: any, columnNames: any) {
|
||||
const db = context.getAppDB()
|
||||
|
@ -144,12 +150,12 @@ export async function importToRows(
|
|||
}
|
||||
|
||||
export async function handleDataImport(
|
||||
user: any,
|
||||
table: any,
|
||||
rows: any,
|
||||
user: ContextUser,
|
||||
table: Table,
|
||||
rows: Row[],
|
||||
identifierFields: Array<string> = []
|
||||
) {
|
||||
const schema: unknown = table.schema
|
||||
const schema = table.schema
|
||||
|
||||
if (!rows || !isRows(rows) || !isSchema(schema)) {
|
||||
return table
|
||||
|
|
|
@ -24,3 +24,8 @@ export interface SaveTableRequest extends TableRequest {
|
|||
}
|
||||
|
||||
export type SaveTableResponse = Table
|
||||
|
||||
export interface BulkImportRequest {
|
||||
rows: Row[]
|
||||
identifierFields?: Array<string>
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue