model

package
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 3, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package model is responsible for the models

Index

Constants

View Source
const ClientBillingAddressType = "client_billing"
View Source
const ClientShippingAddressType = "client_shipping"
View Source
const CompanyBillingAddressType = "company_billing"
View Source
const CompanyShippingAddressType = "company_shipping"

Variables

Functions

func MarshalID

func MarshalID(id hide.ID) graphql.Marshaler

MarshalID implements marshalling for IDs

func UnmarshalID

func UnmarshalID(v interface{}) (hide.ID, error)

UnmarshalID implements reverse marshalling for IDs from strings

Types

type Address

type Address struct {
	SoftDelete
	Name       string
	Street1    string
	Street2    *string
	City       string
	State      *string
	PostalCode int
	Country    string

	AddresseeID   hide.ID
	AddresseeType string
}

func MapInputToAddress added in v0.0.3

func MapInputToAddress(in modelgen.CreateAddressInput) Address

type AuthData

type AuthData struct {
	User             *User   `json:"user"`
	Token            *string `json:"token"`
	TwoFactorEnabled bool    `json:"twoFactorEnabled"`
}

type Client

type Client struct {
	SoftDelete
	Name string

	Website        *string
	VatNumber      *string
	BusinessNumber *string
	Phone          *string

	BillingAddress  Address `gorm:"polymorphic:Addressee;polymorphicValue:client_billing"`
	ShippingAddress Address `gorm:"polymorphic:Addressee;polymorphicValue:client_shipping"`

	Contacts  []Contact
	CompanyID hide.ID `json:"company"`
	Company   Company `json:"-"`
}

func (Client) IsEntity

func (Client) IsEntity()

type Company

type Company struct {
	SoftDelete
	Code    string `gorm:"unique_index:idx_code"`
	Name    string
	Users   []User
	Domains []Domain
	Website string
	Clients []Client

	BillingAddress  Address `gorm:"polymorphic:Addressee;polymorphicValue:company_billing"`
	ShippingAddress Address `gorm:"polymorphic:Addressee;polymorphicValue:company_shipping"`
}

Company model

func (Company) IsEntity added in v0.0.5

func (Company) IsEntity()

type Contact

type Contact struct {
	SoftDelete
	ClientID         hide.ID
	Email            *string
	Phone            *string
	Mobile           *string
	PreferredContact *PreferredContact
	Firstname        string
	Lastname         string
}

type Domain

type Domain struct {
	Model
	Domain    string
	CompanyID hide.ID
	Company   Company
}

Domain model

type Model

type Model struct {
	ID        hide.ID `gorm:"type: bigserial;primary_key" json:"id"` // int64
	CreatedAt time.Time
	UpdatedAt time.Time
}

Model Default model structure with hard deleting

func (Model) IDint

func (m Model) IDint() int64

IDint returns the ID as an int64

func (Model) IDstring

func (m Model) IDstring() string

IDstring returns the ID as a hash string

type PreferredContact

type PreferredContact string
const (
	PreferredContactPhone  PreferredContact = "PHONE"
	PreferredContactMobile PreferredContact = "MOBILE"
	PreferredContactEmail  PreferredContact = "EMAIL"
)

func (PreferredContact) IsValid

func (e PreferredContact) IsValid() bool

func (PreferredContact) MarshalGQL

func (e PreferredContact) MarshalGQL(w io.Writer)

func (PreferredContact) String

func (e PreferredContact) String() string

func (*PreferredContact) UnmarshalGQL

func (e *PreferredContact) UnmarshalGQL(v interface{}) error

type SoftDelete

type SoftDelete struct {
	ID        hide.ID `gorm:"type: bigserial;primary_key" json:"id"` // int64
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt *time.Time
}

SoftDelete Default model structure with soft deleting

func (SoftDelete) IDint

func (m SoftDelete) IDint() int64

IDint returns the ID as an int64

func (SoftDelete) IDstring

func (m SoftDelete) IDstring() string

IDstring returns the ID as a hash string

type TwoFactor

type TwoFactor struct {
	Model
	UserID     hide.ID
	Secret     string
	BackupKeys pq.StringArray `gorm:"type:varchar(10)[]"`
}

TwoFactor model contains the 2FA data for a user

type User

type User struct {
	SoftDelete
	Email            string `gorm:"UNIQUE_INDEX:idx_email"`
	Phone            *string
	Mobile           *string
	PreferredContact *PreferredContact
	Password         string
	Firstname        string
	Lastname         string
	CompanyID        hide.ID                  `json:"company"`
	Company          Company                  `json:"-"`
	BuiltinRoles     []permission.BuiltinRole `gorm:"many2many:user_builtinroles" json:"-"`
	CustomRoles      []permission.CustomRole  `gorm:"many2many:user_customroles" json:"-"`
	TwoFactor        TwoFactor
}

User model

func (User) IsEntity

func (User) IsEntity()

func (User) Roles

func (u User) Roles() []permission.Role

Roles returns all roles a user has as the Role interface

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL