Last active
August 29, 2015 14:08
-
-
Save apneadiving/705e2af19c5a78d936f3 to your computer and use it in GitHub Desktop.
wf example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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