lib/rules/account.go

75 lines
2.7 KiB
Go
Raw Permalink Normal View History

2021-01-13 02:41:43 +00:00
package rules
import (
"code.tnxs.net/taxnexus/lib/api/crm/crm_client/accounts"
"code.tnxs.net/taxnexus/lib/api/crm/crm_models"
"code.tnxs.net/taxnexus/lib/app"
2021-01-19 01:50:45 +00:00
httptransport "github.com/go-openapi/runtime/client"
2021-01-13 02:41:43 +00:00
"go.temporal.io/sdk/workflow"
)
2021-01-18 03:13:54 +00:00
// StoreAccountActivityID is an activity identifier
const StoreAccountActivityID = "STORE_ACCOUNT_ACTIVITY"
// StoreAccountActivity posts a new account object to datastore
2021-01-19 20:23:02 +00:00
func StoreAccountActivity(ctx workflow.Context, w app.AccountActivityWrapper) error { //nolint:gocritic // what we want
2021-01-19 21:18:59 +00:00
obj := &crm_models.Account{
AccountSource: w.AccountSource,
AdministrativeLevel: w.AdministrativeLevel,
BillingAddress: w.BillingAddress.MarshalToCrm(),
BillingContactID: w.BillingContactID,
BillingPreference: w.BillingPreference,
BusinessAddress: w.BusinessAddress.MarshalToCrm(),
CannabisCustomer: w.CannabisCustomer,
CompanyID: w.CompanyID,
CoordinateID: w.CoordinateID,
CustomerID: w.CustomerID,
CustomerPriority: w.CustomerPriority,
DBA: w.DBA,
DefaultAddress: w.DefaultAddress.MarshalToCrm(),
DefaultBackendID: w.DefaultBackendID,
DefaultDeliveryContactID: w.DefaultDeliveryContactID,
DefaultEndUserID: w.DefaultEndUserID,
Description: w.Description,
EIN: w.EIN,
Email: w.Email,
EnrollmentStatus: w.EnrollmentStatus,
Fax: w.Fax,
ISPCustomer: w.ISPCustomer,
MSPCustomer: w.MSPCustomer,
Name: w.Name,
OrderContactID: w.OrderContactID,
OrderEmail: w.OrderEmail,
OwnerID: w.OwnerID,
ParentID: w.ParentID,
Phone: w.Phone,
PlaceID: w.PlaceID,
PreparerID: w.PreparerID,
RatingEngineID: w.RatingEngineID,
Ref: w.Ref,
ShippingAddress: w.ShippingAddress.MarshalToCrm(),
Site: w.Site,
TelecomCustomer: w.TelecomCustomer,
TenantID: w.TenantID,
Type: w.Type,
Website: w.Website,
}
2021-01-13 02:41:43 +00:00
postAccountParams := accounts.NewPostAccountsParamsWithTimeout(postTimeout)
postAccountParams.AccountRequest = &crm_models.AccountRequest{
2021-01-19 21:18:59 +00:00
Data: []*crm_models.Account{obj},
2021-01-13 02:41:43 +00:00
}
2021-01-19 01:50:45 +00:00
_, err := crmClient.Accounts.PostAccounts(
postAccountParams,
httptransport.APIKeyAuth(
"X-API-Key",
"header",
w.APIKey,
))
2021-01-13 02:41:43 +00:00
if err != nil {
return err
}
2021-01-18 03:13:54 +00:00
sugar.Info("rules.StoreAccountActivity: 👍 📤")
2021-01-13 02:41:43 +00:00
return nil
}