|
|
|
@ -40,7 +40,6 @@ module Submissions
|
|
|
|
submissions.where(created_by_user_id: user&.id || -1)
|
|
|
|
submissions.where(created_by_user_id: user&.id || -1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# rubocop:disable Metrics/MethodLength
|
|
|
|
|
|
|
|
def filter_by_status(submissions, filters)
|
|
|
|
def filter_by_status(submissions, filters)
|
|
|
|
case filters[:status]
|
|
|
|
case filters[:status]
|
|
|
|
when 'pending'
|
|
|
|
when 'pending'
|
|
|
|
@ -52,33 +51,24 @@ module Submissions
|
|
|
|
when 'expired'
|
|
|
|
when 'expired'
|
|
|
|
submissions.expired
|
|
|
|
submissions.expired
|
|
|
|
when 'sent'
|
|
|
|
when 'sent'
|
|
|
|
submissions.joins(:submitters)
|
|
|
|
submissions.where(Submitter.where(Submitter.arel_table[:submission_id].eq(Submission.arel_table[:id]))
|
|
|
|
.where(submitters: { opened_at: nil, completed_at: nil, declined_at: nil })
|
|
|
|
.where(opened_at: nil, completed_at: nil, declined_at: nil)
|
|
|
|
.where.not(submitters: { sent_at: nil })
|
|
|
|
.where.not(sent_at: nil)
|
|
|
|
.group(:id)
|
|
|
|
.limit(1).arel.exists)
|
|
|
|
when 'opened'
|
|
|
|
when 'opened'
|
|
|
|
submissions.joins(:submitters)
|
|
|
|
submissions.where(Submitter.where(Submitter.arel_table[:submission_id].eq(Submission.arel_table[:id]))
|
|
|
|
.where(submitters: { completed_at: nil, declined_at: nil })
|
|
|
|
.where(completed_at: nil, declined_at: nil)
|
|
|
|
.where.not(submitters: { opened_at: nil })
|
|
|
|
.where.not(opened_at: nil)
|
|
|
|
.group(:id)
|
|
|
|
.limit(1).arel.exists)
|
|
|
|
when 'partially_completed'
|
|
|
|
when 'partially_completed'
|
|
|
|
submissions.joins(:submitters)
|
|
|
|
submissions.where(completed_at: nil)
|
|
|
|
.group(:id)
|
|
|
|
.where(Submitter.where(Submitter.arel_table[:submission_id].eq(Submission.arel_table[:id]))
|
|
|
|
.having(Arel::Nodes::NamedFunction.new(
|
|
|
|
.where.not(completed_at: nil)
|
|
|
|
'COUNT', [Arel::Nodes::NamedFunction.new('NULLIF',
|
|
|
|
.limit(1).arel.exists)
|
|
|
|
[Submitter.arel_table[:completed_at].eq(nil),
|
|
|
|
|
|
|
|
Arel::Nodes.build_quoted(false)])]
|
|
|
|
|
|
|
|
).gt(0))
|
|
|
|
|
|
|
|
.having(Arel::Nodes::NamedFunction.new(
|
|
|
|
|
|
|
|
'COUNT', [Arel::Nodes::NamedFunction.new('NULLIF',
|
|
|
|
|
|
|
|
[Submitter.arel_table[:completed_at].not_eq(nil),
|
|
|
|
|
|
|
|
Arel::Nodes.build_quoted(false)])]
|
|
|
|
|
|
|
|
).gt(0))
|
|
|
|
|
|
|
|
else
|
|
|
|
else
|
|
|
|
submissions
|
|
|
|
submissions
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
# rubocop:enable Metrics/MethodLength
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def filter_by_created_at(submissions, filters)
|
|
|
|
def filter_by_created_at(submissions, filters)
|
|
|
|
submissions = submissions.where(created_at: filters[:created_at_from]..) if filters[:created_at_from].present?
|
|
|
|
submissions = submissions.where(created_at: filters[:created_at_from]..) if filters[:created_at_from].present?
|
|
|
|
|