mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-21 15:54:22 +01:00
update all attributes of event
This commit is contained in:
parent
b1419271e6
commit
de02bb1c72
@ -80,7 +80,7 @@ class EventService
|
|||||||
when 'single'
|
when 'single'
|
||||||
[event]
|
[event]
|
||||||
when 'next'
|
when 'next'
|
||||||
Event.includes(:availability)
|
Event.includes(:availability, :event_price_categories, :event_files)
|
||||||
.where(
|
.where(
|
||||||
'availabilities.start_at >= ? AND events.recurrence_id = ?',
|
'availabilities.start_at >= ? AND events.recurrence_id = ?',
|
||||||
event.availability.start_at,
|
event.availability.start_at,
|
||||||
@ -88,7 +88,8 @@ class EventService
|
|||||||
)
|
)
|
||||||
.references(:availabilities, :events)
|
.references(:availabilities, :events)
|
||||||
when 'all'
|
when 'all'
|
||||||
Event.where(
|
Event.includes(:availability, :event_price_categories, :event_files)
|
||||||
|
.where(
|
||||||
'recurrence_id = ?',
|
'recurrence_id = ?',
|
||||||
event.recurrence_id
|
event.recurrence_id
|
||||||
)
|
)
|
||||||
@ -97,14 +98,67 @@ class EventService
|
|||||||
end
|
end
|
||||||
|
|
||||||
events.each do |e|
|
events.each do |e|
|
||||||
if e.id == event.id
|
if e.id != event.id
|
||||||
results.push status: !!e.update(event_params), event: e # rubocop:disable Style/DoubleNegation
|
start_at = event_params['availability_attributes']['start_at']
|
||||||
|
end_at = event_params['availability_attributes']['end_at']
|
||||||
|
event_price_categories_attributes = event_params['event_price_categories_attributes']
|
||||||
|
event_files_attributes = event_params['event_files_attributes']
|
||||||
|
e_params = event_params.merge(
|
||||||
|
availability_id: e.availability_id,
|
||||||
|
availability_attributes: {
|
||||||
|
id: e.availability_id,
|
||||||
|
start_at: e.availability.start_at.change(hour: start_at.hour, min: start_at.min),
|
||||||
|
end_at: e.availability.end_at.change(hour: end_at.hour, min: end_at.min),
|
||||||
|
available_type: e.availability.available_type
|
||||||
|
}
|
||||||
|
)
|
||||||
|
epc_attributes = []
|
||||||
|
if event_price_categories_attributes
|
||||||
|
event_price_categories_attributes.each do |epca|
|
||||||
|
epc = e.event_price_categories.find_by(price_category_id: epca['price_category_id'])
|
||||||
|
if epc
|
||||||
|
epc_attributes.push(
|
||||||
|
id: epc.id,
|
||||||
|
price_category_id: epc.price_category_id,
|
||||||
|
amount: epca['amount'],
|
||||||
|
_destroy: epca['_destroy']
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
unless epc_attributes.empty?
|
||||||
|
e_params = e_params.merge(
|
||||||
|
event_price_categories_attributes: epc_attributes
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
ef_attributes = []
|
||||||
|
if event_files_attributes
|
||||||
|
event_files_attributes.each do |efa|
|
||||||
|
if efa['id'].present?
|
||||||
|
event_file = event.event_files.find(efa['id'])
|
||||||
|
ef = e.event_files.find_by(attachment: event_file.attachment.file.filename)
|
||||||
|
if ef
|
||||||
|
ef_attributes.push(
|
||||||
|
id: ef.id,
|
||||||
|
attachment: efa['attachment'],
|
||||||
|
_destroy: efa['_destroy']
|
||||||
|
)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
puts '------------'
|
ef_attributes.push(efa)
|
||||||
puts e.id
|
|
||||||
puts event_params
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
unless ef_attributes.empty?
|
||||||
|
e_params = e_params.merge(
|
||||||
|
event_files_attributes: ef_attributes
|
||||||
|
)
|
||||||
|
end
|
||||||
|
results.push status: !!e.update(e_params.permit!), event: e # rubocop:disable Style/DoubleNegation
|
||||||
|
end
|
||||||
|
end
|
||||||
|
results.push status: !!event.update(event_params), event: event # rubocop:disable Style/DoubleNegation
|
||||||
results
|
results
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user