Sha256: e8d689d9581ec49eed3ffc8ae5e98bb30d2edf5d74053ea33aef3d50611decf5

Contents?: true

Size: 961 Bytes

Versions: 6

Compression:

Stored size: 961 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:, host:, 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:, protocol:)
      ).deliver_later
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
pages_core-3.15.4 app/services/pages_core/invite_service.rb
pages_core-3.15.3 app/services/pages_core/invite_service.rb
pages_core-3.15.2 app/services/pages_core/invite_service.rb
pages_core-3.15.1 app/services/pages_core/invite_service.rb
pages_core-3.14.0 app/services/pages_core/invite_service.rb
pages_core-3.13.0 app/services/pages_core/invite_service.rb