35 lines
1.1 KiB
Go
35 lines
1.1 KiB
Go
package entities
|
|||
|
|
|
||
|
|
import (
|
||
|
|
"time"
|
||
|
|
|
||
|
|
"github.com/google/uuid"
|
||
|
|
"gorm.io/gorm"
|
||
|
|
)
|
||
|
|
|
||
|
|
// LoyaltySettingChange records one change to a loyalty setting: which key, from what,
|
||
|
|
// to what, by whom (docs/prd-point-coin.md F2). Append-only.
|
||
|
|
type LoyaltySettingChange struct {
|
||
|
|
ID uuid.UUID `gorm:"type:uuid;primary_key;default:gen_random_uuid()" json:"id"`
|
||
|
|
OrganizationID uuid.UUID `gorm:"type:uuid;not null" json:"organization_id"`
|
||
|
|
// Nil for an organization setting.
|
||
|
|
OutletID *uuid.UUID `gorm:"type:uuid" json:"outlet_id"`
|
||
|
|
Key string `gorm:"not null;size:100" json:"key"`
|
||
|
|
// Nil when the key had no stored value, or has none any more.
|
||
|
|
OldValue *string `gorm:"type:text" json:"old_value"`
|
||
|
|
NewValue *string `gorm:"type:text" json:"new_value"`
|
||
|
|
ChangedBy uuid.UUID `gorm:"type:uuid;not null" json:"changed_by"`
|
||
|
|
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
|
||
|
|
}
|
||
|
|
|
||
|
|
func (c *LoyaltySettingChange) BeforeCreate(tx *gorm.DB) error {
|
||
|
|
if c.ID == uuid.Nil {
|
||
|
|
c.ID = uuid.New()
|
||
|
|
}
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func (LoyaltySettingChange) TableName() string {
|
||
|
|
return "loyalty_setting_changes"
|
||
|
|
}
|