-
Notifications
You must be signed in to change notification settings - Fork 19
/
complete_case_review.rb
63 lines (48 loc) · 1.56 KB
/
complete_case_review.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# frozen_string_literal: true
class CompleteCaseReview
include ActiveModel::Model
def initialize(case_review_class:, params:)
@case_review_class = case_review_class
@params = params
end
def call
@success = case_review.valid?
create_quality_review_task if success
FormResponse.new(success: success, errors: [response_errors], extra: completed_case_review)
end
private
attr_reader :case_review_class, :params, :success
def case_review
@case_review ||= review_class.complete(params)
end
def review_class
case_review_class.constantize
end
def create_quality_review_task
# Some situations do not want to move onto the QR task
# Where the appeal is a Legacy appeal
# We are in attorney checkout instead of Judge
# The case review is on a flow that already did QR creation
return if case_review.appeal.is_a?(LegacyAppeal) ||
!case_review.is_a?(JudgeCaseReview) ||
case_review.task.parent.is_a?(QualityReviewTask) ||
case_review.task.parent.is_a?(BvaDispatchTask)
root_task = case_review.task.root_task
if QualityReviewCaseSelector.select_case_for_quality_review?
QualityReviewTask.create_from_root_task(root_task)
else
BvaDispatchTask.create_from_root_task(root_task)
end
end
def response_errors
return if success
{
title: COPY::INVALID_RECORD_ERROR_TITLE,
detail: case_review.errors.full_messages.join(", ")
}
end
def completed_case_review
return {} unless success
{ case_review: case_review }
end
end