mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-19 13:54:25 +01:00
data architecture of prepaid-packs
This commit is contained in:
parent
2b0130c6be
commit
7ac60f6ef3
@ -0,0 +1,9 @@
|
||||
import React from 'react';
|
||||
|
||||
/**
|
||||
* This component is a button that shows the list of prepaid-packs when moving the mouse over it.
|
||||
* When clicked, it opens a modal dialog to configure (add/delete/edit/remove) prepaid-packs.
|
||||
*/
|
||||
const ConfigurePacksButton: React.FC = ({}) => {
|
||||
return <button/>;
|
||||
}
|
26
app/models/prepaid_pack.rb
Normal file
26
app/models/prepaid_pack.rb
Normal file
@ -0,0 +1,26 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Prepaid-packs of hours for machines/spaces.
|
||||
# A prepaid-pack is a set a hours that can be bought by a member. The member will be able to book for free as much hours
|
||||
# as there's in the pack, after having bought one.
|
||||
# The number of hours in each packs is saved in minutes
|
||||
class PrepaidPack < ApplicationRecord
|
||||
belongs_to :priceable, polymorphic: true
|
||||
belongs_to :group
|
||||
|
||||
has_many :user_prepaid_packs
|
||||
|
||||
validates :amount, :group_id, :priceable_id, :priceable_type, :minutes, presence: true
|
||||
|
||||
def hours
|
||||
minutes / 60.0
|
||||
end
|
||||
|
||||
def safe_destroy
|
||||
if user_prepaid_packs.count.zero?
|
||||
destroy
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
@ -38,6 +38,9 @@ class User < ApplicationRecord
|
||||
has_many :training_credits, through: :users_credits, source: :training_credit
|
||||
has_many :machine_credits, through: :users_credits, source: :machine_credit
|
||||
|
||||
has_many :user_prepaid_packs, dependent: :destroy
|
||||
has_many :prepaid_packs, through: :user_prepaid_packs
|
||||
|
||||
has_many :user_tags, dependent: :destroy
|
||||
has_many :tags, through: :user_tags
|
||||
accepts_nested_attributes_for :tags, allow_destroy: true
|
||||
|
9
app/models/user_prepaid_pack.rb
Normal file
9
app/models/user_prepaid_pack.rb
Normal file
@ -0,0 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Associate a customer with a bought prepaid-packs of hours for machines/spaces.
|
||||
# Also saves the amount of hours used
|
||||
class UserPrepaidPack < ApplicationRecord
|
||||
belongs_to :prepaid_pack
|
||||
belongs_to :user
|
||||
|
||||
end
|
15
db/migrate/20210621122103_create_prepaid_packs.rb
Normal file
15
db/migrate/20210621122103_create_prepaid_packs.rb
Normal file
@ -0,0 +1,15 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Prepaid-packs of hours for machines/spaces
|
||||
class CreatePrepaidPacks < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :prepaid_packs do |t|
|
||||
t.references :priceable, polymorphic: true
|
||||
t.references :group, foreign_key: true
|
||||
t.integer :amount
|
||||
t.integer :minutes
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
14
db/migrate/20210621123954_create_user_prepaid_packs.rb
Normal file
14
db/migrate/20210621123954_create_user_prepaid_packs.rb
Normal file
@ -0,0 +1,14 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Bought and consumed prepaid-packs
|
||||
class CreateUserPrepaidPacks < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :user_prepaid_packs do |t|
|
||||
t.references :prepaid_pack, foreign_key: true
|
||||
t.references :user, foreign_key: true
|
||||
t.integer :minutes_used, default: 0
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user