Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modify non-handler methods to not write a response #122

Merged
merged 2 commits into from
Sep 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions api/invite.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type (

// Checks do they have an existing invite or are they already a team member
// Or are they an existing user and already in the group?
func (a *Api) checkForDuplicateInvite(ctx context.Context, inviteeEmail, invitorID string, res http.ResponseWriter) bool {
func (a *Api) checkForDuplicateInvite(ctx context.Context, inviteeEmail, invitorID string) bool {

//already has invite from this user?
invites, _ := a.Store.FindConfirmations(
Expand All @@ -50,8 +50,6 @@ func (a *Api) checkForDuplicateInvite(ctx context.Context, inviteeEmail, invitor
if !invites[0].IsExpired() {
log.Println(statusExistingInviteMessage)
log.Println("last invite not yet expired")
statusErr := &status.StatusError{Status: status.NewStatus(http.StatusConflict, statusExistingInviteMessage)}
a.sendModelAsResWithStatus(res, statusErr, http.StatusConflict)
return true
}
}
Expand All @@ -72,7 +70,7 @@ func (a *Api) checkExistingPatientOfClinic(ctx context.Context, clinicId, patien
return false, fmt.Errorf("unexpected status code %v when checking if user is existing patient", response.StatusCode())
}

func (a *Api) checkAccountAlreadySharedWithUser(invitorID, inviteeEmail string, res http.ResponseWriter) (bool, *shoreline.UserData) {
func (a *Api) checkAccountAlreadySharedWithUser(invitorID, inviteeEmail string) (bool, *shoreline.UserData) {
//already in the group?
invitedUsr := a.findExistingUser(inviteeEmail, a.sl.TokenProvide())

Expand All @@ -81,8 +79,6 @@ func (a *Api) checkAccountAlreadySharedWithUser(invitorID, inviteeEmail string,
log.Printf("error checking if user is in group [%v]", err)
} else if perms != nil {
log.Println(statusExistingMemberMessage)
statusErr := &status.StatusError{Status: status.NewStatus(http.StatusConflict, statusExistingMemberMessage)}
a.sendModelAsResWithStatus(res, statusErr, http.StatusConflict)
return true, invitedUsr
}
return false, invitedUsr
Expand Down Expand Up @@ -411,11 +407,17 @@ func (a *Api) SendInvite(res http.ResponseWriter, req *http.Request, vars map[st
return
}

if existingInvite := a.checkForDuplicateInvite(req.Context(), ib.Email, invitorID, res); existingInvite {
if a.checkForDuplicateInvite(req.Context(), ib.Email, invitorID) {
log.Printf("SendInvite: invited [%s] user already has or had an invite", ib.Email)
statusErr := &status.StatusError{
Status: status.NewStatus(http.StatusConflict, statusExistingInviteMessage),
}
a.sendModelAsResWithStatus(res, statusErr, http.StatusConflict)
return
} else if alreadyMember, invitedUsr := a.checkAccountAlreadySharedWithUser(invitorID, ib.Email, res); alreadyMember {
} else if alreadyMember, invitedUsr := a.checkAccountAlreadySharedWithUser(invitorID, ib.Email); alreadyMember {
a.logger.Infof("invited [%s] user is already a member of the care team of %v", ib.Email, invitorID)
statusErr := &status.StatusError{Status: status.NewStatus(http.StatusConflict, statusExistingMemberMessage)}
a.sendModelAsResWithStatus(res, statusErr, http.StatusConflict)
return
} else {
//None exist so lets create the invite
Expand Down