mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-11-28 09:24:24 +01:00
save prices duration in db
This commit is contained in:
parent
94c4be3e61
commit
5ebc1017d2
@ -11,7 +11,8 @@ export interface Price {
|
||||
plan_id: number,
|
||||
priceable_type: string,
|
||||
priceable_id: number,
|
||||
amount: number
|
||||
amount: number,
|
||||
duration: number // in minutes
|
||||
}
|
||||
|
||||
export interface ComputePriceResult {
|
||||
|
@ -16,7 +16,7 @@ class CartItem::Reservation < CartItem::BaseItem
|
||||
end
|
||||
|
||||
def price
|
||||
base_amount = @reservable.prices.find_by(group_id: @customer.group_id, plan_id: @plan.try(:id)).amount
|
||||
base_amount = @reservable.prices.find_by(group_id: @customer.group_id, plan_id: @plan.try(:id), duration: 60).amount
|
||||
is_privileged = @operator.privileged? && @operator.id != @customer.id
|
||||
prepaid = { minutes: PrepaidPackService.minutes_available(@customer, @reservable) }
|
||||
|
||||
|
@ -1,2 +1,4 @@
|
||||
json.extract! price, :id, :group_id, :plan_id, :priceable_type, :priceable_id
|
||||
# frozen_string_literal: true
|
||||
|
||||
json.extract! price, :id, :group_id, :plan_id, :priceable_type, :priceable_id, :duration
|
||||
json.amount price.amount / 100.0
|
||||
|
@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
json.price @amount[:total] / 100.00
|
||||
json.price_without_coupon @amount[:before_coupon] / 100.00
|
||||
if @amount[:elements]
|
||||
|
@ -1 +1,3 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
json.partial! 'api/prices/price', collection: @prices, as: :price
|
||||
|
10
db/migrate/20211220143400_add_duration_to_price.rb
Normal file
10
db/migrate/20211220143400_add_duration_to_price.rb
Normal file
@ -0,0 +1,10 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# From this migration, we allow Prices to be configured by duration.
|
||||
# For example, a Price for a 30-minute session could be configured to be twice the price of a 60-minute session.
|
||||
# This is useful for things like "half-day" sessions, or full-day session when the price is different than the default hour-based price.
|
||||
class AddDurationToPrice < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :prices, :duration, :integer, default: 60
|
||||
end
|
||||
end
|
@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2021_10_18_121822) do
|
||||
ActiveRecord::Schema.define(version: 2021_12_20_143400) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "fuzzystrmatch"
|
||||
@ -492,6 +492,7 @@ ActiveRecord::Schema.define(version: 2021_10_18_121822) do
|
||||
t.integer "weight"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.text "description"
|
||||
end
|
||||
|
||||
create_table "plans", id: :serial, force: :cascade do |t|
|
||||
@ -554,6 +555,7 @@ ActiveRecord::Schema.define(version: 2021_10_18_121822) do
|
||||
t.integer "amount"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.integer "duration", default: 60
|
||||
t.index ["group_id"], name: "index_prices_on_group_id"
|
||||
t.index ["plan_id"], name: "index_prices_on_plan_id"
|
||||
t.index ["priceable_type", "priceable_id"], name: "index_prices_on_priceable_type_and_priceable_id"
|
||||
|
Loading…
Reference in New Issue
Block a user