mirror of
https://github.com/hanzo-fi/payments.git
synced 2026-10-30 20:31:20 +00:00
54 lines
1.4 KiB
Go
54 lines
1.4 KiB
Go
package events
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/hanzo-fi/go-libs/v5/pkg/types/pointer"
|
|
"github.com/hanzo-fi/go-libs/v5/pkg/messaging/publish"
|
|
"github.com/hanzo-fi/payments/pkg/domain/models"
|
|
"github.com/hanzo-fi/payments/pkg/events"
|
|
)
|
|
|
|
type TaskMessagePayload struct {
|
|
ID string `json:"id"`
|
|
ConnectorID *string `json:"connectorID"`
|
|
Status string `json:"status"`
|
|
CreatedAt time.Time `json:"createdAt"`
|
|
UpdatedAt time.Time `json:"updatedAt"`
|
|
CreatedObjectID *string `json:"createdObjectID"`
|
|
Error *string `json:"error"`
|
|
}
|
|
|
|
func (e Events) NewEventUpdatedTask(task models.Task) publish.EventMessage {
|
|
payload := TaskMessagePayload{
|
|
ID: task.ID.String(),
|
|
ConnectorID: func() *string {
|
|
if task.ConnectorID == nil {
|
|
return nil
|
|
}
|
|
|
|
return pointer.For(task.ConnectorID.String())
|
|
}(),
|
|
Status: string(task.Status),
|
|
CreatedAt: task.CreatedAt,
|
|
UpdatedAt: task.UpdatedAt,
|
|
CreatedObjectID: task.CreatedObjectID,
|
|
Error: func() *string {
|
|
if task.Error == nil {
|
|
return nil
|
|
}
|
|
|
|
return pointer.For(task.Error.Error())
|
|
}(),
|
|
}
|
|
|
|
return publish.EventMessage{
|
|
IdempotencyKey: task.IdempotencyKey(),
|
|
Date: time.Now().UTC(),
|
|
App: events.EventApp,
|
|
Version: events.EventVersion,
|
|
Type: events.EventTypeUpdatedTask,
|
|
Payload: payload,
|
|
}
|
|
}
|