1
0
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:
Sylvain 2021-06-21 14:58:49 +02:00
parent 2b0130c6be
commit 7ac60f6ef3
6 changed files with 76 additions and 0 deletions

View File

@ -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/>;
}

View 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

View File

@ -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

View 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

View 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

View 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