# frozen_string_literal: true require 'time' require 'fractal_api/base_model' require 'fractal_api/paginator' module FractalApi module Forecasting class Transaction < BaseModel attributes :id, :bank_id, :forecast_id, :account_id, :value_date, :amount, :currency, :type, :merchant, :category, :reasons, :source def self.all(company_id, filters = {}) filters = filters.transform_keys { |key| key_transformer.transform(key) } Paginator.new('/forecasting/v2/transactions', self) do |url| get( url, params: filters, headers: { 'X-Company-Id' => company_id } ) end end def self.build(json:) super.tap do |record| record.value_date = Time.parse(record.value_date) if record.value_date end end end end end