refac: removed ugly multi-line method chaining
This commit is contained in:
1 parent
e8dff6bb5f
commit
ce9c876db6
6 files changed
+72
-67
No files matched your search
@@ -46,13 +46,13 @@ func (i *InviteRepository) Delete(id uint32) error {
|
||||
}
|
||||
|
||||
func (i *InviteRepository) Renew(id uint32, hashedCode string, expiresAt time.Time, createdAt time.Time) (domainInvite.Invite, error) {
|
||||
result := i.db.Model(&entity.Invite{}).
|
||||
Where("id = ? AND accepted_at IS NULL", id).
|
||||
Updates(map[string]any{
|
||||
"hashed_code": hashedCode,
|
||||
"expires_at": expiresAt,
|
||||
"created_at": createdAt,
|
||||
})
|
||||
query := i.db.Model(&entity.Invite{})
|
||||
query = query.Where("id = ? AND accepted_at IS NULL", id)
|
||||
result := query.Updates(map[string]any{
|
||||
"hashed_code": hashedCode,
|
||||
"expires_at": expiresAt,
|
||||
"created_at": createdAt,
|
||||
})
|
||||
if err := deleteOrNotFound(result, domainInvite.ErrInviteNotFound); err != nil {
|
||||
return domainInvite.Invite{}, err
|
||||
}
|
||||
@@ -67,9 +67,9 @@ func (i *InviteRepository) Renew(id uint32, hashedCode string, expiresAt time.Ti
|
||||
func (i *InviteRepository) AcceptWithUser(inviteID uint32, acceptedAt time.Time, newUser domainUser.User) (domainUser.User, error) {
|
||||
createdModel := mappers.UserToModel(newUser)
|
||||
err := i.db.Transaction(func(tx *gorm.DB) error {
|
||||
marked := tx.Model(&entity.Invite{}).
|
||||
Where("id = ? AND accepted_at IS NULL", inviteID).
|
||||
Update("accepted_at", acceptedAt)
|
||||
query := tx.Model(&entity.Invite{})
|
||||
query = query.Where("id = ? AND accepted_at IS NULL", inviteID)
|
||||
marked := query.Update("accepted_at", acceptedAt)
|
||||
if err := deleteOrNotFound(marked, domainInvite.ErrInviteNotFound); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user