-
Notifications
You must be signed in to change notification settings - Fork 12
/
event_void_invoice.go
31 lines (25 loc) · 986 Bytes
/
event_void_invoice.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
package invoice
import (
"github.com/openline-ai/openline-customer-os/packages/server/customer-os-common-module/validator"
"github.com/openline-ai/openline-customer-os/packages/server/events-processing-platform/eventstore"
"github.com/pkg/errors"
"time"
)
type InvoiceVoidEvent struct {
Tenant string `json:"tenant" validate:"required"`
UpdatedAt time.Time `json:"updatedAt"`
}
func NewInvoiceVoidEvent(aggregate eventstore.Aggregate, updatedAt time.Time) (eventstore.Event, error) {
eventData := InvoiceVoidEvent{
Tenant: aggregate.GetTenant(),
UpdatedAt: updatedAt,
}
if err := validator.GetValidator().Struct(eventData); err != nil {
return eventstore.Event{}, errors.Wrap(err, "failed to validate InvoiceVoidEvent")
}
event := eventstore.NewBaseEvent(aggregate, InvoiceVoidV1)
if err := event.SetJsonData(&eventData); err != nil {
return eventstore.Event{}, errors.Wrap(err, "error setting json data for InvoiceVoidEvent")
}
return event, nil
}