Class: Kidspire::Api::V1::SyncSettingsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/kidspire/api/v1/sync_settings_controller.rb

Instance Method Summary collapse

Instance Method Details

#showObject



7
8
9
# File 'app/controllers/kidspire/api/v1/sync_settings_controller.rb', line 7

def show
  render json: SyncSettingBlueprint.render(SyncSetting.current)
end

#updateObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/kidspire/api/v1/sync_settings_controller.rb', line 11

def update
  settings = SyncSetting.current
  was_auto  = settings.auto_sync_enabled?

  if settings.update(sync_setting_params)
    # If auto-sync was just enabled, kick off the scheduled chain
    if settings.auto_sync_enabled? && !was_auto
      Kidspire::PcoScheduledSyncJob.kick_off_if_enabled!
    end
    render json: SyncSettingBlueprint.render(settings)
  else
    render json: { error: settings.errors.full_messages.first, code: "validation_error" },
           status: :unprocessable_entity
  end
end