Sha256: 838b7699a3f5affba67208e145e738f4e775f1850f1c3a15ecca331c522d94d4
Contents?: true
Size: 793 Bytes
Versions: 3
Compression:
Stored size: 793 Bytes
Contents
# frozen_string_literal: true module Decidim module Core # A GraphQL resolver to handle `count` and `metric` queries class MetricResolver attr_reader :name def initialize(name, organization) @name = name @organization = organization @group_by = :day @counter_field = :cumulative end def count metric_scope.max.try(:last) || 0 end def history metric_scope end private def metric_scope Decidim::Metric .where(metric_type: name, organization: organization) .group(group_by) .order("#{group_by} DESC") .limit(60) .sum(counter_field) end attr_reader :organization, :group_by, :counter_field end end end
Version data entries
3 entries across 3 versions & 1 rubygems