-
Notifications
You must be signed in to change notification settings - Fork 0
/
invitation.go
63 lines (46 loc) · 1.04 KB
/
invitation.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package domain
import (
"github.com/haleyrc/pkg/time"
"github.com/haleyrc/cheevos/internal/lib/stringutil"
)
type Invitation struct {
ID string
Email string
OrganizationID string
Expires time.Time
}
func (i *Invitation) Expired() bool {
return i.Expires.Before(time.Now())
}
func (i *Invitation) Model() string { return "Invitation" }
func (i *Invitation) Normalize() {
i.Email = stringutil.MakeSafe(i.Email)
}
func (i *Invitation) Validate() error {
i.Normalize()
var fes []FieldError
if i.ID == "" {
fes = append(fes, FieldError{
Field: "ID", Msg: "ID can't be blank.",
})
}
if i.Email == "" {
fes = append(fes, FieldError{
Field: "Email", Msg: "Email can't be blank.",
})
}
if i.OrganizationID == "" {
fes = append(fes, FieldError{
Field: "OrganizationID", Msg: "Organization ID can't be blank.",
})
}
if i.Expires.IsZero() {
fes = append(fes, FieldError{
Field: "Expires", Msg: "Expiration time can't be blank.",
})
}
if len(fes) > 0 {
return NewValidationError("Invitation", fes)
}
return nil
}