Class: Spree::Api::V2::Tenant::UserDeviceTokensController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/spree/api/v2/tenant/user_device_tokens_controller.rb

Instance Method Summary collapse

Methods inherited from BaseController

#render_serialized_payload, #require_tenant, #scope

Instance Method Details

#createObject



8
9
10
11
12
13
14
15
16
17
# File 'app/controllers/spree/api/v2/tenant/user_device_tokens_controller.rb', line 8

def create
  options = filter_params.merge(user: spree_current_user)
  context = SpreeCmCommissioner::UserDeviceTokenRegister.call(options)

  if context.success?
    render_serialized_payload { serialize_resource(context.device_token) }
  else
    render_error_payload(context.message)
  end
end

#destroyObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/spree/api/v2/tenant/user_device_tokens_controller.rb', line 19

def destroy
  options = {
    user: spree_current_user,
    registration_token: params[:id]
  }

  context = SpreeCmCommissioner::UserDeviceTokenDeregister.call(options)

  if context.success?
    render json: { message: 'Device token deleted successfully' }, status: :ok
  else
    render_error_payload(context.error)
  end
end

#filter_paramsObject



38
39
40
41
42
43
44
45
# File 'app/controllers/spree/api/v2/tenant/user_device_tokens_controller.rb', line 38

def filter_params
  {
    registration_token: params[:registration_token],
    device_type: params[:device_type],
    client_version: app_version,
    client_name: app_name
  }
end

#resource_serializerObject



34
35
36
# File 'app/controllers/spree/api/v2/tenant/user_device_tokens_controller.rb', line 34

def resource_serializer
  Spree::V2::Tenant::UserDeviceTokenSerializer
end