🐛 Fix relationships
This commit is contained in:
parent
497c0692ca
commit
64fd2f3cd9
@ -1,8 +1,8 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"git.solsynth.dev/hypernet/passport/pkg/authkit/models"
|
||||
|
||||
"git.solsynth.dev/hypernet/passport/pkg/internal/database"
|
||||
@ -112,6 +112,10 @@ func NewFriend(userA models.Account, userB models.Account, skipPending ...bool)
|
||||
Status: models.RelationshipPending,
|
||||
}
|
||||
|
||||
if userA.ID == userB.ID {
|
||||
return relA, fmt.Errorf("unable to make relationship with yourself")
|
||||
}
|
||||
|
||||
var dupeCount int
|
||||
if rel, err := GetRelationWithTwoNode(userA.ID, userB.ID, true); err == nil {
|
||||
relA = rel
|
||||
@ -131,12 +135,6 @@ func NewFriend(userA models.Account, userB models.Account, skipPending ...bool)
|
||||
relB.Status = models.RelationshipFriend
|
||||
}
|
||||
|
||||
if userA.ID == userB.ID {
|
||||
return relA, fmt.Errorf("unable to make relationship with yourself")
|
||||
} else if _, err := GetRelationWithTwoNode(userA.ID, userB.ID, true); err == nil || !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return relA, fmt.Errorf("unable to recreate a relationship with that user")
|
||||
}
|
||||
|
||||
if err := database.C.Save(&relA).Error; err != nil {
|
||||
return relA, err
|
||||
} else if err = database.C.Save(&relB).Error; err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user