|
@ -234,7 +234,7 @@ func (l *Loader) FindProject(ctx context.Context, id string) (*models.ProjectRes |
|
|
if project.UserID != auth.UserID(ctx) { |
|
|
if project.UserID != auth.UserID(ctx) { |
|
|
return nil, slerrors.NotFound("Goal") |
|
|
return nil, slerrors.NotFound("Goal") |
|
|
} |
|
|
} |
|
|
result := &models.ProjectResult{Project: *project} |
|
|
|
|
|
|
|
|
result := &models.ProjectResult{Project: *project, Subtractions: []models.ProjectSubtraction{}} |
|
|
|
|
|
|
|
|
tasks, err := l.DB.Tasks().List(ctx, models.TaskFilter{ |
|
|
tasks, err := l.DB.Tasks().List(ctx, models.TaskFilter{ |
|
|
UserID: auth.UserID(ctx), |
|
|
UserID: auth.UserID(ctx), |
|
@ -301,10 +301,19 @@ func (l *Loader) FindProject(ctx context.Context, id string) (*models.ProjectRes |
|
|
} |
|
|
} |
|
|
for _, log := range result.Tasks[i].Logs { |
|
|
for _, log := range result.Tasks[i].Logs { |
|
|
if project.StartTime != nil && log.LoggedTime.Before(*project.StartTime) { |
|
|
if project.StartTime != nil && log.LoggedTime.Before(*project.StartTime) { |
|
|
continue |
|
|
|
|
|
|
|
|
result.Subtractions = append(result.Subtractions, models.ProjectSubtraction{ |
|
|
|
|
|
Item: *result.Tasks[i].Item, |
|
|
|
|
|
Amount: log.ItemAmount, |
|
|
|
|
|
}) |
|
|
|
|
|
if log.SecondaryItemID != nil { |
|
|
|
|
|
result.Subtractions = append(result.Subtractions, models.ProjectSubtraction{ |
|
|
|
|
|
Item: *log.SecondaryItem, |
|
|
|
|
|
Amount: log.SecondaryItemAmount, |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
result.Tasks[i].CompletedAmount += log.Amount(result.Tasks[i].ItemID) |
|
|
|
|
|
|
|
|
result.Tasks[i].CompletedAmount += log.Amount(log.ItemID) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -359,7 +368,7 @@ func (l *Loader) ListProjects(ctx context.Context, filter models.ProjectFilter) |
|
|
|
|
|
|
|
|
results := make([]*models.ProjectResult, len(projects)) |
|
|
results := make([]*models.ProjectResult, len(projects)) |
|
|
for i, project := range projects { |
|
|
for i, project := range projects { |
|
|
results[i] = &models.ProjectResult{Project: *project} |
|
|
|
|
|
|
|
|
results[i] = &models.ProjectResult{Project: *project, Subtractions: []models.ProjectSubtraction{}} |
|
|
results[i].Tasks = make([]*models.TaskResult, 0, 16) |
|
|
results[i].Tasks = make([]*models.TaskResult, 0, 16) |
|
|
for _, task := range tasks { |
|
|
for _, task := range tasks { |
|
|
if task.ProjectID != project.ID { |
|
|
if task.ProjectID != project.ID { |
|
@ -408,7 +417,16 @@ func (l *Loader) ListProjects(ctx context.Context, filter models.ProjectFilter) |
|
|
} |
|
|
} |
|
|
for _, log := range taskResult.Logs { |
|
|
for _, log := range taskResult.Logs { |
|
|
if project.StartTime != nil && log.LoggedTime.Before(*project.StartTime) { |
|
|
if project.StartTime != nil && log.LoggedTime.Before(*project.StartTime) { |
|
|
continue |
|
|
|
|
|
|
|
|
results[i].Subtractions = append(results[i].Subtractions, models.ProjectSubtraction{ |
|
|
|
|
|
Item: *taskResult.Item, |
|
|
|
|
|
Amount: log.ItemAmount, |
|
|
|
|
|
}) |
|
|
|
|
|
if log.SecondaryItem != nil { |
|
|
|
|
|
results[i].Subtractions = append(results[i].Subtractions, models.ProjectSubtraction{ |
|
|
|
|
|
Item: *log.SecondaryItem, |
|
|
|
|
|
Amount: log.SecondaryItemAmount, |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
taskResult.CompletedAmount += log.Amount(taskResult.ItemID) |
|
|
taskResult.CompletedAmount += log.Amount(taskResult.ItemID) |
|
|