Fix promises
This commit is contained in:
parent
55d4e2dffe
commit
5715f7e9c1
|
@ -84,14 +84,18 @@ export async function fetch(ctx: UserCtx<void, FetchTablesResponse>) {
|
|||
}
|
||||
})
|
||||
|
||||
ctx.body = [...internal, ...external].map(sdk.tables.enrichViewSchemas)
|
||||
const result: FetchTablesResponse = []
|
||||
for (const table of [...internal, ...external]) {
|
||||
result.push(await sdk.tables.enrichViewSchemas(table))
|
||||
}
|
||||
ctx.body = result //
|
||||
}
|
||||
|
||||
export async function find(ctx: UserCtx<void, TableResponse>) {
|
||||
const tableId = ctx.params.tableId
|
||||
const table = await sdk.tables.getTable(tableId)
|
||||
|
||||
const result = sdk.tables.enrichViewSchemas({
|
||||
const result = await sdk.tables.enrichViewSchemas({
|
||||
...table,
|
||||
schema: await sdk.tables.enrichRelationshipSchema(table.schema),
|
||||
})
|
||||
|
@ -109,7 +113,7 @@ export async function save(ctx: UserCtx<SaveTableRequest, SaveTableResponse>) {
|
|||
const api = pickApi({ table })
|
||||
let savedTable = await api.save(ctx, renaming)
|
||||
if (!table._id) {
|
||||
savedTable = sdk.tables.enrichViewSchemas(savedTable)
|
||||
savedTable = await sdk.tables.enrichViewSchemas(savedTable)
|
||||
await events.table.created(savedTable)
|
||||
} else {
|
||||
await events.table.updated(savedTable)
|
||||
|
|
|
@ -189,16 +189,19 @@ export async function enrichRelationshipSchema(
|
|||
return result
|
||||
}
|
||||
|
||||
export function enrichViewSchemas(table: Table): TableResponse {
|
||||
export async function enrichViewSchemas(table: Table): Promise<TableResponse> {
|
||||
const views = []
|
||||
for (const view of Object.values(table.views ?? [])) {
|
||||
if (sdk.views.isV2(view)) {
|
||||
views.push(await sdk.views.enrichSchema(view, table.schema))
|
||||
} else views.push(view)
|
||||
}
|
||||
|
||||
return {
|
||||
...table,
|
||||
views: Object.values(table.views ?? [])
|
||||
.map(v =>
|
||||
sdk.views.isV2(v) ? sdk.views.enrichSchema(v, table.schema) : v
|
||||
)
|
||||
.reduce((p, v) => {
|
||||
p[v.name!] = v
|
||||
return p
|
||||
}, {} as TableViewsResponse),
|
||||
views: views.reduce((p, v) => {
|
||||
p[v.name!] = v
|
||||
return p
|
||||
}, {} as TableViewsResponse),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ describe("table sdk", () => {
|
|||
const view1 = getTable()
|
||||
const view2 = getTable()
|
||||
const view3 = getTable()
|
||||
const res = sdk.tables.enrichViewSchemas({
|
||||
const res = await sdk.tables.enrichViewSchemas({
|
||||
...basicTable,
|
||||
views: {
|
||||
[view1.name]: view1,
|
||||
|
|
|
@ -60,7 +60,7 @@ describe("table sdk", () => {
|
|||
},
|
||||
}
|
||||
|
||||
describe("enrichViewSchemas", () => {
|
||||
describe("enrichSchema", () => {
|
||||
it("should fetch the default schema if not overridden", async () => {
|
||||
const tableId = basicTable._id!
|
||||
const view: ViewV2 = {
|
||||
|
|
Loading…
Reference in New Issue