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