Class: ForestAdminDatasourceMambuPayments::Collections::Event

Inherits:
BaseCollection
  • Object
show all
Defined in:
lib/forest_admin_datasource_mambu_payments/collections/event.rb

Constant Summary collapse

PolymorphicManyToOneSchema =
ForestAdminDatasourceToolkit::Schema::Relations::PolymorphicManyToOneSchema
TYPE_TO_COLLECTION =

Maps Numeral’s ‘topic` / `related_object_type` enum values to Forest collection names. The polymorphic relation resolver expects the type column to hold the target collection name, so we translate at serialize time.

{
  'payment_order' => 'MambuPaymentOrder',
  'transaction' => 'MambuTransaction',
  'incoming_payment' => 'MambuIncomingPayment',
  'expected_payment' => 'MambuExpectedPayment',
  'direct_debit_mandate' => 'MambuDirectDebitMandate',
  'balance' => 'MambuBalance',
  'connected_account' => 'MambuConnectedAccount',
  'account_holder' => 'MambuAccountHolder',
  'internal_account' => 'MambuInternalAccount',
  'external_account' => 'MambuExternalAccount'
}.freeze
ENUM_STATUS =
%w[created delivered pending_retry failed archived].freeze

Constants inherited from BaseCollection

BaseCollection::BOOL_OPS, BaseCollection::ColumnSchema, BaseCollection::DATE_OPS, BaseCollection::ForestException, BaseCollection::ID_OPS, BaseCollection::Leaf, BaseCollection::NUMBER_OPS, BaseCollection::Operators, BaseCollection::STRING_OPS

Instance Method Summary collapse

Methods inherited from BaseCollection

#aggregate, client_resource, #fetch_by_ids, #list

Constructor Details

#initialize(datasource) ⇒ Event

Returns a new instance of Event.



26
27
28
29
30
31
# File 'lib/forest_admin_datasource_mambu_payments/collections/event.rb', line 26

def initialize(datasource)
  super(datasource, 'MambuEvent')
  define_schema
  define_relations
  reconcile_filter_operators!
end

Instance Method Details

#serialize(record) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/forest_admin_datasource_mambu_payments/collections/event.rb', line 33

def serialize(record)
  a = attrs_of(record)
  {
    'id' => a['id'],
    'object' => a['object'],
    'topic' => a['topic'],
    'type' => a['type'],
    'related_object_id' => a['related_object_id'],
    'related_object_type' => TYPE_TO_COLLECTION[a['related_object_type']] || a['related_object_type'],
    'status' => a['status'],
    'status_details' => a['status_details'],
    'webhook_id' => a['webhook_id'],
    'data' => a['data'],
    'created_at' => a['created_at']
  }
end