@@ -2,7 +2,6 @@ package handlers
22
33import (
44 "context"
5- "errors"
65 "strings"
76
87 "github.com/stripe/stripe-go/v84"
@@ -15,7 +14,7 @@ import (
1514 "github.com/theopenlane/core/internal/ent/generated/orgprice"
1615 "github.com/theopenlane/core/internal/ent/generated/orgproduct"
1716 "github.com/theopenlane/core/internal/ent/generated/privacy"
18- "github.com/theopenlane/core/internal/ent/hooks "
17+ "github.com/theopenlane/core/internal/ent/generated/trustcenter "
1918 "github.com/theopenlane/core/pkg/entitlements"
2019 "github.com/theopenlane/core/pkg/logx"
2120 "github.com/theopenlane/core/pkg/middleware/transaction"
@@ -155,10 +154,19 @@ func upsertOrgModule(ctx context.Context, orgSub *ent.OrgSubscription, price *en
155154
156155 newCtx = privacy .DecisionContext (newCtx , privacy .Allow )
157156
158- err := tx .TrustCenter .Create ().SetOwnerID (orgSub .OwnerID ).
159- Exec (newCtx )
157+ // check for trustcenter existence for this org user
158+ exists , err := tx .TrustCenter .Query ().Where (trustcenter .OwnerID (orgSub .OwnerID )).
159+ Exist (ctx )
160160 if err != nil {
161- if ! errors .Is (err , hooks .ErrNotSingularTrustCenter ) {
161+ logx .FromContext (ctx ).Error ().Err (err ).Msg ("could not query for trustcenter existence while syncing modules" )
162+ return nil , err
163+ }
164+
165+ // if for some reason they do not have the trustcenter, then create it
166+ if ! exists {
167+ err = tx .TrustCenter .Create ().SetOwnerID (orgSub .OwnerID ).
168+ Exec (newCtx )
169+ if err != nil {
162170 logx .FromContext (ctx ).Error ().Err (err ).Msg ("error creating trust center" )
163171 return nil , err
164172 }
0 commit comments