fix(merge_component): 🐛 fix unsavable after accept

This commit is contained in:
pakintada@gmail.com 2024-03-15 17:41:32 +07:00
parent 2afdc1e10d
commit ef9cf48fc1
4 changed files with 42 additions and 57 deletions

View file

@ -484,7 +484,7 @@ func (d *Data) GetRecipe01ByProductCode(filename, countryID, productCode string)
func (d *Data) SetValuesToRecipe(base_recipe []models.Recipe01, recipe models.Recipe01) {
not_found := false
global_idx := 0
// global_idx := 0
for index, v := range base_recipe {
if v.ProductCode == recipe.ProductCode {
// Log.Debug("SetValuesToRecipe", zap.Any("old", v), zap.Any("new", recipe))
@ -529,12 +529,13 @@ func (d *Data) SetValuesToRecipe(base_recipe []models.Recipe01, recipe models.Re
}
} else {
not_found = true
global_idx = index
// global_idx = index
}
}
if not_found {
base_recipe[global_idx+1] = recipe
// base_recipe[global_idx+1] = recipe
base_recipe = append(base_recipe, recipe)
}
}
@ -1033,6 +1034,9 @@ func (d *Data) SortRecipe(countryID, filename string, sort_by string) (error, []
// merge
func (d *Data) Merge(country string, filename string, attr string, changeKey string, updated interface{}) (string, error) {
d.taoLogger.Log.Debug("check on merge request", zap.Any("args", []string{
country, filename, attr, changeKey,
}))
// change this to switch case
if attr == "Recipe" {
@ -1041,7 +1045,14 @@ func (d *Data) Merge(country string, filename string, attr string, changeKey str
if updated == nil {
return "UpdatedValueError", fmt.Errorf("updated value is nil")
}
return d.MergeRecipeNoCache(country, filename, updated.(models.Recipe01))
// type assertion
updatedModel, ok := updated.(models.Recipe01)
d.taoLogger.Log.Debug("check on update model", zap.Any("appliedFromClient", updatedModel))
if !ok {
return d.MergeRecipeNoCache(country, filename, updatedModel)
}
}
return "NotKnownAttr", nil