Skip to content
Open
Show file tree
Hide file tree
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
34 changes: 34 additions & 0 deletions db/bounty_ownership.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package db

import (
"errors"
"time"
)

func (db database) TransferWorkspaceBountyOwnership(workspaceUUID string, fromOwnerID string, toOwnerID string) (int64, error) {
if workspaceUUID == "" {
return 0, errors.New("workspace_uuid is required")
}
if fromOwnerID == "" {
return 0, errors.New("from_owner_id is required")
}
if toOwnerID == "" {
return 0, errors.New("to_owner_id is required")
}
if fromOwnerID == toOwnerID {
return 0, errors.New("from_owner_id and to_owner_id must be different")
}

now := time.Now()
result := db.db.Model(&NewBounty{}).
Where("workspace_uuid = ? AND owner_id = ? AND paid = ?", workspaceUUID, fromOwnerID, false).
Updates(map[string]interface{}{
"owner_id": toOwnerID,
"updated": &now,
})
if result.Error != nil {
return 0, result.Error
}

return result.RowsAffected, nil
}
1 change: 1 addition & 0 deletions db/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type Database interface {
UpdateBounty(b NewBounty) (NewBounty, error)
UpdateBountyPaymentStatuses(bounty NewBounty) (NewBounty, error)
UpdateBountyPayment(b NewBounty) (NewBounty, error)
TransferWorkspaceBountyOwnership(workspaceUUID string, fromOwnerID string, toOwnerID string) (int64, error)
GetListedOffers(r *http.Request) ([]PeopleExtra, error)
UpdateBot(uuid string, u map[string]interface{}) bool
GetAllTribes() []Tribe
Expand Down
Loading