mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-21 15:54:22 +01:00
fixed: create event with custom price
This commit is contained in:
parent
c4b3c1eab5
commit
80aab9f17c
@ -97,7 +97,7 @@ class API::EventsController < API::ApiController
|
|||||||
event_theme_ids: [],
|
event_theme_ids: [],
|
||||||
event_image_attributes: [:attachment],
|
event_image_attributes: [:attachment],
|
||||||
event_files_attributes: %i[id attachment_destroy],
|
event_files_attributes: %i[id attachment_destroy],
|
||||||
event_price_categories_attributes: %i[id price_category_id amount_destroy])
|
event_price_categories_attributes: %i[id price_category_id amount _destroy])
|
||||||
EventService.process_params(event_preparams)
|
EventService.process_params(event_preparams)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
class EventService
|
class EventService
|
||||||
def self.process_params(params)
|
def self.process_params(params)
|
||||||
# handle dates & times (whole-day events or not, maybe during many days)
|
# handle dates & times (whole-day events or not, maybe during many days)
|
||||||
range = EventService.date_range({date: params[:start_date], time: params[:start_time] },
|
range = EventService.date_range({ date: params[:start_date], time: params[:start_time] },
|
||||||
{ date: params[:end_date], time: params[:end_time] },
|
{ date: params[:end_date], time: params[:end_time] },
|
||||||
params[:all_day] == 'true')
|
params[:all_day] == 'true')
|
||||||
params.merge!(availability_attributes: { id: params[:availability_id],
|
params.merge!(availability_attributes: { id: params[:availability_id],
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
module Events
|
module Events
|
||||||
class AsAdminTest < ActionDispatch::IntegrationTest
|
class AsAdminTest < ActionDispatch::IntegrationTest
|
||||||
|
|
||||||
@ -11,16 +12,16 @@ module Events
|
|||||||
# First, we create a new event
|
# First, we create a new event
|
||||||
post '/api/events',
|
post '/api/events',
|
||||||
{
|
{
|
||||||
event: {
|
event: {
|
||||||
title: 'OpenLab discovery day',
|
title: 'OpenLab discovery day',
|
||||||
description: 'A day to discover the Fablab and try its machines and possibilities.',
|
description: 'A day to discover the Fablab and try its machines and possibilities.',
|
||||||
start_date: 1.week.from_now.utc,
|
start_date: 1.week.from_now.utc,
|
||||||
start_time: 1.week.from_now.utc.change({hour: 16}),
|
start_time: 1.week.from_now.utc.change(hour: 16),
|
||||||
end_date: 1.week.from_now.utc,
|
end_date: 1.week.from_now.utc,
|
||||||
end_time: 1.week.from_now.utc.change({hour: 20}),
|
end_time: 1.week.from_now.utc.change(hour: 20),
|
||||||
category_id: Category.first.id,
|
category_id: Category.first.id,
|
||||||
amount: 0
|
amount: 0
|
||||||
}
|
}
|
||||||
}.to_json,
|
}.to_json,
|
||||||
default_headers
|
default_headers
|
||||||
|
|
||||||
@ -38,18 +39,16 @@ module Events
|
|||||||
|
|
||||||
# Then, modify the event to set a nb of places
|
# Then, modify the event to set a nb of places
|
||||||
put "/api/events/#{e.id}",
|
put "/api/events/#{e.id}",
|
||||||
{
|
event: {
|
||||||
event: {
|
title: 'OpenLab discovery day',
|
||||||
title: 'OpenLab discovery day',
|
description: 'A day to discover the Fablab and try its machines and possibilities.',
|
||||||
description: 'A day to discover the Fablab and try its machines and possibilities.',
|
start_date: 1.week.from_now.utc,
|
||||||
start_date: 1.week.from_now.utc,
|
start_time: 1.week.from_now.utc.change(hour: 16),
|
||||||
start_time: 1.week.from_now.utc.change({hour: 16}),
|
end_date: 1.week.from_now.utc,
|
||||||
end_date: 1.week.from_now.utc,
|
end_time: 1.week.from_now.utc.change(hour: 20),
|
||||||
end_time: 1.week.from_now.utc.change({hour: 20}),
|
category_id: Category.first.id,
|
||||||
category_id: Category.first.id,
|
amount: 0,
|
||||||
amount: 0,
|
nb_total_places: 10
|
||||||
nb_total_places: 10
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check response format & status
|
# Check response format & status
|
||||||
@ -63,23 +62,23 @@ module Events
|
|||||||
|
|
||||||
# Now, let's make a reservation on this event
|
# Now, let's make a reservation on this event
|
||||||
post '/api/reservations',
|
post '/api/reservations',
|
||||||
{
|
{
|
||||||
reservation: {
|
reservation: {
|
||||||
user_id: User.find_by(username: 'pdurand').id,
|
user_id: User.find_by(username: 'pdurand').id,
|
||||||
reservable_id: e.id,
|
reservable_id: e.id,
|
||||||
reservable_type: 'Event',
|
reservable_type: 'Event',
|
||||||
nb_reserve_places: 2,
|
nb_reserve_places: 2,
|
||||||
slots_attributes: [
|
slots_attributes: [
|
||||||
{
|
{
|
||||||
start_at: e.availability.start_at,
|
start_at: e.availability.start_at,
|
||||||
end_at: e.availability.end_at,
|
end_at: e.availability.end_at,
|
||||||
availability_id: e.availability.id,
|
availability_id: e.availability.id,
|
||||||
offered: false
|
offered: false
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}.to_json,
|
}.to_json,
|
||||||
default_headers
|
default_headers
|
||||||
|
|
||||||
# Check response format & status
|
# Check response format & status
|
||||||
assert_equal 201, response.status, response.body
|
assert_equal 201, response.status, response.body
|
||||||
@ -91,18 +90,16 @@ module Events
|
|||||||
|
|
||||||
# Finally, modify the event to add some places
|
# Finally, modify the event to add some places
|
||||||
put "/api/events/#{e.id}",
|
put "/api/events/#{e.id}",
|
||||||
{
|
event: {
|
||||||
event: {
|
title: 'OpenLab discovery day',
|
||||||
title: 'OpenLab discovery day',
|
description: 'A day to discover the Fablab and try its machines and possibilities.',
|
||||||
description: 'A day to discover the Fablab and try its machines and possibilities.',
|
start_date: 1.week.from_now.utc,
|
||||||
start_date: 1.week.from_now.utc,
|
start_time: 1.week.from_now.utc.change(hour: 16),
|
||||||
start_time: 1.week.from_now.utc.change({hour: 16}),
|
end_date: 1.week.from_now.utc,
|
||||||
end_date: 1.week.from_now.utc,
|
end_time: 1.week.from_now.utc.change(hour: 20),
|
||||||
end_time: 1.week.from_now.utc.change({hour: 20}),
|
category_id: Category.first.id,
|
||||||
category_id: Category.first.id,
|
amount: 0,
|
||||||
amount: 0,
|
nb_total_places: 20
|
||||||
nb_total_places: 20
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check response format & status
|
# Check response format & status
|
||||||
@ -122,23 +119,23 @@ module Events
|
|||||||
# First, we create a new event
|
# First, we create a new event
|
||||||
post '/api/events',
|
post '/api/events',
|
||||||
{
|
{
|
||||||
event: {
|
event: {
|
||||||
title: 'Electronics initiation',
|
title: 'Electronics initiation',
|
||||||
description: 'A workshop about electronics and the abilities to create robots.',
|
description: 'A workshop about electronics and the abilities to create robots.',
|
||||||
start_date: 1.week.from_now.utc + 2.days,
|
start_date: 1.week.from_now.utc + 2.days,
|
||||||
start_time: 1.week.from_now.utc.change({hour: 18}) + 2.days,
|
start_time: 1.week.from_now.utc.change(hour: 18) + 2.days,
|
||||||
end_date: 1.week.from_now.utc + 2.days,
|
end_date: 1.week.from_now.utc + 2.days,
|
||||||
end_time: 1.week.from_now.utc.change({hour: 22}) + 2.days,
|
end_time: 1.week.from_now.utc.change(hour: 22) + 2.days,
|
||||||
category_id: Category.last.id,
|
category_id: Category.last.id,
|
||||||
amount: 20,
|
amount: 20,
|
||||||
nb_total_places: 10,
|
nb_total_places: 10,
|
||||||
event_price_categories_attributes: [
|
event_price_categories_attributes: [
|
||||||
{
|
{
|
||||||
price_category_id: price_category.id.to_s,
|
price_category_id: price_category.id.to_s,
|
||||||
amount: 16.to_s
|
amount: 16.to_s
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}.to_json,
|
}.to_json,
|
||||||
default_headers
|
default_headers
|
||||||
|
|
||||||
@ -159,26 +156,26 @@ module Events
|
|||||||
# Now, let's make a reservation on this event
|
# Now, let's make a reservation on this event
|
||||||
post '/api/reservations',
|
post '/api/reservations',
|
||||||
{
|
{
|
||||||
reservation: {
|
reservation: {
|
||||||
user_id: User.find_by(username: 'lseguin').id,
|
user_id: User.find_by(username: 'lseguin').id,
|
||||||
reservable_id: e.id,
|
reservable_id: e.id,
|
||||||
reservable_type: 'Event',
|
reservable_type: 'Event',
|
||||||
nb_reserve_places: 4,
|
nb_reserve_places: 4,
|
||||||
slots_attributes: [
|
slots_attributes: [
|
||||||
{
|
{
|
||||||
start_at: e.availability.start_at,
|
start_at: e.availability.start_at,
|
||||||
end_at: e.availability.end_at,
|
end_at: e.availability.end_at,
|
||||||
availability_id: e.availability.id,
|
availability_id: e.availability.id,
|
||||||
offered: false
|
offered: false
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
tickets_attributes: [
|
tickets_attributes: [
|
||||||
{
|
{
|
||||||
event_price_category_id: e.event_price_categories.first.id,
|
event_price_category_id: e.event_price_categories.first.id,
|
||||||
booked: 4
|
booked: 4
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}.to_json,
|
}.to_json,
|
||||||
default_headers
|
default_headers
|
||||||
|
|
||||||
@ -203,4 +200,4 @@ module Events
|
|||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user