Skip to content

Commit

Permalink
Fix #create_or_update_student (#14)
Browse files Browse the repository at this point in the history
* Fix #create_or_update_student

* Refacto
  • Loading branch information
grmnlrt authored Jan 25, 2024
1 parent b2eef61 commit 75f1a3e
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/edusign/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,12 @@ def update_student(student_uid:, first_name:, last_name:, email:, group_uids: []
end

def create_or_update_student(first_name:, last_name:, email:, student_uid: nil, group_uids: [])
student = student_uid.present? ? student_by_uid(student_uid: student_uid) : student_by_email(email: email)
@student = student_by_uid(student_uid: student_uid) if student_uid.present?
@student = student_by_email(email: email) if @student.nil?
raise Response::Error, "Student doesn't exist" if student.nil?
raise Response::Error, "Student was deleted from edusign" if student[:HIDDEN] == 1
raise Response::Error, "Student was deleted from edusign" if @student[:HIDDEN] == 1

update_student(student_uid: student[:ID], first_name: first_name, last_name: last_name, email: email, group_uids: group_uids)
update_student(student_uid: @student[:ID], first_name: first_name, last_name: last_name, email: email, group_uids: group_uids)
rescue Response::Error => _e
create_student(first_name: first_name, last_name: last_name, email: email, group_uids: group_uids)
end
Expand Down

0 comments on commit 75f1a3e

Please sign in to comment.