Sha256: 6a60ce4f9b745b006b818a80cb21e4f6b0ef79e0c88dcff392dfff72bb57b1f2

Contents?: true

Size: 1.19 KB

Versions: 13

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

module Heya
  module Campaigns
    module Queries
      # {Queries::MembershipsToProcess} returns the CampaignMembership records
      # which should be processed by the scheduler.
      MembershipsToProcess = ->(user: nil) {
        Heya::CampaignMembership.to_process(user: user)
      }

      # Given a campaign and a user, {Queries::MembershipsForUpdate}
      # returns the user's campaign memberships which should be updated
      # concurrently.
      MembershipsForUpdate = ->(campaign, user) {
        membership = CampaignMembership.where(user: user, campaign_gid: campaign.gid).first
        if membership.concurrent?
          CampaignMembership
            .where(user: user, campaign_gid: campaign.gid)
        else
          CampaignMembership
            .where(user: user, concurrent: false)
        end
      }

      # Given a campaign, {Queries::OrphanedMemberships} returns the campaign
      # memberships which are on steps have been removed from the campaign.
      OrphanedMemberships = ->(campaign) {
        CampaignMembership
          .where(campaign_gid: campaign.gid)
          .where.not(step_gid: campaign.steps.map(&:gid))
      }
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
heya-0.12.0 lib/heya/campaigns/queries.rb
heya-0.11.0 lib/heya/campaigns/queries.rb
heya-0.10.0 lib/heya/campaigns/queries.rb
heya-0.9.0 lib/heya/campaigns/queries.rb
heya-0.8.0 lib/heya/campaigns/queries.rb
heya-0.7.0 lib/heya/campaigns/queries.rb
heya-0.6.1 lib/heya/campaigns/queries.rb
heya-0.6.0 lib/heya/campaigns/queries.rb
heya-0.5.3 lib/heya/campaigns/queries.rb
heya-0.5.2 lib/heya/campaigns/queries.rb
heya-0.5.1 lib/heya/campaigns/queries.rb
heya-0.5.0 lib/heya/campaigns/queries.rb
heya-0.4.0 lib/heya/campaigns/queries.rb