You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

68 lines
1.4 KiB

package customer
import (
"strconv"
"time"
)
// Покупатель
type Customer struct {
SimpleRow
Code string `json:"code"`
Email string `json:"email"`
Login string `json:"login"`
Password string `json:"password"`
Confirmed bool `json:"confirmed"`
TimeReregistration time.Time `json:"reregistration_at"` // Время начиная с которого допустима повторная регистрация
}
func (c *Customer) refreshCode(minutes int) string {
return strconv.Itoa(time.Now().Nanosecond())
}
func (c *Customer) refreshTime(minutes int) time.Time {
return time.Now().Add(time.Minute * time.Duration(minutes))
}
func (c *Customer) Add(minutes int) error {
c.Code = c.refreshCode(minutes)
c.TimeReregistration = c.refreshTime(minutes)
//
meta, err := c.collection.CreateDocument(c.ctx, c)
if err != nil {
return err
} else {
c.key = meta.Key
}
return nil
}
func (c *Customer) Update() error {
c.UpdatedAt = time.Now()
//
_, err := c.collection.UpdateDocument(c.ctx, c.key, c)
return err
}
func (c *Customer) Delete() error {
return c.SimpleRow.Delete()
}
func (c *Customer) Refresh(minutes int) error {
c.Code = c.refreshCode(minutes)
c.TimeReregistration = c.refreshTime(minutes)
return c.Update()
}
func (c *Customer) Confirm() error {
c.Confirmed = true
return c.Update()
}