Typing table save
This commit is contained in:
parent
dbbe9ff0ac
commit
082166d8f9
|
@ -22,6 +22,8 @@ import {
|
||||||
QueryJson,
|
QueryJson,
|
||||||
RelationshipType,
|
RelationshipType,
|
||||||
RenameColumn,
|
RenameColumn,
|
||||||
|
SaveTableRequest,
|
||||||
|
SaveTableResponse,
|
||||||
Table,
|
Table,
|
||||||
TableRequest,
|
TableRequest,
|
||||||
UserCtx,
|
UserCtx,
|
||||||
|
@ -198,8 +200,8 @@ function isRelationshipSetup(column: FieldSchema) {
|
||||||
return column.foreignKey || column.through
|
return column.foreignKey || column.through
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function save(ctx: UserCtx) {
|
export async function save(ctx: UserCtx<SaveTableRequest, SaveTableResponse>) {
|
||||||
const inputs: TableRequest = ctx.request.body
|
const inputs = ctx.request.body
|
||||||
const renamed = inputs?._rename
|
const renamed = inputs?._rename
|
||||||
// can't do this right now
|
// can't do this right now
|
||||||
delete inputs.rows
|
delete inputs.rows
|
||||||
|
|
|
@ -9,6 +9,8 @@ import { isExternalTable, isSQL } from "../../../integrations/utils"
|
||||||
import { events } from "@budibase/backend-core"
|
import { events } from "@budibase/backend-core"
|
||||||
import {
|
import {
|
||||||
FetchTablesResponse,
|
FetchTablesResponse,
|
||||||
|
SaveTableResponse,
|
||||||
|
SaveTableRequest,
|
||||||
Table,
|
Table,
|
||||||
TableResponse,
|
TableResponse,
|
||||||
UserCtx,
|
UserCtx,
|
||||||
|
@ -60,7 +62,7 @@ export async function find(ctx: UserCtx<void, TableResponse>) {
|
||||||
ctx.body = sdk.tables.enrichViewSchemas(table)
|
ctx.body = sdk.tables.enrichViewSchemas(table)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function save(ctx: UserCtx) {
|
export async function save(ctx: UserCtx<SaveTableRequest, SaveTableResponse>) {
|
||||||
const appId = ctx.appId
|
const appId = ctx.appId
|
||||||
const table = ctx.request.body
|
const table = ctx.request.body
|
||||||
const isImport = table.rows
|
const isImport = table.rows
|
||||||
|
|
|
@ -9,7 +9,15 @@ import {
|
||||||
fixAutoColumnSubType,
|
fixAutoColumnSubType,
|
||||||
} from "../../../utilities/rowProcessor"
|
} from "../../../utilities/rowProcessor"
|
||||||
import { runStaticFormulaChecks } from "./bulkFormula"
|
import { runStaticFormulaChecks } from "./bulkFormula"
|
||||||
import { Table, ViewV2 } from "@budibase/types"
|
import {
|
||||||
|
SaveTableRequest,
|
||||||
|
SaveTableResponse,
|
||||||
|
Table,
|
||||||
|
TableRequest,
|
||||||
|
UserCtx,
|
||||||
|
ViewStatisticsSchema,
|
||||||
|
ViewV2,
|
||||||
|
} from "@budibase/types"
|
||||||
import { quotas } from "@budibase/pro"
|
import { quotas } from "@budibase/pro"
|
||||||
import isEqual from "lodash/isEqual"
|
import isEqual from "lodash/isEqual"
|
||||||
import { cloneDeep } from "lodash/fp"
|
import { cloneDeep } from "lodash/fp"
|
||||||
|
@ -33,10 +41,10 @@ function checkAutoColumns(table: Table, oldTable?: Table) {
|
||||||
return table
|
return table
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function save(ctx: any) {
|
export async function save(ctx: UserCtx<SaveTableRequest, SaveTableResponse>) {
|
||||||
const db = context.getAppDB()
|
const db = context.getAppDB()
|
||||||
const { rows, ...rest } = ctx.request.body
|
const { rows, ...rest } = ctx.request.body
|
||||||
let tableToSave = {
|
let tableToSave: TableRequest = {
|
||||||
type: "table",
|
type: "table",
|
||||||
_id: generateTableID(),
|
_id: generateTableID(),
|
||||||
views: {},
|
views: {},
|
||||||
|
@ -80,7 +88,7 @@ export async function save(ctx: any) {
|
||||||
let { _rename } = tableToSave
|
let { _rename } = tableToSave
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
if (_rename && _rename.old === _rename.updated) {
|
if (_rename && _rename.old === _rename.updated) {
|
||||||
_rename = null
|
_rename = undefined
|
||||||
delete tableToSave._rename
|
delete tableToSave._rename
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,7 +113,11 @@ export async function save(ctx: any) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tableView.schema.group || tableView.schema.field) continue
|
if (
|
||||||
|
(tableView.schema as ViewStatisticsSchema).group ||
|
||||||
|
tableView.schema.field
|
||||||
|
)
|
||||||
|
continue
|
||||||
tableView.schema = tableToSave.schema
|
tableView.schema = tableToSave.schema
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,7 +132,7 @@ export async function save(ctx: any) {
|
||||||
tableToSave._rev = linkResp._rev
|
tableToSave._rev = linkResp._rev
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
ctx.throw(400, err)
|
ctx.throw(400, err as string)
|
||||||
}
|
}
|
||||||
|
|
||||||
// don't perform any updates until relationships have been
|
// don't perform any updates until relationships have been
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
import { Table, TableSchema, View, ViewV2 } from "../../../documents"
|
import {
|
||||||
|
Table,
|
||||||
|
TableRequest,
|
||||||
|
TableSchema,
|
||||||
|
View,
|
||||||
|
ViewV2,
|
||||||
|
} from "../../../documents"
|
||||||
|
|
||||||
interface ViewV2Response extends ViewV2 {
|
interface ViewV2Response extends ViewV2 {
|
||||||
schema: TableSchema
|
schema: TableSchema
|
||||||
|
@ -11,3 +17,7 @@ export interface TableResponse extends Table {
|
||||||
}
|
}
|
||||||
|
|
||||||
export type FetchTablesResponse = TableResponse[]
|
export type FetchTablesResponse = TableResponse[]
|
||||||
|
|
||||||
|
export interface SaveTableRequest extends TableRequest {}
|
||||||
|
|
||||||
|
export type SaveTableResponse = Table
|
||||||
|
|
Loading…
Reference in New Issue