(app App, optTypes ...string)
| 448 | } |
| 449 | |
| 450 | func validateCollectionId(app App, optTypes ...string) validation.RuleFunc { |
| 451 | return func(value any) error { |
| 452 | id, _ := value.(string) |
| 453 | if id == "" { |
| 454 | return nil |
| 455 | } |
| 456 | |
| 457 | collection := &Collection{} |
| 458 | if err := app.ModelQuery(collection).Model(id, collection); err != nil { |
| 459 | return validation.NewError("validation_invalid_collection_id", "Missing or invalid collection.") |
| 460 | } |
| 461 | |
| 462 | if len(optTypes) > 0 && !slices.Contains(optTypes, collection.Type) { |
| 463 | return validation.NewError( |
| 464 | "validation_invalid_collection_type", |
| 465 | fmt.Sprintf("Invalid collection type - must be %s.", strings.Join(optTypes, ", ")), |
| 466 | ) |
| 467 | } |
| 468 | |
| 469 | return nil |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | func validateRecordId(app App, collectionNameOrId string) validation.RuleFunc { |
| 474 | return func(value any) error { |
no test coverage detected
searching dependent graphs…