referral.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package models
  2. import (
  3. "github.com/lithammer/shortuuid/v4"
  4. "github.com/porter-dev/porter/api/types"
  5. "gorm.io/gorm"
  6. )
  7. const (
  8. // ReferralStatusSignedUp is the status of a referral where the referred user has signed up
  9. ReferralStatusSignedUp = "signed_up"
  10. // ReferralStatusCompleted is the status of a referral where the referred user has linked a credit card
  11. ReferralStatusCompleted = "completed"
  12. )
  13. // Referral type that extends gorm.Model
  14. type Referral struct {
  15. gorm.Model
  16. // Code is the referral code that is shared with the referred user
  17. Code string
  18. // ProjectID is the ID of the project that was used to refer a new user
  19. ProjectID uint
  20. // ReferredUserID is the ID of the user who was referred
  21. ReferredUserID uint
  22. // Status is the status of the referral (pending, signed_up, etc.)
  23. Status string
  24. }
  25. // NewReferralCode generates a new referral code
  26. func NewReferralCode() string {
  27. return shortuuid.New()
  28. }
  29. // ToReferralType generates an external types.Referral to be shared over REST
  30. func (r *Referral) ToReferralType() *types.Referral {
  31. return &types.Referral{
  32. ID: r.ID,
  33. ReferredUserID: r.ReferredUserID,
  34. Status: r.Status,
  35. }
  36. }