diff --git a/internal/chore/handler.go b/internal/chore/handler.go index 9667385..4000d84 100644 --- a/internal/chore/handler.go +++ b/internal/chore/handler.go @@ -231,7 +231,13 @@ func (h *Handler) createChore(c *gin.Context) { return } stringNotificationMetadata := string(notificationMetadataBytes) - + if stringNotificationMetadata == "null" { + // TODO: Clean this update after 0.1.38.. there is a bug in the frontend that sends null instead of empty object + // this is a temporary fix to avoid breaking changes + // once change we can change notificationMetadataBytes to var notificationMetadataMap map[string]interface{} to gernerate empty object + // and remove this check + stringNotificationMetadata = "{}" + } var stringLabels *string if len(choreReq.Labels) > 0 { var escapedLabels []string @@ -243,6 +249,7 @@ func (h *Handler) createChore(c *gin.Context) { stringLabels = &labels } createdChore := &chModel.Chore{ + Name: choreReq.Name, FrequencyType: choreReq.FrequencyType, Frequency: choreReq.Frequency, @@ -263,7 +270,6 @@ func (h *Handler) createChore(c *gin.Context) { CompletionWindow: choreReq.CompletionWindow, Description: choreReq.Description, SubTasks: choreReq.SubTasks, - Priority: choreReq.Priority, } id, err := h.choreRepo.CreateChore(c, createdChore) createdChore.ID = id @@ -464,6 +470,13 @@ func (h *Handler) editChore(c *gin.Context) { return } stringNotificationMetadata := string(notificationMetadataBytes) + if stringNotificationMetadata == "null" { + // TODO: Clean this update after 0.1.38.. there is a bug in the frontend that sends null instead of empty object + // this is a temporary fix to avoid breaking changes + // once change we can change notificationMetadataBytes to var notificationMetadataMap map[string]interface{} to gernerate empty object + // and remove this check + stringNotificationMetadata = "{}" + } // escape special characters in labels and store them as a string : var stringLabels *string @@ -547,7 +560,6 @@ func (h *Handler) editChore(c *gin.Context) { if choreReq.SubTasks == nil { choreReq.SubTasks = &[]stModel.SubTask{} } - // check what subtask needed to be removed: for _, existedSubTask := range *oldChore.SubTasks { found := false for _, newSubTask := range *choreReq.SubTasks { @@ -560,16 +572,14 @@ func (h *Handler) editChore(c *gin.Context) { ToBeRemoved = append(ToBeRemoved, existedSubTask) } } - // check what subtask needed to be added or updated: + for _, newSubTask := range *choreReq.SubTasks { found := false newSubTask.ChoreID = oldChore.ID for _, existedSubTask := range *oldChore.SubTasks { if existedSubTask.ID == newSubTask.ID { - if existedSubTask.Name != newSubTask.Name || - existedSubTask.OrderID != newSubTask.OrderID || - existedSubTask.ParentId != newSubTask.ParentId { + if existedSubTask.Name != newSubTask.Name || existedSubTask.OrderID != newSubTask.OrderID { // there is a change in the subtask, update it break } diff --git a/migrations/20250314_fix_notification_metadata_experiment_modal.go b/migrations/20250314_fix_notification_metadata_experiment_modal.go new file mode 100644 index 0000000..9226494 --- /dev/null +++ b/migrations/20250314_fix_notification_metadata_experiment_modal.go @@ -0,0 +1,43 @@ +package migrations + +import ( + "context" + + "donetick.com/core/logging" + "gorm.io/gorm" +) + +type MigrateFixNotificationMetadataExperimentModal20241212 struct{} + +func (m MigrateFixNotificationMetadataExperimentModal20241212) ID() string { + return "20250314_fix_notification_metadata_experiment_modal" +} + +func (m MigrateFixNotificationMetadataExperimentModal20241212) Description() string { + return `Fix notification metadata for experiment modal, where notification metadata is a null string 'null' to empty json {}` +} + +func (m MigrateFixNotificationMetadataExperimentModal20241212) Down(ctx context.Context, db *gorm.DB) error { + return nil +} + +func (m MigrateFixNotificationMetadataExperimentModal20241212) Up(ctx context.Context, db *gorm.DB) error { + log := logging.FromContext(ctx) + + // Start a transaction + return db.Transaction(func(tx *gorm.DB) error { + // Update all chore where notification metadata is a null stirng 'null' to empty json {}: + + if err := tx.Table("chores").Where("notification_metadata = ?", "null").Update("notification_metadata", "{}").Error; err != nil { + log.Errorf("Failed to update chores with null notification metadata: %v", err) + return err + } + + return nil + }) +} + +// Register this migration +func init() { + Register(MigrateFixNotificationMetadataExperimentModal20241212{}) +}