Sha256: 5f6a6f73c13243cea56d3cce3b3d8c775daccdaebec0b657ebc2c78356f51be2

Contents?: true

Size: 994 Bytes

Versions: 21

Compression:

Stored size: 994 Bytes

Contents

# frozen_string_literal: true

module PagesCore
  class InviteService
    include Rails.application.routes.url_helpers

    attr_reader :attributes, :user, :host, :protocol

    def initialize(attributes, user:, host:, protocol: "http")
      @attributes = attributes
      @user = user
      @host = host
      @protocol = protocol
    end

    class << self
      def call(attrs, user:, host:, protocol: "http")
        new(attrs, user: user, host: host, protocol: protocol).call
      end
    end

    def call
      Invite.transaction do
        invite = user.invites.create(attributes)
        if invite.valid?
          deliver_invite(invite)
          invite.update(sent_at: Time.now.utc)
        end
        invite
      end
    end

    private

    def deliver_invite(invite)
      AdminMailer.invite(
        invite,
        admin_invite_with_token_url(invite, invite.token,
                                    host: host, protocol: protocol)
      ).deliver_later
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
pages_core-3.12.7 app/services/pages_core/invite_service.rb
pages_core-3.12.6 app/services/pages_core/invite_service.rb
pages_core-3.12.5 app/services/pages_core/invite_service.rb
pages_core-3.12.4 app/services/pages_core/invite_service.rb
pages_core-3.12.3 app/services/pages_core/invite_service.rb
pages_core-3.12.2 app/services/pages_core/invite_service.rb
pages_core-3.12.1 app/services/pages_core/invite_service.rb
pages_core-3.12.0 app/services/pages_core/invite_service.rb
pages_core-3.11.3 app/services/pages_core/invite_service.rb
pages_core-3.11.2 app/services/pages_core/invite_service.rb
pages_core-3.11.1 app/services/pages_core/invite_service.rb
pages_core-3.11.0 app/services/pages_core/invite_service.rb
pages_core-3.10.2 app/services/pages_core/invite_service.rb
pages_core-3.10.1 app/services/pages_core/invite_service.rb
pages_core-3.9.2 app/services/pages_core/invite_service.rb
pages_core-3.9.1 app/services/pages_core/invite_service.rb
pages_core-3.9.0 app/services/pages_core/invite_service.rb
pages_core-3.8.3 app/services/pages_core/invite_service.rb
pages_core-3.8.2 app/services/pages_core/invite_service.rb
pages_core-3.8.1 app/services/pages_core/invite_service.rb