Skip to content

Commit 89c0491

Browse files
gabrielcicero45GabrielRMuller
authored andcommitted
add scopes in story
1 parent 13685b0 commit 89c0491

File tree

4 files changed

+17
-16
lines changed

4 files changed

+17
-16
lines changed

app/controllers/beta/project_boards_controller.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ def show
1212
@project = result.success.project
1313
authorize @project, policy_class: Beta::ProjectPolicy
1414

15-
response = result.success.as_json(root: false)
16-
render json: response
15+
render json: result.success.as_json(root: false)
1716
end
1817

1918
private

app/models/story.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ class Story < ApplicationRecord
2020
start_date.beginning_of_day,
2121
end_date.end_of_day)
2222
}
23+
scope :not_accepted_or_recently_accepted, ->(current_iteration_start) { where.not(state: 'accepted').or(where("accepted_at >= ?", current_iteration_start))}
24+
scope :collapsed_story, -> {select(
25+
:id,
26+
:title,
27+
:description,
28+
:estimate,
29+
:story_type,
30+
:state,
31+
:requested_by_name,
32+
:owned_by_initials,
33+
:project_id
34+
)}
2335

2436
delegate :suppress_notifications, to: :project
2537

app/operations/beta/project_board_operations/read.rb

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,25 +56,15 @@ def stories_and_past_iterations
5656
yield Success(
5757
stories: @active_stories,
5858
past_iterations: past_iterations
59-
)
59+
)
6060
end
6161

6262
def active_stories
6363
@active_stories ||= begin
6464
project
6565
.stories
66-
.where("state != 'accepted' OR accepted_at >= ?", current_iteration_start)
67-
.select(
68-
:id,
69-
:title,
70-
:description,
71-
:estimate,
72-
:story_type,
73-
:state,
74-
:requested_by_name,
75-
:owned_by_initials,
76-
:project_id
77-
)
66+
.not_accepted_or_recently_accepted(current_iteration_start)
67+
.collapsed_story
7868
.order('updated_at DESC')
7969
end
8070

app/operations/story_operations/read_all.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def active_stories
3535
project
3636
.stories
3737
.with_dependencies
38-
.where("state != 'accepted' OR accepted_at >= ?", current_iteration_start)
38+
.not_accepted_or_recently_accepted(current_iteration_start)
3939
.order('updated_at DESC')
4040
end
4141

0 commit comments

Comments
 (0)