mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-17 06:52:27 +01:00
create reccursive events
This commit is contained in:
parent
a60a39ff9e
commit
26738563bd
@ -617,7 +617,7 @@ Application.Controllers.controller('CreateEventModalController', ['$scope', '$ui
|
||||
|
||||
if ($scope.availability.is_recurrent) {
|
||||
const date = moment($scope.availability.start_at);
|
||||
const diff = moment($scope.availability.start_at).diff($scope.availability.end_at);
|
||||
const diff = moment($scope.availability.end_at).diff($scope.availability.start_at);
|
||||
const end = moment($scope.availability.end_date).endOf('day');
|
||||
while (date.isBefore(end)) {
|
||||
const occur_end = moment(date).add(diff, 'ms');
|
||||
|
@ -47,9 +47,11 @@ class API::AvailabilitiesController < API::ApiController
|
||||
def create
|
||||
authorize Availability
|
||||
@availability = Availability.new(availability_params)
|
||||
service = Availabilities::CreateAvailabilitiesService.new
|
||||
service.create(@availability, params[:availability][:occurrences])
|
||||
if @availability.save
|
||||
if params[:availability][:occurrences]
|
||||
service = Availabilities::CreateAvailabilitiesService.new
|
||||
service.create(@availability, params[:availability][:occurrences])
|
||||
end
|
||||
render :show, status: :created, location: @availability
|
||||
else
|
||||
render json: @availability.errors, status: :unprocessable_entity
|
||||
|
@ -2,10 +2,12 @@
|
||||
|
||||
# Provides helper methods toi create an Availability with multiple occurrences
|
||||
class Availabilities::CreateAvailabilitiesService
|
||||
def create(availability, occurrences)
|
||||
def create(availability, occurrences = [])
|
||||
availability.update_attributes(occurrence_id: availability.id)
|
||||
|
||||
occurrences.each do |o|
|
||||
next if availability.start_at == o[:start_at] && availability.end_at == o[:end_at]
|
||||
|
||||
Availability.new(
|
||||
start_at: o[:start_at],
|
||||
end_at: o[:end_at],
|
||||
|
Loading…
x
Reference in New Issue
Block a user