|
|
|
@ -65,12 +65,18 @@ class Submission < ApplicationRecord
|
|
|
|
|
|
|
|
|
|
|
|
scope :active, -> { where(archived_at: nil) }
|
|
|
|
scope :active, -> { where(archived_at: nil) }
|
|
|
|
scope :archived, -> { where.not(archived_at: nil) }
|
|
|
|
scope :archived, -> { where.not(archived_at: nil) }
|
|
|
|
scope :pending, -> { joins(:submitters).where(submitters: { completed_at: nil }).group(:id) }
|
|
|
|
scope :pending, lambda {
|
|
|
|
|
|
|
|
where(Submitter.where(Submitter.arel_table[:submission_id].eq(Submission.arel_table[:id])
|
|
|
|
|
|
|
|
.and(Submitter.arel_table[:completed_at].eq(nil))).select(1).arel.exists)
|
|
|
|
|
|
|
|
}
|
|
|
|
scope :completed, lambda {
|
|
|
|
scope :completed, lambda {
|
|
|
|
where.not(Submitter.where(Submitter.arel_table[:submission_id].eq(Submission.arel_table[:id])
|
|
|
|
where.not(Submitter.where(Submitter.arel_table[:submission_id].eq(Submission.arel_table[:id])
|
|
|
|
.and(Submitter.arel_table[:completed_at].eq(nil))).select(1).arel.exists)
|
|
|
|
.and(Submitter.arel_table[:completed_at].eq(nil))).select(1).arel.exists)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
scope :declined, -> { joins(:submitters).where.not(submitters: { declined_at: nil }).group(:id) }
|
|
|
|
scope :declined, lambda {
|
|
|
|
|
|
|
|
where(Submitter.where(Submitter.arel_table[:submission_id].eq(Submission.arel_table[:id])
|
|
|
|
|
|
|
|
.and(Submitter.arel_table[:declined_at].not_eq(nil))).select(1).arel.exists)
|
|
|
|
|
|
|
|
}
|
|
|
|
scope :expired, -> { pending.where(expire_at: ..Time.current) }
|
|
|
|
scope :expired, -> { pending.where(expire_at: ..Time.current) }
|
|
|
|
|
|
|
|
|
|
|
|
enum :source, {
|
|
|
|
enum :source, {
|
|
|
|
|