35 lines
1.0 KiB
Go
35 lines
1.0 KiB
Go
|
|
package entities
|
||
|
|
|
||
|
|
import (
|
||
|
|
"time"
|
||
|
|
|
||
|
|
"github.com/google/uuid"
|
||
|
|
|
||
|
|
"gorm.io/gorm"
|
||
|
|
)
|
||
|
|
|
||
|
|
type Organization struct {
|
||
|
|
ID uuid.UUID `gorm:"type:uuid;primary_key;default:gen_random_uuid()" json:"id"`
|
||
|
|
Name string `gorm:"not null;size:255" json:"name" validate:"required,min=1,max=255"`
|
||
|
|
Email *string `gorm:"size:255" json:"email" validate:"omitempty,email"`
|
||
|
|
PhoneNumber *string `gorm:"size:20" json:"phone_number" validate:"omitempty"`
|
||
|
|
PlanType string `gorm:"not null;size:50" json:"plan_type" validate:"required,oneof=basic premium enterprise"`
|
||
|
|
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
|
||
|
|
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
|
||
|
|
|
||
|
|
Outlets []Outlet `gorm:"foreignKey:OrganizationID" json:"outlets,omitempty"`
|
||
|
|
Users []User `gorm:"foreignKey:OrganizationID" json:"users,omitempty"`
|
||
|
|
}
|
||
|
|
|
||
|
|
func (o *Organization) BeforeCreate(tx *gorm.DB) error {
|
||
|
|
if o.ID == uuid.Nil {
|
||
|
|
id := uuid.New()
|
||
|
|
o.ID = id
|
||
|
|
}
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func (Organization) TableName() string {
|
||
|
|
return "organizations"
|
||
|
|
}
|