feat(ui+backend): project params persistence

This commit is contained in:
2020-09-11 12:41:07 +02:00
parent aacff1d694
commit 833213e5fe
9 changed files with 161 additions and 17 deletions

View File

@ -219,6 +219,66 @@ func (r *ProjectRepository) UpdateTask(ctx context.Context, projectID, taskID in
return task, nil
}
func (r *ProjectRepository) UpdateParams(ctx context.Context, projectID int64, changes ProjectParamsChanges) (*Project, error) {
project := &Project{}
project.ID = projectID
err := r.db.Transaction(func(tx *gorm.DB) error {
err := tx.Model(project).
Preload("ACL").
Preload("ACL.User").
Preload("Tasks").
Preload("Tasks.Category").
Preload("TaskCategories").
First(project, "id = ?", projectID).
Error
if err != nil {
return errors.WithStack(err)
}
if project.Params == nil {
project.Params = &ProjectParams{}
}
if changes.Currency != nil {
project.Params.Currency = *changes.Currency
}
if changes.HideFinancialPreviewOnPrint != nil {
project.Params.HideFinancialPreviewOnPrint = *changes.HideFinancialPreviewOnPrint
}
if changes.RoundUpEstimations != nil {
project.Params.RoundUpEstimations = *changes.RoundUpEstimations
}
if changes.TimeUnit != nil {
if project.Params.TimeUnit == nil {
project.Params.TimeUnit = &TimeUnit{}
}
if changes.TimeUnit.Acronym != nil {
project.Params.TimeUnit.Acronym = *changes.TimeUnit.Acronym
}
if changes.TimeUnit.Label != nil {
project.Params.TimeUnit.Label = *changes.TimeUnit.Label
}
}
if err := tx.Save(project).Error; err != nil {
return errors.WithStack(err)
}
return nil
})
if err != nil {
return nil, errors.Wrap(err, "could not update project params")
}
return project, nil
}
func updateTaskWithChanges(db *gorm.DB, task *Task, changes ProjectTaskChanges) error {
if changes.Label != nil {
task.Label = changes.Label