2019-07-02 08:10:25 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class VoteService < BaseService
|
|
|
|
include Authorization
|
|
|
|
|
|
|
|
def call(account, poll, choices)
|
|
|
|
authorize_with account, poll, :vote?
|
|
|
|
|
|
|
|
@account = account
|
|
|
|
@poll = poll
|
|
|
|
@choices = choices
|
|
|
|
@votes = []
|
|
|
|
|
|
|
|
ApplicationRecord.transaction do
|
|
|
|
@choices.each do |choice|
|
2020-05-01 17:46:31 +01:00
|
|
|
@votes << @poll.votes.create!(account: @account, choice: choice)
|
2019-07-02 08:10:25 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
ActivityTracker.increment('activity:interactions')
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|