Skip to content

Commit

Permalink
fix: cast field input to Decimal
Browse files Browse the repository at this point in the history
  • Loading branch information
kennedybaird committed Aug 20, 2024
1 parent 19a734c commit f2b1187
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/core/src/fields/types/decimal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,14 @@ function parseDecimalValueOption (meta: FieldData, value: string, name: string)
return decimal
}

export function decimal <ListTypeInfo extends BaseListTypeInfo>(config: DecimalFieldConfig<ListTypeInfo> = {}): FieldTypeFunc<ListTypeInfo> {
function safeParseDecimalValueOption (meta: FieldData, value: string | null | undefined, name: string): Decimal | null | undefined {
if (value === null || value === undefined) {
return value
}
return parseDecimalValueOption(meta, value, name)
}

export function decimal <ListTypeInfo extends BaseListTypeInfo> (config: DecimalFieldConfig<ListTypeInfo> = {}): FieldTypeFunc<ListTypeInfo> {
const {
isIndexed,
precision = 18,
Expand Down Expand Up @@ -107,7 +114,7 @@ export function decimal <ListTypeInfo extends BaseListTypeInfo>(config: DecimalF
} = makeValidateHook(meta, config, ({ resolvedData, operation, addValidationError }) => {
if (operation === 'delete') return

const value: Decimal | null | undefined = resolvedData[meta.fieldKey]
const value = safeParseDecimalValueOption(meta, resolvedData[meta.fieldKey], 'value')
if (value != null) {
if (min !== undefined && value.lessThan(min)) {
addValidationError(`value must be greater than or equal to ${min}`)
Expand Down

0 comments on commit f2b1187

Please sign in to comment.