From e4c6f13fffc819df978014389201b1c9acaadc17 Mon Sep 17 00:00:00 2001 From: elliot14A Date: Thu, 1 Jun 2023 16:52:33 +0530 Subject: [PATCH] fix: resending invitation upon exipiration is working now --- server/action/organisation/user/create.go | 25 ++++++++--------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/server/action/organisation/user/create.go b/server/action/organisation/user/create.go index 4897775a..06dec89e 100644 --- a/server/action/organisation/user/create.go +++ b/server/action/organisation/user/create.go @@ -20,6 +20,7 @@ import ( "github.com/factly/x/validationx" "github.com/go-chi/chi" "github.com/spf13/viper" + "gorm.io/gorm" ) type invites struct { @@ -109,7 +110,13 @@ func create(w http.ResponseWriter, r *http.Request) { }).First(&invitee).Error if err != nil { - tx.Create(&invitee) + if err == gorm.ErrRecordNotFound { + tx.Create(&invitee) + } else { + loggerx.Error(errors.New("error creating invitee")) + errorx.Render(w, errorx.Parser(errorx.InternalServerError())) + return + } } invitation := &model.Invitation{ @@ -123,22 +130,8 @@ func create(w http.ResponseWriter, r *http.Request) { ExpiredAt: time.Now().AddDate(0, 0, 7), } - var invitationCount int64 - err = tx.Model(&model.Invitation{}). - Where("invitee_id=? AND organisation_id=? AND status=? AND role=? AND expired_at 0 { - loggerx.Error(err) - continue - } - err := tx.Model(&model.Invitation{}).Create(&invitation).Error if err != nil { tx.Rollback() loggerx.Error(err)