mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-18 07:52:23 +01:00
[bug] when an event is modified, the member's reservations does not reflect the new event date
This commit is contained in:
parent
1c22d3a62a
commit
588b8050db
@ -6,6 +6,7 @@
|
||||
- Updated environment documentation
|
||||
- Removed useless locales' configuration files
|
||||
- OpenAPI's endpoints will now return more detailed error messages when something wrong occurs
|
||||
- Fix a bug: when an event is modified, the member's reservations does not reflect the new event date
|
||||
- Fix a security issue: updated ini to 1.3.8 to fix [CVE-2020-7788](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2020-7788)
|
||||
− Fix a security issue: updated nokogiri to 1.11.1 to fix [CVE-2020-26247](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2020-26247)
|
||||
- Updated caxlsx to 3.0.4, and the dependencies of caxlsx_rail
|
||||
|
@ -2,7 +2,8 @@
|
||||
|
||||
# Provides helper methods for Events resources and properties
|
||||
class EventService
|
||||
def self.process_params(params)
|
||||
class << self
|
||||
def process_params(params)
|
||||
# handle dates & times (whole-day events or not, maybe during many days)
|
||||
range = EventService.date_range({ date: params[:start_date], time: params[:start_time] },
|
||||
{ date: params[:end_date], time: params[:end_time] },
|
||||
@ -27,7 +28,7 @@ class EventService
|
||||
params
|
||||
end
|
||||
|
||||
def self.date_range(starting, ending, all_day)
|
||||
def date_range(starting, ending, all_day)
|
||||
start_date = Time.zone.parse(starting[:date])
|
||||
end_date = Time.zone.parse(ending[:date])
|
||||
start_time = Time.parse(starting[:time]) if starting[:time]
|
||||
@ -43,7 +44,7 @@ class EventService
|
||||
end
|
||||
|
||||
# delete one or more events (if periodic)
|
||||
def self.delete(event_id, mode = 'single')
|
||||
def delete(event_id, mode = 'single')
|
||||
results = []
|
||||
event = Event.find(event_id)
|
||||
events = case mode
|
||||
@ -74,8 +75,7 @@ class EventService
|
||||
end
|
||||
|
||||
# update one or more events (if periodic)
|
||||
def self.update(event, event_params, mode = 'single')
|
||||
results = []
|
||||
def update(event, event_params, mode = 'single')
|
||||
events = case mode
|
||||
when 'single'
|
||||
[event]
|
||||
@ -96,7 +96,13 @@ class EventService
|
||||
else
|
||||
[]
|
||||
end
|
||||
update_events(event, events, event_params)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def update_events(event, events, event_params)
|
||||
results = []
|
||||
events.each do |e|
|
||||
next unless e.id != event.id
|
||||
|
||||
@ -162,12 +168,26 @@ class EventService
|
||||
rescue StandardError => err
|
||||
results.push status: false, event: e, error: err.try(:record).try(:class).try(:name), message: err.message
|
||||
end
|
||||
results.concat(update_slots(e.availability_id))
|
||||
end
|
||||
begin
|
||||
results.push status: !!event.update(event_params), event: event # rubocop:disable Style/DoubleNegation
|
||||
rescue StandardError => err
|
||||
results.push status: false, event: event, error: err.try(:record).try(:class).try(:name), message: err.message
|
||||
end
|
||||
results.concat(update_slots(event.availability_id))
|
||||
results
|
||||
end
|
||||
|
||||
def update_slots(availability_id)
|
||||
results = []
|
||||
avail = Availability.find(availability_id)
|
||||
avail.slots.each do |s|
|
||||
results.push(status: !!s.update_attributes(start_at: avail.start_at, end_at: avail.end_at), slot: s) # rubocop:disable Style/DoubleNegation
|
||||
rescue StandardError => err
|
||||
results.push status: false, slot: s, error: err.try(:record).try(:class).try(:name), message: err.message
|
||||
end
|
||||
results
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user