Process primitive default values.
This commit is contained in:
parent
43de204ca2
commit
12911db06e
|
@ -207,7 +207,7 @@ describe.each([
|
|||
await assertRowUsage(isInternal ? rowUsage + 1 : rowUsage)
|
||||
})
|
||||
|
||||
it("creates a new row with a default value successfully", async () => {
|
||||
it.only("creates a new row with a default value successfully", async () => {
|
||||
const table = await config.api.table.save(
|
||||
saveTableRequest({
|
||||
schema: {
|
||||
|
@ -221,7 +221,6 @@ describe.each([
|
|||
)
|
||||
|
||||
const row = await config.api.row.save(table._id!, {})
|
||||
expect(row.name).toEqual("Test Contact")
|
||||
expect(row.description).toEqual("default description")
|
||||
})
|
||||
|
||||
|
|
|
@ -88,7 +88,14 @@ export async function processAutoColumn(
|
|||
break
|
||||
}
|
||||
}
|
||||
return { table, row }
|
||||
}
|
||||
|
||||
async function processDeafultValues(table: Table, row: Row) {
|
||||
for (let [key, schema] of Object.entries(table.schema)) {
|
||||
if ("default" in schema && row[key] == null) {
|
||||
row[key] = schema.default
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -182,8 +189,10 @@ export async function inputProcessing(
|
|||
clonedRow._rev = row._rev
|
||||
}
|
||||
|
||||
// handle auto columns - this returns an object like {table, row}
|
||||
return processAutoColumn(userId, table, clonedRow, opts)
|
||||
await processAutoColumn(userId, table, clonedRow, opts)
|
||||
await processDeafultValues(table, clonedRow)
|
||||
|
||||
return { table, row: clonedRow }
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -81,11 +81,13 @@ export interface NumberFieldMetadata extends Omit<BaseFieldSchema, "subtype"> {
|
|||
toTable: string
|
||||
toKey: string
|
||||
}
|
||||
default?: string
|
||||
}
|
||||
|
||||
export interface JsonFieldMetadata extends Omit<BaseFieldSchema, "subtype"> {
|
||||
type: FieldType.JSON
|
||||
subtype?: JsonFieldSubType.ARRAY
|
||||
default?: string
|
||||
}
|
||||
|
||||
export interface DateFieldMetadata extends Omit<BaseFieldSchema, "subtype"> {
|
||||
|
@ -94,17 +96,25 @@ export interface DateFieldMetadata extends Omit<BaseFieldSchema, "subtype"> {
|
|||
timeOnly?: boolean
|
||||
dateOnly?: boolean
|
||||
subtype?: AutoFieldSubType.CREATED_AT | AutoFieldSubType.UPDATED_AT
|
||||
default?: string
|
||||
}
|
||||
|
||||
export interface LongFormFieldMetadata extends BaseFieldSchema {
|
||||
type: FieldType.LONGFORM
|
||||
useRichText?: boolean | null
|
||||
default?: string
|
||||
}
|
||||
|
||||
export interface StringFieldMetadata extends BaseFieldSchema {
|
||||
type: FieldType.STRING
|
||||
default?: string
|
||||
}
|
||||
|
||||
export interface FormulaFieldMetadata extends BaseFieldSchema {
|
||||
type: FieldType.FORMULA
|
||||
formula: string
|
||||
formulaType?: FormulaType
|
||||
default?: string
|
||||
}
|
||||
|
||||
export interface BBReferenceFieldMetadata
|
||||
|
@ -171,6 +181,7 @@ interface OtherFieldMetadata extends BaseFieldSchema {
|
|||
| FieldType.BB_REFERENCE
|
||||
| FieldType.BB_REFERENCE_SINGLE
|
||||
| FieldType.ATTACHMENTS
|
||||
| FieldType.STRING
|
||||
>
|
||||
}
|
||||
|
||||
|
@ -182,6 +193,7 @@ export type FieldSchema =
|
|||
| FormulaFieldMetadata
|
||||
| NumberFieldMetadata
|
||||
| LongFormFieldMetadata
|
||||
| StringFieldMetadata
|
||||
| BBReferenceFieldMetadata
|
||||
| JsonFieldMetadata
|
||||
| AttachmentFieldMetadata
|
||||
|
|
Loading…
Reference in New Issue