Responding to PR feedback.
This commit is contained in:
parent
0d9f257cc2
commit
a0e9abb95b
|
@ -18,6 +18,8 @@ import {
|
|||
AutoReason,
|
||||
Datasource,
|
||||
FieldSchema,
|
||||
ImportRowsRequest,
|
||||
ImportRowsResponse,
|
||||
Operation,
|
||||
QueryJson,
|
||||
RelationshipType,
|
||||
|
@ -374,7 +376,7 @@ export async function destroy(ctx: UserCtx) {
|
|||
return tableToDelete
|
||||
}
|
||||
|
||||
export async function bulkImport(ctx: UserCtx) {
|
||||
export async function bulkImport(ctx: UserCtx<ImportRowsRequest, ImportRowsResponse>) {
|
||||
const table = await sdk.tables.getTable(ctx.params.tableId)
|
||||
const { rows }: { rows: unknown } = ctx.request.body
|
||||
const schema: unknown = table.schema
|
||||
|
|
|
@ -6,9 +6,11 @@ import {
|
|||
validate as validateSchema,
|
||||
} from "../../../utilities/schema"
|
||||
import { isExternalTable, isSQL } from "../../../integrations/utils"
|
||||
import { context, events } from "@budibase/backend-core"
|
||||
import { events } from "@budibase/backend-core"
|
||||
import {
|
||||
FetchTablesResponse,
|
||||
ImportRowsRequest,
|
||||
ImportRowsResponse,
|
||||
SaveTableRequest,
|
||||
SaveTableResponse,
|
||||
Table,
|
||||
|
@ -97,16 +99,13 @@ export async function destroy(ctx: UserCtx) {
|
|||
builderSocket?.emitTableDeletion(ctx, deletedTable)
|
||||
}
|
||||
|
||||
export async function bulkImport(ctx: UserCtx) {
|
||||
export async function bulkImport(ctx: UserCtx<ImportRowsRequest, ImportRowsResponse>) {
|
||||
const tableId = ctx.params.tableId
|
||||
let db = context.getAppDB()
|
||||
let tableBefore = await sdk.tables.getTable(tableId)
|
||||
let tableAfter = await pickApi({ tableId }).bulkImport(ctx)
|
||||
|
||||
if (!isEqual(tableBefore, tableAfter)) {
|
||||
await db.put(tableAfter)
|
||||
ctx.eventEmitter &&
|
||||
ctx.eventEmitter.emitTable(`table:save`, ctx.appId, tableAfter)
|
||||
await sdk.tables.saveTable(tableAfter)
|
||||
}
|
||||
|
||||
// right now we don't trigger anything for bulk import because it
|
||||
|
|
|
@ -10,6 +10,8 @@ import {
|
|||
} from "../../../utilities/rowProcessor"
|
||||
import { runStaticFormulaChecks } from "./bulkFormula"
|
||||
import {
|
||||
ImportRowsRequest,
|
||||
ImportRowsResponse,
|
||||
RenameColumn,
|
||||
SaveTableRequest,
|
||||
SaveTableResponse,
|
||||
|
@ -206,7 +208,7 @@ export async function destroy(ctx: any) {
|
|||
return tableToDelete
|
||||
}
|
||||
|
||||
export async function bulkImport(ctx: any) {
|
||||
export async function bulkImport(ctx: UserCtx<ImportRowsRequest, ImportRowsResponse>) {
|
||||
const table = await sdk.tables.getTable(ctx.params.tableId)
|
||||
const { rows, identifierFields } = ctx.request.body
|
||||
await handleDataImport(ctx.user, table, rows, identifierFields)
|
||||
|
|
|
@ -200,29 +200,16 @@ describe("/tables", () => {
|
|||
},
|
||||
})
|
||||
|
||||
let response = await request
|
||||
.post(`/api/${table._id}/rows`)
|
||||
.send({})
|
||||
.set(config.defaultHeaders())
|
||||
.expect(200)
|
||||
let row = await config.api.row.save(table._id!, {})
|
||||
expect(row.autoId).toEqual(1)
|
||||
|
||||
expect(response.body.autoId).toEqual(1)
|
||||
await config.api.row.bulkImport(table._id!, {
|
||||
rows: [{ autoId: 2 }],
|
||||
identifierFields: [],
|
||||
})
|
||||
|
||||
await request
|
||||
.post(`/api/tables/${table._id}/import`)
|
||||
.send({
|
||||
rows: [{ autoId: 2 }],
|
||||
})
|
||||
.set(config.defaultHeaders())
|
||||
.expect(200)
|
||||
|
||||
response = await request
|
||||
.post(`/api/${table._id}/rows`)
|
||||
.send({})
|
||||
.set(config.defaultHeaders())
|
||||
.expect(200)
|
||||
|
||||
expect(response.body.autoId).toEqual(3)
|
||||
row = await config.api.row.save(table._id!, {})
|
||||
expect(row.autoId).toEqual(3)
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
@ -4,6 +4,8 @@ import {
|
|||
Row,
|
||||
ValidateResponse,
|
||||
ExportRowsRequest,
|
||||
ImportRowsRequest,
|
||||
ImportRowsResponse,
|
||||
} from "@budibase/types"
|
||||
import TestConfiguration from "../TestConfiguration"
|
||||
import { TestAPI } from "./base"
|
||||
|
@ -123,6 +125,19 @@ export class RowAPI extends TestAPI {
|
|||
return request
|
||||
}
|
||||
|
||||
bulkImport = async (
|
||||
tableId: string,
|
||||
body: ImportRowsRequest,
|
||||
{ expectStatus } = { expectStatus: 200 }
|
||||
): Promise<ImportRowsResponse> => {
|
||||
let request = this.request
|
||||
.post(`/api/tables/${tableId}/import`)
|
||||
.send(body)
|
||||
.set(this.config.defaultHeaders())
|
||||
.expect(expectStatus)
|
||||
return (await request).body
|
||||
}
|
||||
|
||||
search = async (
|
||||
sourceId: string,
|
||||
{ expectStatus } = { expectStatus: 200 }
|
||||
|
|
|
@ -37,3 +37,12 @@ export interface ExportRowsRequest {
|
|||
}
|
||||
|
||||
export type ExportRowsResponse = ReadStream
|
||||
|
||||
export type ImportRowsRequest = {
|
||||
rows: Row[]
|
||||
identifierFields: string[]
|
||||
}
|
||||
|
||||
export type ImportRowsResponse = {
|
||||
message: string
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue