Skip to content

Commit

Permalink
✨ Handle not required to required prop update on dynamic types
Browse files Browse the repository at this point in the history
  • Loading branch information
andremacedopv committed Jan 16, 2023
1 parent d661e55 commit aaa4134
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions transactions/updateAssetType.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
)

// ? Update tag name?
// TODO: Handle not required -> required

// UpdateAssetType is the transaction which updates a dynamic Asset Type
var UpdateAssetType = Transaction{
Expand Down Expand Up @@ -145,7 +144,6 @@ func handleProps(assetType assets.AssetType, propMap []interface{}) (assets.Asse
if deleteVal && !hasProp {
return assetType, nil, errors.WrapError(err, "attempt to delete inexistent prop")
} else if deleteVal && hasProp {
// ? Should you be able to delete a required prop?
for i, prop := range propObj {
if prop.Tag == tagValue {
if prop.IsKey {
Expand All @@ -156,8 +154,7 @@ func handleProps(assetType assets.AssetType, propMap []interface{}) (assets.Asse
}
} else if !hasProp && !deleteVal {
// ? Should you be able to create a isKey prop?
// TODO: Handle verification if assets exists on require
required, err := CheckValue(v, false, "boolean", "required")
required, err := CheckValue(v["required"], false, "boolean", "required")
if err != nil {
return assetType, nil, errors.WrapError(err, "invalid required info")
}
Expand All @@ -180,9 +177,32 @@ func handleProps(assetType assets.AssetType, propMap []interface{}) (assets.Asse
}
propObj = append(propObj, newProp)
} else {
// TODO: Handle required/isKey prop
// ? Should you be able to update a isKey prop?
for i, prop := range propObj {
if prop.Tag == tagValue {
required, err := CheckValue(v["required"], false, "boolean", "required")
if err != nil {
return assetType, nil, errors.WrapError(err, "invalid required info")
}
requiredVal := required.(bool)

defaultValue, ok := v["defaultValue"]
if !ok {
defaultValue = prop.DefaultValue
}

if !prop.Required && requiredVal {
if defaultValue == nil {
return assetType, nil, errors.NewCCError("required prop must have a default value in case of existing assets", http.StatusBadRequest)
}

requiredValue := map[string]interface{}{
"tag": tagValue,
"defaultValue": defaultValue,
}
requiredValues = append(requiredValues, requiredValue)
}

updatedProp, err := handlePropUpdate(prop, v)
if err != nil {
return assetType, nil, errors.WrapError(err, "failed to update prop")
Expand Down

0 comments on commit aaa4134

Please sign in to comment.