lib/rules/new-developer.go

67 lines
1.6 KiB
Go
Raw Normal View History

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"
)
// newDeveloperWrapper wraps a Lead and a user identifier (app.User)
type newDeveloperWrapper struct {
contact crm_models.Contact
account crm_models.Account
paymentMethod ops_models.PaymentMethod
principal app.User
}
// NewDeveloperWorkflow is a 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,
}).Get(ctx, nil)
if err != nil {
return err
}
err = workflow.ExecuteActivity(ctx,
StoreAccountActivity,
&app.AccountChannelWrapper{
Obj: payload.account,
Principal: payload.principal,
}).Get(ctx, nil)
if err != nil {
return err
}
err = workflow.ExecuteActivity(ctx,
StorePaymentMethodActivity,
&app.PaymentMethodChannelWrapper{
Obj: payload.paymentMethod,
Principal: payload.principal,
}).Get(ctx, nil)
if err != nil {
return err
}
err = workflow.ExecuteActivity(ctx,
NotifyContactActivity,
&app.ContactChannelWrapper{
Obj: payload.contact,
Principal: payload.principal,
}).Get(ctx, nil)
if err != nil {
return err
}
err = workflow.ExecuteActivity(ctx, NotifyLeadActivity, payload).Get(ctx, nil)
if err != nil {
return err
}
return nil
}