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