Gab-Social/app/services/vote_service.rb

24 lines
477 B
Ruby
Raw Normal View History

2019-07-02 07:10:25 +00: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 16:46:31 +00:00
@votes << @poll.votes.create!(account: @account, choice: choice)
2019-07-02 07:10:25 +00:00
end
end
ActivityTracker.increment('activity:interactions')
end
end