- Fix failure when trying to save empty labels

- Update README
This commit is contained in:
Mo Tarbin 2024-11-27 19:14:25 -05:00
commit ed4144a64b
2 changed files with 17 additions and 11 deletions

View file

@ -16,7 +16,10 @@ An open-source, user-friendly app for managing tasks and chores, featuring custo
Release binary included everything needed to be up and running, as even the frontend file served Release binary included everything needed to be up and running, as even the frontend file served
### Using Docker run : ### Using Docker run :
1. pull the latest image using: `docker pull donetick/donetick` 1. pull the latest image using: `docker pull donetick/donetick`
2. run the container `DT_ENV=selfhosted docker run -v /path/to/host/data:/usr/src/app/data -p 2021:2021 donetick/donetick` 2. run the container and replace `/path/to/host/data` with where you want to place attach the volumne for the sqlite db `DT_ENV=selfhosted DT_SQLITE_PATH=/donetick-data/donetick.db docker run -v /path/to/host/data:/donetick-data -p 2021:2021 donetick/donetick`
### Using Docker Compose: ### Using Docker Compose:
@ -30,10 +33,11 @@ services:
ports: ports:
- 2021:2021 # needed for serving backend and frontend - 2021:2021 # needed for serving backend and frontend
volumes: volumes:
- ./data:/usr/src/app/data # database file stored (sqlite database) - ./data:/donetick-data # database file stored (sqlite database)
- ./config:/config # configration file like selfhosted.yaml - ./config:/config # configration file like selfhosted.yaml
environment: environment:
- DT_ENV=selfhosted # this tell donetick to load ./config/selfhosted.yaml for the configuration file - DT_ENV=selfhosted # this tell donetick to load ./config/selfhosted.yaml for the configuration file
- DT_SQLITE_PATH=/donetick-data/donetick.db
``` ```

View file

@ -73,17 +73,19 @@ func (r *LabelRepository) AssignLabelsToChore(ctx context.Context, choreID int,
}) })
} }
return r.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error { return r.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
if len(toBeRemoved) > 0 {
if err := r.db.WithContext(ctx).Where("chore_id = ? AND user_id = ? AND label_id IN (?)", choreID, userID, toBeRemoved).Delete(&chModel.ChoreLabels{}).Error; err != nil { if err := r.db.WithContext(ctx).Where("chore_id = ? AND user_id = ? AND label_id IN (?)", choreID, userID, toBeRemoved).Delete(&chModel.ChoreLabels{}).Error; err != nil {
return err return err
} }
}
if len(toBeAdded) > 0 {
if err := r.db.WithContext(ctx).Clauses(clause.OnConflict{ if err := r.db.WithContext(ctx).Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "chore_id"}, {Name: "label_id"}, {Name: "user_id"}}, Columns: []clause.Column{{Name: "chore_id"}, {Name: "label_id"}, {Name: "user_id"}},
DoNothing: true, DoNothing: true,
}).Create(&choreLabels).Error; err != nil { }).Create(&choreLabels).Error; err != nil {
return err return err
} }
}
return nil return nil
}) })
} }