Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions app/domains/accountify/contact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ module Accountify
module Contact
extend self

class CreatedEvent < Event; end

def create(user_id:, tenant_id:,
organisation_id:, first_name:, last_name:, email:)
contact = nil
Expand All @@ -18,7 +16,7 @@ def create(user_id:, tenant_id:,
last_name: last_name,
email: email)

event = CreatedEvent
event = Models::Contact::CreatedEvent
.create!(
user_id: user_id,
tenant_id: tenant_id,
Expand Down Expand Up @@ -58,8 +56,6 @@ def find_by_id(user_id:, tenant_id:, id:)
}
end

class UpdatedEvent < Event; end

def update(user_id:, tenant_id:, id:,
first_name:, last_name:, email:)
contact = nil
Expand All @@ -74,7 +70,7 @@ def update(user_id:, tenant_id:, id:,
last_name: last_name,
email: email)

event = UpdatedEvent
event = Models::Contact::UpdatedEvent
.create!(
user_id: user_id,
tenant_id: tenant_id,
Expand All @@ -90,8 +86,6 @@ def update(user_id:, tenant_id:, id:,
{ id: contact.id, events: [{ id: event.id, type: event.type }] }
end

class DeletedEvent < Event; end

def delete(user_id:, tenant_id:, id:, time: ::Time)
contact = nil
event = nil
Expand All @@ -102,7 +96,7 @@ def delete(user_id:, tenant_id:, id:, time: ::Time)

contact.update!(deleted_at: time.now.utc)

event = DeletedEvent
event = Models::Contact::DeletedEvent
.create!(
user_id: user_id,
tenant_id: tenant_id,
Expand Down
24 changes: 6 additions & 18 deletions app/domains/accountify/invoice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ module Status
VOIDED = 'voided'
end

class DraftedEvent < Event; end

def draft(user_id:, tenant_id:,
organisation_id:, contact_id:,
currency_code:, due_date:, line_items:,
Expand Down Expand Up @@ -51,7 +49,7 @@ def draft(user_id:, tenant_id:,
quantity: line_item[:quantity])
end

event = DraftedEvent.create!(
event = Models::Invoice::DraftedEvent.create!(
user_id: user_id,
tenant_id: tenant_id,
created_at: current_utc_time,
Expand Down Expand Up @@ -118,8 +116,6 @@ def find_by_id(user_id:, tenant_id:, id:)
}
end

class UpdatedEvent < Event; end

def update(user_id:, tenant_id:, id:,
organisation_id:, contact_id:,
due_date:, line_items:,
Expand Down Expand Up @@ -162,7 +158,7 @@ def update(user_id:, tenant_id:, id:,
quantity: line_item[:quantity])
end

event = UpdatedEvent.create!(
event = Models::Invoice::UpdatedEvent.create!(
user_id: user_id,
tenant_id: tenant_id,
created_at: current_utc_time,
Expand Down Expand Up @@ -191,8 +187,6 @@ def update(user_id:, tenant_id:, id:,
{ id: invoice.id, events: [{ id: event.id, type: event.type }] }
end

class DeletedEvent < Event; end

def delete(user_id:, tenant_id:, id:, time: ::Time)
invoice = nil
event = nil
Expand All @@ -204,7 +198,7 @@ def delete(user_id:, tenant_id:, id:, time: ::Time)

invoice.update!(updated_at: current_utc_time, deleted_at: current_utc_time)

event = DeletedEvent.create!(
event = Models::Invoice::DeletedEvent.create!(
user_id: user_id,
tenant_id: tenant_id,
created_at: current_utc_time,
Expand All @@ -219,8 +213,6 @@ def delete(user_id:, tenant_id:, id:, time: ::Time)
{ id: invoice.id, events: [{ id: event.id, type: event.type }] }
end

class IssuedEvent < Event; end

def issue(user_id:, tenant_id:, id:, time: ::Time)
invoice = nil
event = nil
Expand All @@ -235,7 +227,7 @@ def issue(user_id:, tenant_id:, id:, time: ::Time)
issued_at: current_utc_time,
updated_at: current_utc_time)

event = IssuedEvent.create!(
event = Models::Invoice::IssuedEvent.create!(
user_id: user_id,
tenant_id: tenant_id,
created_at: current_utc_time,
Expand All @@ -251,8 +243,6 @@ def issue(user_id:, tenant_id:, id:, time: ::Time)
{ id: invoice.id, events: [{ id: event.id, type: event.type }] }
end

class PaidEvent < Event; end

def paid(user_id:, tenant_id:, id:, time: ::Time)
invoice = nil
event = nil
Expand All @@ -268,7 +258,7 @@ def paid(user_id:, tenant_id:, id:, time: ::Time)

invoice.update!(status: Invoice::Status::PAID, paid_at: Time.current)

event = PaidEvent.create!(
event = Models::Invoice::PaidEvent.create!(
user_id: user_id,
tenant_id: tenant_id,
eventable: invoice,
Expand All @@ -284,8 +274,6 @@ def paid(user_id:, tenant_id:, id:, time: ::Time)
{ id: invoice.id, events: [{ id: event.id, type: event.type }] }
end

class VoidedEvent < Event; end

def void(user_id:, tenant_id:, id:, time: ::Time)
invoice = nil
event = nil
Expand All @@ -295,7 +283,7 @@ def void(user_id:, tenant_id:, id:, time: ::Time)

invoice.update!(status: Invoice::Status::VOIDED)

event = VoidedEvent.create!(
event = Models::Invoice::VoidedEvent.create!(
user_id: user_id,
tenant_id: tenant_id,
eventable: invoice,
Expand Down
9 changes: 9 additions & 0 deletions app/domains/accountify/models/contact/created_event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Accountify
module Models
class Contact
class CreatedEvent < Models::Event

end
end
end
end
9 changes: 9 additions & 0 deletions app/domains/accountify/models/contact/deleted_event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Accountify
module Models
class Contact
class DeletedEvent < Models::Event

end
end
end
end
9 changes: 9 additions & 0 deletions app/domains/accountify/models/contact/updated_event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Accountify
module Models
class Contact
class UpdatedEvent < Models::Event

end
end
end
end
7 changes: 7 additions & 0 deletions app/domains/accountify/models/event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Accountify
module Models
class Event < ::Models::Event

end
end
end
3 changes: 1 addition & 2 deletions app/domains/accountify/models/invoice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ class Invoice < ActiveRecord::Base

has_many :line_items, -> { order(id: :asc) }

has_many :events, -> { order(created_at: :asc) },
as: :eventable
has_many :events, -> { order(created_at: :asc) }, as: :eventable

has_one :invoice_status_summary

Expand Down
9 changes: 9 additions & 0 deletions app/domains/accountify/models/invoice/deleted_event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Accountify
module Models
class Invoice
class DeletedEvent < Models::Event

end
end
end
end
9 changes: 9 additions & 0 deletions app/domains/accountify/models/invoice/drafted_event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Accountify
module Models
class Invoice
class DraftedEvent < Models::Event

end
end
end
end
9 changes: 9 additions & 0 deletions app/domains/accountify/models/invoice/issued_event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Accountify
module Models
class Invoice
class IssuedEvent < Models::Event

end
end
end
end
9 changes: 9 additions & 0 deletions app/domains/accountify/models/invoice/paid_event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Accountify
module Models
class Invoice
class PaidEvent < Models::Event

end
end
end
end
9 changes: 9 additions & 0 deletions app/domains/accountify/models/invoice/updated_event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Accountify
module Models
class Invoice
class UpdatedEvent < Models::Event

end
end
end
end
9 changes: 9 additions & 0 deletions app/domains/accountify/models/invoice/voided_event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Accountify
module Models
class Invoice
class VoidedEvent < Models::Event

end
end
end
end
2 changes: 1 addition & 1 deletion app/domains/accountify/models/organisation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Models
class Organisation < ActiveRecord::Base
self.table_name = 'accountify_organisations'

has_many :events, -> { order(created_at: :asc) }, as: :eventable
has_many :events, -> { order(created_at: :asc) }, as: :eventable, class_name: 'Models::Event'

has_one :invoice_status_summary
end
Expand Down
9 changes: 9 additions & 0 deletions app/domains/accountify/models/organisation/created_event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Accountify
module Models
class Organisation
class CreatedEvent < Models::Event

end
end
end
end
9 changes: 9 additions & 0 deletions app/domains/accountify/models/organisation/deleted_event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Accountify
module Models
class Organisation
class DeletedEvent < Models::Event

end
end
end
end
9 changes: 9 additions & 0 deletions app/domains/accountify/models/organisation/updated_event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Accountify
module Models
class Organisation
class UpdatedEvent < Models::Event

end
end
end
end
12 changes: 3 additions & 9 deletions app/domains/accountify/organisation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ module Accountify
module Organisation
extend self

class CreatedEvent < Event; end

def create(user_id:, tenant_id:, name:)
organisation = nil
event = nil
Expand All @@ -13,7 +11,7 @@ def create(user_id:, tenant_id:, name:)
.where(tenant_id: tenant_id)
.create!(name: name)

event = CreatedEvent
event = Models::Organisation::CreatedEvent
.where(user_id: user_id, tenant_id: tenant_id)
.create!(
eventable: organisation,
Expand Down Expand Up @@ -48,8 +46,6 @@ def find_by_id(user_id:, tenant_id:, id:)
}
end

class UpdatedEvent < Event; end

def update(user_id:, tenant_id:, id:, name:)
organisation = nil
event = nil
Expand All @@ -60,7 +56,7 @@ def update(user_id:, tenant_id:, id:, name:)

organisation.update!(name: name)

event = UpdatedEvent
event = Models::Organisation::UpdatedEvent
.where(user_id: user_id, tenant_id: tenant_id)
.create!(
eventable: organisation,
Expand All @@ -73,8 +69,6 @@ def update(user_id:, tenant_id:, id:, name:)
{ id: organisation.id, events: [{ id: event.id, type: event.type }] }
end

class DeletedEvent < Event; end

def delete(user_id:, tenant_id:, id:, time: ::Time)
organisation = nil
event = nil
Expand All @@ -85,7 +79,7 @@ def delete(user_id:, tenant_id:, id:, time: ::Time)

organisation.update!(deleted_at: time.now.utc)

event = DeletedEvent
event = Models::Organisation::DeletedEvent
.where(user_id: user_id, tenant_id: tenant_id)
.create!(
eventable: organisation,
Expand Down
21 changes: 21 additions & 0 deletions app/domains/models/event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module Models
class Event < ActiveRecord::Base
self.table_name = 'events'

# associations

belongs_to :eventable, polymorphic: true

# validations

validates :user_id, presence: true
validates :tenant_id, presence: true

validates :type, presence: true, length: { maximum: 255 }

validates :eventable_type, presence: true, length: { maximum: 255 },
if: -> { eventable_id.present? }

validates :eventable_id, presence: true, if: -> { eventable_type.present? }
end
end
Loading
Loading