80 lines
1.9 KiB
Go
80 lines
1.9 KiB
Go
package rules
|
|
|
|
import (
|
|
"time"
|
|
|
|
"code.tnxs.net/taxnexus/lib/api/crm/crm_models"
|
|
"code.tnxs.net/taxnexus/lib/api/ops/ops_models"
|
|
"code.tnxs.net/taxnexus/lib/app"
|
|
"go.temporal.io/sdk/workflow"
|
|
)
|
|
|
|
// NewDeveloperWrapper wraps a contact, account, payment method and a user identifier (app.User)
|
|
type NewDeveloperWrapper struct {
|
|
Contact crm_models.Contact
|
|
Account crm_models.Account
|
|
PaymentMethod ops_models.PaymentMethod
|
|
Principal app.User
|
|
SagaID string
|
|
SagaType string
|
|
}
|
|
|
|
// NewDeveloperWorkflow is a Temporal workflow
|
|
func NewDeveloperWorkflow(
|
|
ctx workflow.Context,
|
|
payload *NewDeveloperWrapper,
|
|
) error {
|
|
ctx = workflow.WithActivityOptions(ctx, workflow.ActivityOptions{
|
|
StartToCloseTimeout: time.Minute,
|
|
})
|
|
err := workflow.ExecuteActivity(ctx,
|
|
StoreContactActivity,
|
|
&app.ContactChannelWrapper{
|
|
Obj: payload.Contact,
|
|
Principal: payload.Principal,
|
|
SagaID: payload.SagaID,
|
|
SagaType: payload.SagaType,
|
|
}).Get(ctx, nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err = workflow.ExecuteActivity(ctx,
|
|
StoreAccountActivity,
|
|
&app.AccountChannelWrapper{
|
|
Obj: payload.Account,
|
|
Principal: payload.Principal,
|
|
SagaID: payload.SagaID,
|
|
SagaType: payload.SagaType,
|
|
}).Get(ctx, nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err = workflow.ExecuteActivity(ctx,
|
|
StorePaymentMethodActivity,
|
|
&app.PaymentMethodChannelWrapper{
|
|
Obj: payload.PaymentMethod,
|
|
Principal: payload.Principal,
|
|
SagaID: payload.SagaID,
|
|
SagaType: payload.SagaType,
|
|
}).Get(ctx, nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err = workflow.ExecuteActivity(ctx,
|
|
NotifyContactActivity,
|
|
&app.ContactChannelWrapper{
|
|
Obj: payload.Contact,
|
|
Principal: payload.Principal,
|
|
SagaID: payload.SagaID,
|
|
SagaType: payload.SagaType,
|
|
}).Get(ctx, nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err = workflow.ExecuteActivity(ctx, NotifyLeadActivity, payload).Get(ctx, nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|