fix(admin): standardize resource initialization and lists
This commit is contained in:
@@ -242,6 +242,7 @@ func PrepareResourceValues(ctx *gin.Context, model any, allowedFields []string,
|
||||
if err := ctx.ShouldBindJSON(&input); err != nil || len(input) == 0 {
|
||||
return nil, errors.New("invalid resource payload")
|
||||
}
|
||||
stripClientManagedCreateFields(input)
|
||||
values, err := ResolveResourceRelations(input, allowedFields, relations, true)
|
||||
if err != nil || len(values) == 0 {
|
||||
return nil, errors.New("invalid resource payload")
|
||||
@@ -249,6 +250,13 @@ func PrepareResourceValues(ctx *gin.Context, model any, allowedFields []string,
|
||||
return values, nil
|
||||
}
|
||||
|
||||
// stripClientManagedCreateFields ensures database IDs and public identities are
|
||||
// always generated by the logic layer for newly created records.
|
||||
func stripClientManagedCreateFields(input map[string]any) {
|
||||
delete(input, "id")
|
||||
delete(input, "identity")
|
||||
}
|
||||
|
||||
// ValidateResourceValues enforces invariants that database nullability and
|
||||
// frontend form metadata cannot express.
|
||||
func ValidateResourceValues(model any, values map[string]any, creating bool) error {
|
||||
|
||||
Reference in New Issue
Block a user