houdini/app/controllers/nonprofits/supporter_emails_controller.rb

31 lines
917 B
Ruby

module Nonprofits
class SupporterEmailsController < ApplicationController
include NonprofitHelper
before_filter :authenticate_nonprofit_user!
def create
if params[:selecting_all]
ids = QuerySupporters.full_filter_expr(params[:nonprofit_id], params[:query])
.select("supporters.id")
.execute(format: 'csv')[1..-1].flatten
elsif params[:supporter_ids]
ids = params[:supporter_ids]
end
if ids.nil? || ids.empty?
render json: {errors: 'Supporters not found'}, status: :unprocessable_entity
return
end
DelayedJobHelper.enqueue_job(EmailSupporters, :deliver, [ids, params[:supporter_email]])
render json: {count: ids.count}, status: :ok
end
def gmail
gmail = SupporterEmail.create params[:gmail]
InsertActivities.for_supporter_emails([gmail.id])
render json: gmail
end
end
end