commit
acb6bbe180
2 changed files with 60 additions and 7 deletions
|
@ -231,7 +231,13 @@ func (h *Handler) createChore(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
stringNotificationMetadata := string(notificationMetadataBytes)
|
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
|
var stringLabels *string
|
||||||
if len(choreReq.Labels) > 0 {
|
if len(choreReq.Labels) > 0 {
|
||||||
var escapedLabels []string
|
var escapedLabels []string
|
||||||
|
@ -243,6 +249,7 @@ func (h *Handler) createChore(c *gin.Context) {
|
||||||
stringLabels = &labels
|
stringLabels = &labels
|
||||||
}
|
}
|
||||||
createdChore := &chModel.Chore{
|
createdChore := &chModel.Chore{
|
||||||
|
|
||||||
Name: choreReq.Name,
|
Name: choreReq.Name,
|
||||||
FrequencyType: choreReq.FrequencyType,
|
FrequencyType: choreReq.FrequencyType,
|
||||||
Frequency: choreReq.Frequency,
|
Frequency: choreReq.Frequency,
|
||||||
|
@ -263,7 +270,6 @@ func (h *Handler) createChore(c *gin.Context) {
|
||||||
CompletionWindow: choreReq.CompletionWindow,
|
CompletionWindow: choreReq.CompletionWindow,
|
||||||
Description: choreReq.Description,
|
Description: choreReq.Description,
|
||||||
SubTasks: choreReq.SubTasks,
|
SubTasks: choreReq.SubTasks,
|
||||||
Priority: choreReq.Priority,
|
|
||||||
}
|
}
|
||||||
id, err := h.choreRepo.CreateChore(c, createdChore)
|
id, err := h.choreRepo.CreateChore(c, createdChore)
|
||||||
createdChore.ID = id
|
createdChore.ID = id
|
||||||
|
@ -464,6 +470,13 @@ func (h *Handler) editChore(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
stringNotificationMetadata := string(notificationMetadataBytes)
|
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 :
|
// escape special characters in labels and store them as a string :
|
||||||
var stringLabels *string
|
var stringLabels *string
|
||||||
|
@ -547,7 +560,6 @@ func (h *Handler) editChore(c *gin.Context) {
|
||||||
if choreReq.SubTasks == nil {
|
if choreReq.SubTasks == nil {
|
||||||
choreReq.SubTasks = &[]stModel.SubTask{}
|
choreReq.SubTasks = &[]stModel.SubTask{}
|
||||||
}
|
}
|
||||||
// check what subtask needed to be removed:
|
|
||||||
for _, existedSubTask := range *oldChore.SubTasks {
|
for _, existedSubTask := range *oldChore.SubTasks {
|
||||||
found := false
|
found := false
|
||||||
for _, newSubTask := range *choreReq.SubTasks {
|
for _, newSubTask := range *choreReq.SubTasks {
|
||||||
|
@ -560,16 +572,14 @@ func (h *Handler) editChore(c *gin.Context) {
|
||||||
ToBeRemoved = append(ToBeRemoved, existedSubTask)
|
ToBeRemoved = append(ToBeRemoved, existedSubTask)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// check what subtask needed to be added or updated:
|
|
||||||
for _, newSubTask := range *choreReq.SubTasks {
|
for _, newSubTask := range *choreReq.SubTasks {
|
||||||
found := false
|
found := false
|
||||||
newSubTask.ChoreID = oldChore.ID
|
newSubTask.ChoreID = oldChore.ID
|
||||||
|
|
||||||
for _, existedSubTask := range *oldChore.SubTasks {
|
for _, existedSubTask := range *oldChore.SubTasks {
|
||||||
if existedSubTask.ID == newSubTask.ID {
|
if existedSubTask.ID == newSubTask.ID {
|
||||||
if existedSubTask.Name != newSubTask.Name ||
|
if existedSubTask.Name != newSubTask.Name || existedSubTask.OrderID != newSubTask.OrderID {
|
||||||
existedSubTask.OrderID != newSubTask.OrderID ||
|
|
||||||
existedSubTask.ParentId != newSubTask.ParentId {
|
|
||||||
// there is a change in the subtask, update it
|
// there is a change in the subtask, update it
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
|
@ -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{})
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue