mirror of
https://github.com/pocketbase/pocketbase.git
synced 2025-02-09 12:14:03 +02:00
skip number validator on zero-default
This commit is contained in:
parent
3b9a9df171
commit
341bcc4a0e
@ -135,7 +135,7 @@ func (validator *RecordDataValidator) checkFieldValue(field *schema.SchemaField,
|
||||
func (validator *RecordDataValidator) checkTextValue(field *schema.SchemaField, value any) error {
|
||||
val, _ := value.(string)
|
||||
if val == "" {
|
||||
return nil // nothing to check
|
||||
return nil // nothing to check (skip zero-defaults)
|
||||
}
|
||||
|
||||
options, _ := field.Options.(*schema.TextOptions)
|
||||
@ -159,11 +159,11 @@ func (validator *RecordDataValidator) checkTextValue(field *schema.SchemaField,
|
||||
}
|
||||
|
||||
func (validator *RecordDataValidator) checkNumberValue(field *schema.SchemaField, value any) error {
|
||||
if value == nil {
|
||||
return nil // nothing to check
|
||||
val, _ := value.(float64)
|
||||
if val == 0 {
|
||||
return nil // nothing to check (skip zero-defaults)
|
||||
}
|
||||
|
||||
val, _ := value.(float64)
|
||||
options, _ := field.Options.(*schema.NumberOptions)
|
||||
|
||||
if options.Min != nil && val < *options.Min {
|
||||
|
@ -168,7 +168,7 @@ func TestRecordDataValidatorValidateNumber(t *testing.T) {
|
||||
// create new test collection
|
||||
collection := &models.Collection{}
|
||||
collection.Name = "validate_test"
|
||||
min := 0.0
|
||||
min := 2.0
|
||||
max := 150.0
|
||||
collection.Schema = schema.NewSchema(
|
||||
&schema.SchemaField{
|
||||
@ -244,6 +244,15 @@ func TestRecordDataValidatorValidateNumber(t *testing.T) {
|
||||
nil,
|
||||
[]string{"field3"},
|
||||
},
|
||||
{
|
||||
"(number) check min with zero-default",
|
||||
map[string]any{
|
||||
"field2": 1,
|
||||
"field3": 0,
|
||||
},
|
||||
nil,
|
||||
[]string{},
|
||||
},
|
||||
{
|
||||
"(number) check max constraint",
|
||||
map[string]any{
|
||||
|
Loading…
x
Reference in New Issue
Block a user