Skip to content

Nested operation DecryptEmailToken

Vladislav Trotsenko edited this page Sep 27, 2019 · 8 revisions

Synopsis

The point of this nested operation is setting model from decrypted jwt email token payload.

Code

module Api::V1::Users::Lib::Operation
  class DecryptEmailToken < ApplicationOperation
    step Macro::Contract::Schema(Api::V1::Users::Lib::Contract::DecryptEmailTokenValidation)
    step Contract::Validate(), fail_fast: true
    step Macro::Assign(to: :email_token, path: %w[contract.default email_token]) # sets to email_token to context
    step :set_payload # extracts and sets payload from email_token to context
    fail Macro::AddContractError(base: 'errors.verification.invalid_email_token'), fail_fast: true # add custom error
    step :set_model # sets model by payload
    fail Macro::Semantic(failure: :not_found), fail_fast: true # sets not_found status
  end
end

Used nested & macroses

Clone this wiki locally