Guard primary display
This commit is contained in:
parent
b7beec6226
commit
ad02581e1d
|
@ -37,6 +37,7 @@ import { jsonFromCsvString } from "../../../utilities/csv"
|
||||||
import { builderSocket } from "../../../websockets"
|
import { builderSocket } from "../../../websockets"
|
||||||
import { cloneDeep } from "lodash"
|
import { cloneDeep } from "lodash"
|
||||||
import {
|
import {
|
||||||
|
canBeDisplayColumn,
|
||||||
helpers,
|
helpers,
|
||||||
PROTECTED_EXTERNAL_COLUMNS,
|
PROTECTED_EXTERNAL_COLUMNS,
|
||||||
PROTECTED_INTERNAL_COLUMNS,
|
PROTECTED_INTERNAL_COLUMNS,
|
||||||
|
@ -67,6 +68,20 @@ function checkDefaultFields(table: Table) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function guardTable(table: Table) {
|
||||||
|
checkDefaultFields(table)
|
||||||
|
|
||||||
|
if (
|
||||||
|
table.primaryDisplay &&
|
||||||
|
!canBeDisplayColumn(table.schema[table.primaryDisplay]?.type)
|
||||||
|
) {
|
||||||
|
throw new HTTPError(
|
||||||
|
`Column "${table.primaryDisplay}" cannot be used as a display type.`,
|
||||||
|
400
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// covers both internal and external
|
// covers both internal and external
|
||||||
export async function fetch(ctx: UserCtx<void, FetchTablesResponse>) {
|
export async function fetch(ctx: UserCtx<void, FetchTablesResponse>) {
|
||||||
const internal = await sdk.tables.getAllInternalTables()
|
const internal = await sdk.tables.getAllInternalTables()
|
||||||
|
@ -111,7 +126,7 @@ export async function save(ctx: UserCtx<SaveTableRequest, SaveTableResponse>) {
|
||||||
|
|
||||||
const isCreate = !table._id
|
const isCreate = !table._id
|
||||||
|
|
||||||
checkDefaultFields(table)
|
guardTable(table)
|
||||||
|
|
||||||
let savedTable: Table
|
let savedTable: Table
|
||||||
if (isCreate) {
|
if (isCreate) {
|
||||||
|
|
|
@ -12,8 +12,8 @@ const allowDisplayColumnByType: Record<FieldType, boolean> = {
|
||||||
[FieldType.AUTO]: true,
|
[FieldType.AUTO]: true,
|
||||||
[FieldType.INTERNAL]: true,
|
[FieldType.INTERNAL]: true,
|
||||||
[FieldType.BARCODEQR]: true,
|
[FieldType.BARCODEQR]: true,
|
||||||
|
|
||||||
[FieldType.BIGINT]: true,
|
[FieldType.BIGINT]: true,
|
||||||
|
|
||||||
[FieldType.BOOLEAN]: false,
|
[FieldType.BOOLEAN]: false,
|
||||||
[FieldType.ARRAY]: false,
|
[FieldType.ARRAY]: false,
|
||||||
[FieldType.ATTACHMENTS]: false,
|
[FieldType.ATTACHMENTS]: false,
|
||||||
|
|
Loading…
Reference in New Issue