Fix types
This commit is contained in:
parent
eb0d445295
commit
8d45e44e2f
|
@ -59,5 +59,39 @@ describe("utils", () => {
|
|||
])
|
||||
})
|
||||
})
|
||||
|
||||
it("can import data without a specific user performing the action", async () => {
|
||||
await config.doInContext(config.appId, async () => {
|
||||
const table = await config.createTable({
|
||||
name: "table",
|
||||
type: "table",
|
||||
schema: {
|
||||
autoId: {
|
||||
name: "autoId",
|
||||
type: FieldType.NUMBER,
|
||||
subtype: AutoFieldSubTypes.AUTO_ID,
|
||||
autocolumn: true,
|
||||
constraints: {
|
||||
type: FieldType.NUMBER,
|
||||
presence: true,
|
||||
},
|
||||
},
|
||||
name: {
|
||||
name: "name",
|
||||
type: FieldType.STRING,
|
||||
constraints: {
|
||||
type: FieldType.STRING,
|
||||
presence: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
const data = [{ name: "Alice" }, { name: "Bob" }, { name: "Claire" }]
|
||||
|
||||
const result = importToRows(data, table)
|
||||
expect(result).toHaveLength(3)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -105,7 +105,11 @@ export function makeSureTableUpToDate(table: any, tableToSave: any) {
|
|||
return tableToSave
|
||||
}
|
||||
|
||||
export function importToRows(data: any[], table: Table, user: ContextUser) {
|
||||
export function importToRows(
|
||||
data: any[],
|
||||
table: Table,
|
||||
user: ContextUser | null = null
|
||||
) {
|
||||
let finalData: any = []
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
let row = data[i]
|
||||
|
|
|
@ -34,7 +34,7 @@ function syncLastIds(table: Table, rowCount: number) {
|
|||
})
|
||||
}
|
||||
|
||||
function tableImport(table: Table, data: Row) {
|
||||
function tableImport(table: Table, data: Row[]) {
|
||||
const cloneTable = cloneDeep(table)
|
||||
const rowDocs = importToRows(data, cloneTable)
|
||||
syncLastIds(cloneTable, rowDocs.length)
|
||||
|
|
|
@ -131,7 +131,7 @@ export function coerce(row: any, type: string) {
|
|||
* @returns {object} the row which has been prepared to be written to the DB.
|
||||
*/
|
||||
export function inputProcessing(
|
||||
user: ContextUser,
|
||||
user: ContextUser | null,
|
||||
table: Table,
|
||||
row: Row,
|
||||
opts?: AutoColumnProcessingOpts
|
||||
|
|
Loading…
Reference in New Issue