2021-01-13 02:41:43 +00:00
|
|
|
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"
|
|
|
|
)
|
|
|
|
|
2021-01-13 05:09:16 +00:00
|
|
|
// NewDeveloperWrapper wraps a contact, account, payment method and a user identifier (app.User)
|
|
|
|
type NewDeveloperWrapper struct {
|
2021-01-14 06:36:35 +00:00
|
|
|
Contact crm_models.Contact
|
|
|
|
Account crm_models.Account
|
|
|
|
PaymentMethod ops_models.PaymentMethod
|
|
|
|
Principal app.User
|
|
|
|
SagaID string
|
|
|
|
SagaType string
|
2021-01-13 02:41:43 +00:00
|
|
|
}
|
|
|
|
|
2021-01-14 06:36:35 +00:00
|
|
|
// NewDeveloperWorkflow is a Temporal workflow
|
|
|
|
func NewDeveloperWorkflow(
|
|
|
|
ctx workflow.Context,
|
|
|
|
payload *NewDeveloperWrapper,
|
|
|
|
) error {
|
2021-01-13 02:41:43 +00:00
|
|
|
ctx = workflow.WithActivityOptions(ctx, workflow.ActivityOptions{
|
|
|
|
StartToCloseTimeout: time.Minute,
|
|
|
|
})
|
|
|
|
err := workflow.ExecuteActivity(ctx,
|
|
|
|
StoreContactActivity,
|
|
|
|
&app.ContactChannelWrapper{
|
2021-01-19 01:50:45 +00:00
|
|
|
Obj: payload.Contact,
|
|
|
|
APIKey: payload.Principal.APIKey,
|
|
|
|
SagaID: payload.SagaID,
|
|
|
|
SagaType: payload.SagaType,
|
2021-01-13 02:41:43 +00:00
|
|
|
}).Get(ctx, nil)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = workflow.ExecuteActivity(ctx,
|
|
|
|
StoreAccountActivity,
|
|
|
|
&app.AccountChannelWrapper{
|
2021-01-19 01:50:45 +00:00
|
|
|
Obj: payload.Account,
|
|
|
|
APIKey: payload.Principal.APIKey,
|
|
|
|
SagaID: payload.SagaID,
|
|
|
|
SagaType: payload.SagaType,
|
2021-01-13 02:41:43 +00:00
|
|
|
}).Get(ctx, nil)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = workflow.ExecuteActivity(ctx,
|
|
|
|
StorePaymentMethodActivity,
|
|
|
|
&app.PaymentMethodChannelWrapper{
|
2021-01-19 01:50:45 +00:00
|
|
|
Obj: payload.PaymentMethod,
|
|
|
|
APIKey: payload.Principal.APIKey,
|
|
|
|
SagaID: payload.SagaID,
|
|
|
|
SagaType: payload.SagaType,
|
2021-01-13 02:41:43 +00:00
|
|
|
}).Get(ctx, nil)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = workflow.ExecuteActivity(ctx,
|
|
|
|
NotifyContactActivity,
|
|
|
|
&app.ContactChannelWrapper{
|
2021-01-19 01:50:45 +00:00
|
|
|
Obj: payload.Contact,
|
|
|
|
APIKey: payload.Principal.APIKey,
|
|
|
|
SagaID: payload.SagaID,
|
|
|
|
SagaType: payload.SagaType,
|
2021-01-13 02:41:43 +00:00
|
|
|
}).Get(ctx, nil)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = workflow.ExecuteActivity(ctx, NotifyLeadActivity, payload).Get(ctx, nil)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|