/
events.go
53 lines (45 loc) · 1.83 KB
/
events.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
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"
)
const (
InvoiceCreateForContractV1 = "V1_INVOICE_CREATE_FOR_CONTRACT"
InvoiceFillRequestedV1 = "V1_INVOICE_FILL_REQUESTED"
InvoiceFillV1 = "V1_INVOICE_FILL"
InvoicePdfRequestedV1 = "V1_INVOICE_PDF_REQUESTED"
InvoicePdfGeneratedV1 = "V1_INVOICE_PDF_GENERATED"
InvoiceUpdateV1 = "V1_INVOICE_UPDATE"
InvoicePaidV1 = "V1_INVOICE_PAID"
InvoicePayNotificationV1 = "V1_INVOICE_PAY_NOTIFICATION"
InvoiceDeleteV1 = "V1_INVOICE_DELETE"
InvoiceVoidV1 = "V1_INVOICE_VOID"
// Deprecated
InvoicePayV1 = "V1_INVOICE_PAY"
)
const (
FieldMaskStatus = "status"
FieldMaskPaymentLink = "paymentLink"
)
type InvoicePdfGeneratedEvent struct {
Tenant string `json:"tenant" validate:"required"`
UpdatedAt time.Time `json:"updatedAt"`
RepositoryFileId string `json:"repositoryFileId" validate:"required"`
}
func NewInvoicePdfGeneratedEvent(aggregate eventstore.Aggregate, updatedAt time.Time, repositoryFileId string) (eventstore.Event, error) {
eventData := InvoicePdfGeneratedEvent{
Tenant: aggregate.GetTenant(),
UpdatedAt: updatedAt,
RepositoryFileId: repositoryFileId,
}
if err := validator.GetValidator().Struct(eventData); err != nil {
return eventstore.Event{}, errors.Wrap(err, "failed to validate InvoicePdfGeneratedEvent")
}
event := eventstore.NewBaseEvent(aggregate, InvoicePdfGeneratedV1)
if err := event.SetJsonData(&eventData); err != nil {
return eventstore.Event{}, errors.Wrap(err, "error setting json data for InvoicePdfGeneratedEvent")
}
return event, nil
}