1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-17 06:52:27 +01:00

[ongoing] db architecture for custom prices reservation

This commit is contained in:
Sylvain 2016-08-25 18:41:33 +02:00
parent 4fd31c3e9b
commit c6a83e98cb
11 changed files with 75 additions and 12 deletions

View File

@ -150,9 +150,9 @@ Application.Controllers.controller "ShowEventController", ["$scope", "$state", "
## parameters for a new reservation
$scope.reserve =
nbPlaces: []
nbReducedPlaces: []
nbReducedPlaces: [] #FIXME
nbReservePlaces: 0
nbReserveReducedPlaces: 0
nbReserveReducedPlaces: 0 #FIXME
toReserve: false
amountTotal : 0
@ -183,7 +183,7 @@ Application.Controllers.controller "ShowEventController", ["$scope", "$state", "
##
$scope.changeNbPlaces = ->
reste = $scope.event.nb_free_places - $scope.reserve.nbReservePlaces
$scope.reserve.nbReducedPlaces = [0..reste]
$scope.reserve.nbReducedPlaces = [0..reste] #FIXME
$scope.computeEventAmount()
@ -191,7 +191,7 @@ Application.Controllers.controller "ShowEventController", ["$scope", "$state", "
##
# Callback to call when the number of discounted places change in the current booking
##
$scope.changeNbReducedPlaces = ->
$scope.changeNbReducedPlaces = -> #FIXME
reste = $scope.event.nb_free_places - $scope.reserve.nbReserveReducedPlaces
$scope.reserve.nbPlaces = [0..reste]
$scope.computeEventAmount()
@ -270,7 +270,7 @@ Application.Controllers.controller "ShowEventController", ["$scope", "$state", "
reservable_type: 'Event'
slots_attributes: []
nb_reserve_places: $scope.reserve.nbReservePlaces
nb_reserve_reduced_places: $scope.reserve.nbReserveReducedPlaces
nb_reserve_reduced_places: $scope.reserve.nbReserveReducedPlaces #FIXME
reservation.slots_attributes.push
start_at: $scope.event.start_date
end_at: $scope.event.end_date
@ -420,7 +420,7 @@ Application.Controllers.controller "ShowEventController", ["$scope", "$state", "
# initialize the "reserve" object with the event's data
$scope.reserve.nbPlaces = [0..$scope.event.nb_free_places]
$scope.reserve.nbReducedPlaces = [0..$scope.event.nb_free_places]
$scope.reserve.nbReducedPlaces = [0..$scope.event.nb_free_places] #FIXME
# if non-admin, get the current user's reservations into $scope.reservations
if $scope.currentUser
@ -458,7 +458,7 @@ Application.Controllers.controller "ShowEventController", ["$scope", "$state", "
reservable_type: 'Event'
slots_attributes: []
nb_reserve_places: reserve.nbReservePlaces
nb_reserve_reduced_places: reserve.nbReserveReducedPlaces
tickets_attributes: []
reservation.slots_attributes.push
start_at: event.start_date
@ -466,6 +466,11 @@ Application.Controllers.controller "ShowEventController", ["$scope", "$state", "
availability_id: event.availability.id
offered: event.offered || false
for price in event.prices
reservation.tickets_attributes.push
event_price_category_id: price.id
booked: reserve.fixme #FIXME
reservation
@ -491,7 +496,7 @@ Application.Controllers.controller "ShowEventController", ["$scope", "$state", "
if $scope.event
$scope.reserve =
nbPlaces: [0..$scope.event.nb_free_places]
nbReducedPlaces: [0..$scope.event.nb_free_places]
nbReducedPlaces: [0..$scope.event.nb_free_places] #FIXME
nbReservePlaces: 0
nbReserveReducedPlaces: 0
toReserve: false

View File

@ -61,7 +61,8 @@ class API::PricesController < API::ApiController
end
def compute_price_params
params.require(:reservation).permit(:reservable_id, :reservable_type, :plan_id, :user_id, :nb_reserve_places, :nb_reserve_reduced_places,
params.require(:reservation).permit(:reservable_id, :reservable_type, :plan_id, :user_id, :nb_reserve_places,
tickets_attributes: [:event_price_category_id, :booked],
slots_attributes: [:id, :start_at, :end_at, :availability_id, :offered])
end

View File

@ -52,7 +52,8 @@ class API::ReservationsController < API::ApiController
def reservation_params
params.require(:reservation).permit(:user_id, :message, :reservable_id, :reservable_type, :card_token, :plan_id,
:nb_reserve_places, :nb_reserve_reduced_places,
:nb_reserve_places,
tickets_attributes: [:event_price_category_id, :booked],
slots_attributes: [:id, :start_at, :end_at, :availability_id, :offered])
end

View File

@ -12,7 +12,7 @@ class Event < ActiveRecord::Base
has_many :event_price_categories
has_many :price_categories, through: :event_price_categories
accepts_nested_attributes_for :event_price_categories, allow_destroy: true
accepts_nested_attributes_for :event_price_categories, allow_destroy: false
belongs_to :age_range

View File

@ -2,6 +2,8 @@ class EventPriceCategory < ActiveRecord::Base
belongs_to :event
belongs_to :price_category
has_many :tickets
validates :event_id, presence: true
validates :price_category_id, presence: true
validates :amount, presence: true

View File

@ -6,6 +6,9 @@ class Reservation < ActiveRecord::Base
accepts_nested_attributes_for :slots, allow_destroy: true
belongs_to :reservable, polymorphic: true
has_many :tickets
accepts_nested_attributes_for :tickets, allow_destroy: false
has_one :invoice, -> {where(type: nil)}, as: :invoiced, dependent: :destroy
validates_presence_of :reservable_id, :reservable_type

9
app/models/ticket.rb Normal file
View File

@ -0,0 +1,9 @@
class Ticket < ActiveRecord::Base
belongs_to :reservation
belongs_to :event_price_category
validates :reservation_id, presence: true
validates :event_price_category_id, presence: true
validates :booked, presence: true
validates :booked, numericality: { only_integer: true, greater_than: 0 }
end

View File

@ -0,0 +1,11 @@
class CreateTickets < ActiveRecord::Migration
def change
create_table :tickets do |t|
t.belongs_to :reservation, index: true, foreign_key: true
t.belongs_to :event_price_category, index: true, foreign_key: true
t.integer :booked
t.timestamps null: false
end
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160824084111) do
ActiveRecord::Schema.define(version: 20160825141326) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -633,6 +633,17 @@ ActiveRecord::Schema.define(version: 20160824084111) do
t.string "name", limit: 255, null: false
end
create_table "tickets", force: :cascade do |t|
t.integer "reservation_id"
t.integer "event_price_category_id"
t.integer "booked"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "tickets", ["event_price_category_id"], name: "index_tickets_on_event_price_category_id", using: :btree
add_index "tickets", ["reservation_id"], name: "index_tickets_on_reservation_id", using: :btree
create_table "trainings", force: :cascade do |t|
t.string "name", limit: 255
t.datetime "created_at"
@ -796,6 +807,8 @@ ActiveRecord::Schema.define(version: 20160824084111) do
add_foreign_key "organizations", "profiles"
add_foreign_key "prices", "groups"
add_foreign_key "prices", "plans"
add_foreign_key "tickets", "event_price_categories"
add_foreign_key "tickets", "reservations"
add_foreign_key "user_tags", "tags"
add_foreign_key "user_tags", "users"
add_foreign_key "wallet_transactions", "users"

11
test/fixtures/tickets.yml vendored Normal file
View File

@ -0,0 +1,11 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
reservation_id:
event_price_category_id:
booked: 1
two:
reservation_id:
event_price_category_id:
booked: 1

View File

@ -0,0 +1,7 @@
require 'test_helper'
class TicketTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end