1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-24 15:49:39 +02:00
Maybe/app/controllers/imports_controller.rb
Zach Gollwitzer c5da8ea550
Allow CSV imports to be configured with single or multi-account mode (#1943)
* Allow CSV imports to be configured to a single account or multiple accounts

* Initialize import directly from accounts page

* Fix brakeman warnings

* Fix schema

* Fix Synth check
2025-03-03 12:47:30 -05:00

54 lines
1.3 KiB
Ruby

class ImportsController < ApplicationController
before_action :set_import, only: %i[show publish destroy revert]
def publish
@import.publish_later
redirect_to import_path(@import), notice: "Your import has started in the background."
end
def index
@imports = Current.family.imports
render layout: "settings"
end
def new
@pending_import = Current.family.imports.ordered.pending.first
end
def create
account = Current.family.accounts.find_by(id: params.dig(:import, :account_id))
import = Current.family.imports.create!(type: import_params[:type], account: account)
redirect_to import_upload_path(import)
end
def show
if !@import.uploaded?
redirect_to import_upload_path(@import), alert: "Please finalize your file upload."
elsif !@import.publishable?
redirect_to import_confirm_path(@import), alert: "Please finalize your mappings before proceeding."
end
end
def revert
@import.revert_later
redirect_to imports_path, notice: "Import is reverting in the background."
end
def destroy
@import.destroy
redirect_to imports_path, notice: "Your import has been deleted."
end
private
def set_import
@import = Current.family.imports.find(params[:id])
end
def import_params
params.require(:import).permit(:type)
end
end