Skip to content

Commit

Permalink
Marketplace: Sprout model for OrderNotificationMethod
Browse files Browse the repository at this point in the history
- #1511

OK this is awkwardly named, but it is the first tiny step towards
allowing us to manage multiple order notification emails without the
silly comma separated value.
  • Loading branch information
zspencer committed Jun 15, 2023
1 parent 884907c commit a627714
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 2 deletions.
2 changes: 2 additions & 0 deletions app/furniture/marketplace/marketplace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class Marketplace < Furniture

has_many :delivery_areas, inverse_of: :marketplace, dependent: :destroy

has_many :order_notification_methods, inverse_of: :marketplace, dependent: :destroy

setting :notify_emails
setting :stripe_account
alias_method :vendor_stripe_account, :stripe_account
Expand Down
2 changes: 1 addition & 1 deletion app/furniture/marketplace/order/received_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class Marketplace
class Order
class ReceivedMailer < Mailer
def to
order.marketplace.notify_emails.split(",")
order.marketplace.notify_emails.split(",") + order.marketplace.order_notification_methods.map(&:contact_location)
end
end
end
Expand Down
12 changes: 12 additions & 0 deletions app/furniture/marketplace/order_notification_method.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

class Marketplace
class OrderNotificationMethod < Record
self.table_name = :marketplace_order_notification_methods
location(parent: :marketplace)
belongs_to :marketplace, inverse_of: :order_notification_methods

has_encrypted :contact_location
validates :contact_location, presence: true
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class AddMarketplaceOrderNotificationMethods < ActiveRecord::Migration[7.0]
def change
create_table :marketplace_order_notification_methods, id: :uuid do |t|
t.references :marketplace, type: :uuid, foreign_key: {to_table: :furnitures}
t.string :contact_method, default: :email, null: false
t.string :contact_location_ciphertext, null: false
t.timestamps
end
end
end
12 changes: 11 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2023_05_18_014356) do
ActiveRecord::Schema[7.0].define(version: 2023_06_15_002110) do
# These are extensions that must be enabled in order to support this database
enable_extension "pgcrypto"
enable_extension "plpgsql"
Expand Down Expand Up @@ -139,6 +139,15 @@
t.index ["marketplace_id"], name: "index_marketplace_delivery_areas_on_marketplace_id"
end

create_table "marketplace_order_notification_methods", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.uuid "marketplace_id"
t.string "contact_method", default: "email", null: false
t.string "contact_location_ciphertext", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["marketplace_id"], name: "index_marketplace_order_notification_methods_on_marketplace_id"
end

create_table "marketplace_orders", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.uuid "marketplace_id"
t.datetime "created_at", null: false
Expand Down Expand Up @@ -270,6 +279,7 @@
add_foreign_key "marketplace_cart_products", "marketplace_orders", column: "cart_id"
add_foreign_key "marketplace_cart_products", "marketplace_products", column: "product_id"
add_foreign_key "marketplace_delivery_areas", "furnitures", column: "marketplace_id"
add_foreign_key "marketplace_order_notification_methods", "furnitures", column: "marketplace_id"
add_foreign_key "marketplace_orders", "marketplace_delivery_areas", column: "delivery_area_id"
add_foreign_key "marketplace_orders", "marketplace_shoppers", column: "shopper_id"
add_foreign_key "marketplace_product_tax_rates", "marketplace_products", column: "product_id"
Expand Down

0 comments on commit a627714

Please sign in to comment.