Created
October 14, 2014 04:07
-
-
Save rShetty/c47e1d96698b0e46a3b5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create | |
uploaded_file = params[:batch_payouts_csv] | |
unless valid_file_type?(uploaded_file) | |
render json: {"error_message" => I18n.t("merchant.messages.errors.invalid_file_type")}, status: 400 | |
return | |
end | |
uploaded_csv_file = Batch::CsvFile.new(uploaded_file.path) | |
unless uploaded_csv_file.valid_size? | |
render json: {"error_message" => I18n.t("merchant.messages.errors.exceeding_file_size")}, status: 400 | |
return | |
end | |
filename_with_timestamp = "#{DateTime.now.strftime("%Q")}_#{uploaded_file.original_filename}" | |
merchant_employee = @current_user | |
currency = Currency.find(batch_payout_params[:currency_id]) | |
batch_payout = BatchPayout.create(merchant_employee: merchant_employee, currency: currency) | |
unless request.xhr? | |
response = {filename: filename_with_timestamp, status: "success", location: merchants_batch_payouts_path(batch_payout)} | |
render text: response.to_json, status: 201 \ | |
return | |
end | |
render json: {"filename" => filename_with_timestamp}, location: merchants_batch_payouts_path(batch_payout), status: 201 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment