1
0
Fork 0
mirror of synced 2024-10-06 04:54:52 +13:00

Fix types

This commit is contained in:
adrinr 2023-03-30 11:30:35 +01:00
parent eb0d445295
commit 8d45e44e2f
4 changed files with 41 additions and 3 deletions

View file

@ -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)
})
})
})
})

View file

@ -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]

View file

@ -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)

View file

@ -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