feat(ui+backend): project params persistence
This commit is contained in:
@ -18,6 +18,18 @@ input ProjectTaskEstimationsChanges {
|
||||
pessimistic: Float
|
||||
}
|
||||
|
||||
input ProjectParamsChanges {
|
||||
timeUnit: TimeUnitChanges
|
||||
currency: String
|
||||
roundUpEstimations: Boolean
|
||||
hideFinancialPreviewOnPrint: Boolean
|
||||
}
|
||||
|
||||
input TimeUnitChanges {
|
||||
label: String
|
||||
acronym: String
|
||||
}
|
||||
|
||||
type Mutation {
|
||||
updateUser(id: ID!, changes: UserChanges!): User!
|
||||
createProject(changes: CreateProjectChanges!): Project!
|
||||
@ -25,4 +37,5 @@ type Mutation {
|
||||
addProjectTask(projectId: ID!, changes: ProjectTaskChanges!): Task!
|
||||
removeProjectTask(projectId: ID!, taskId: ID!): Boolean!
|
||||
updateProjectTask(projectId: ID!, taskId: ID!, changes: ProjectTaskChanges!): Task!
|
||||
updateProjectParams(projectId: ID!, changes: ProjectParamsChanges!): ProjectParams!
|
||||
}
|
@ -34,6 +34,10 @@ func (r *mutationResolver) UpdateProjectTask(ctx context.Context, projectID int6
|
||||
return handleUpdateProjectTask(ctx, projectID, taskID, changes)
|
||||
}
|
||||
|
||||
func (r *mutationResolver) UpdateProjectParams(ctx context.Context, projectID int64, changes model.ProjectParamsChanges) (*model.ProjectParams, error) {
|
||||
return handleUpdateProjectParams(ctx, projectID, changes)
|
||||
}
|
||||
|
||||
// Mutation returns generated.MutationResolver implementation.
|
||||
func (r *Resolver) Mutation() generated.MutationResolver { return &mutationResolver{r} }
|
||||
|
||||
|
@ -110,3 +110,19 @@ func handleUpdateProjectTask(ctx context.Context, projectID, taskID int64, chang
|
||||
|
||||
return task, nil
|
||||
}
|
||||
|
||||
func handleUpdateProjectParams(ctx context.Context, projectID int64, changes model.ProjectParamsChanges) (*model.ProjectParams, error) {
|
||||
db, err := getDB(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
repo := model.NewProjectRepository(db)
|
||||
|
||||
project, err := repo.UpdateParams(ctx, projectID, changes)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
return project.Params, nil
|
||||
}
|
||||
|
@ -18,15 +18,7 @@ func (r *queryResolver) Projects(ctx context.Context, filter *model1.ProjectsFil
|
||||
return handleProjects(ctx, filter)
|
||||
}
|
||||
|
||||
func (r *taskResolver) Estimations(ctx context.Context, obj *model1.Task) (*model1.Estimations, error) {
|
||||
return handleEstimations(ctx, obj)
|
||||
}
|
||||
|
||||
// Query returns generated.QueryResolver implementation.
|
||||
func (r *Resolver) Query() generated.QueryResolver { return &queryResolver{r} }
|
||||
|
||||
// Task returns generated.TaskResolver implementation.
|
||||
func (r *Resolver) Task() generated.TaskResolver { return &taskResolver{r} }
|
||||
|
||||
type queryResolver struct{ *Resolver }
|
||||
type taskResolver struct{ *Resolver }
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user