-
Notifications
You must be signed in to change notification settings - Fork 0
/
order.go
99 lines (94 loc) · 1.93 KB
/
order.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package schema
import (
"entgo.io/ent"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"github.com/google/uuid"
)
// Order holds the schema definition for the Order entity.
type Order struct {
ent.Schema
}
// Fields of the Order.
func (Order) Fields() []ent.Field {
return []ent.Field{
field.UUID("id", uuid.UUID{}).
Default(uuid.New).
Immutable(),
field.UUID("customer_id", uuid.UUID{}).
Immutable(),
field.String("note").
Optional().
Nillable(),
field.UUID("created_by", uuid.UUID{}).
Immutable(),
field.UUID("parent_order_id", uuid.UUID{}).
Optional().
Nillable().
Immutable(),
field.Int("priority").
Nillable().
Default(0).
Range(0, 100),
field.Enum("type").
NamedValues(
"Sale", "SALE",
"Return", "RETURN",
"Exchange", "EXCHANGE",
"Transfer", "TRANSFER",
"Other", "OTHER",
).
Nillable().
Default("SALE").
Immutable(),
field.Int("status_code").
Default(1),
field.UUID("staff_id", uuid.UUID{}).
Optional().
Nillable(),
field.String("internal_note").
Optional().
Nillable(),
field.Bool("is_internal").
Nillable().
Default(false).
Immutable(),
field.UUID("address_id", uuid.UUID{}),
}
}
// Edges of the Order.
func (Order) Edges() []ent.Edge {
return []ent.Edge{
edge.To("customer", Person.Type).
Field("customer_id").
Unique().
Required().
Immutable(),
edge.To("creator", Person.Type).
Field("created_by").
Unique().
Required().
Immutable(),
edge.To("parent_order", Order.Type).
Field("parent_order_id").
Unique().
Immutable(),
edge.To("order_status", OrderStatusCode.Type).
Field("status_code").
Unique().
Required(),
edge.To("staff", Person.Type).
Field("staff_id").
Unique(),
edge.To("order_address", Address.Type).
Field("address_id").
Unique().
Required(),
}
}
// Mixin of the Order.
func (Order) Mixin() []ent.Mixin {
return []ent.Mixin{
TimeMixin{},
}
}