2019-07-06 18:53:20 +03:00
|
|
|
package models
|
|
|
|
|
|
|
|
type Alias struct {
|
|
|
|
ID uint `gorm:"primary_key"`
|
2020-11-06 19:09:41 +03:00
|
|
|
Type uint8 `gorm:"not null; index:idx_alias_type_key; constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
|
2020-11-03 12:02:39 +03:00
|
|
|
User *User `json:"-" gorm:"not null"`
|
2019-07-06 18:53:20 +03:00
|
|
|
UserID string `gorm:"not null; index:idx_alias_user"`
|
|
|
|
Key string `gorm:"not null; index:idx_alias_type_key"`
|
|
|
|
Value string `gorm:"not null"`
|
|
|
|
}
|
2021-01-21 02:26:52 +03:00
|
|
|
|
|
|
|
func (a *Alias) IsValid() bool {
|
|
|
|
return a.Key != "" && a.Value != "" && a.validateType()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *Alias) validateType() bool {
|
|
|
|
for _, t := range SummaryTypes() {
|
|
|
|
if a.Type == t {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|