Skip to content

Instantly share code, notes, and snippets.

@apneadiving
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apneadiving/705e2af19c5a78d936f3 to your computer and use it in GitHub Desktop.
Save apneadiving/705e2af19c5a78d936f3 to your computer and use it in GitHub Desktop.
wf example
def accept_group_terms
if current_entity.user? && notification.group_terms?
if params[:terms_of_service][:checked]
user_group = notification.entity.user_groups.with_user(current_entity).first
if user_group
user_group.terms_accepted_at = Time.now
user_group.save
notification.mark_as_read_by(current_entity).save!
render_notif
else
render json: { errors: [ 'You are not allowed to answer this form' ] }, status: 422
end
else
render json: { errors: [ 'You must accept the terms' ] }, status: 422
end
else
render json: { errors: [ 'You cannot answer this form' ] }, status: 422
end
end
def accept_group_terms
Wf.new
.when_falsy { current_entity.user? && notification.group_terms? }
.dam { 'You cannot answer this form' }
.when_falsy { params[:terms_of_service][:checked] }
.dam { 'You must accept the terms' }
.when_falsy { @user_group = notification.entity.user_groups.with_user(current_entity).first }
.dam { 'You are not allowed to answer this form' }
.chain {
@user_group.terms_accepted_at = Time.now
@user_group.save
notification.mark_as_read_by(current_entity).save!
render_notif
}
.on_dam { |err| render json: { errors: [err] }, status: 422 }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment