Skip to content

Commit 8c18297

Browse files
authored
fix: transaction handling (#3369)
1 parent 92f551c commit 8c18297

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

openmeter/app/stripe/adapter/customer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func (a *adapter) UpsertStripeCustomerData(ctx context.Context, input appstripee
112112
// Start transaction
113113
_, err = entutils.TransactingRepo(ctx, a, func(ctx context.Context, repo *adapter) (any, error) {
114114
// Make sure the customer has an app relationship
115-
err := a.appService.EnsureCustomer(ctx, app.EnsureCustomerInput{
115+
err := repo.appService.EnsureCustomer(ctx, app.EnsureCustomerInput{
116116
AppID: input.AppID,
117117
CustomerID: input.CustomerID,
118118
})
@@ -207,7 +207,7 @@ func (a *adapter) DeleteStripeCustomerData(ctx context.Context, input appstripee
207207
}
208208

209209
// Delete app customer relationship
210-
err = a.appService.DeleteCustomer(ctx, app.DeleteCustomerInput{
210+
err = repo.appService.DeleteCustomer(ctx, app.DeleteCustomerInput{
211211
AppID: input.AppID,
212212
CustomerID: input.CustomerID,
213213
})

openmeter/billing/adapter/customeroverride.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func (a *adapter) UpdateCustomerOverride(ctx context.Context, input billing.Upda
113113

114114
func (a *adapter) GetCustomerOverride(ctx context.Context, input billing.GetCustomerOverrideAdapterInput) (*billing.CustomerOverride, error) {
115115
return entutils.TransactingRepo(ctx, a, func(ctx context.Context, tx *adapter) (*billing.CustomerOverride, error) {
116-
query := a.db.BillingCustomerOverride.Query().
116+
query := tx.db.BillingCustomerOverride.Query().
117117
Where(billingcustomeroverride.Namespace(input.Customer.Namespace)).
118118
Where(billingcustomeroverride.CustomerID(input.Customer.ID)).
119119
WithBillingProfile(func(bpq *db.BillingProfileQuery) {
@@ -135,7 +135,7 @@ func (a *adapter) GetCustomerOverride(ctx context.Context, input billing.GetCust
135135

136136
if dbCustomerOverride.BillingProfileID == nil {
137137
// Let's fetch the default billing profile
138-
dbDefaultProfile, err := a.db.BillingProfile.Query().
138+
dbDefaultProfile, err := tx.db.BillingProfile.Query().
139139
Where(billingprofile.Namespace(input.Customer.Namespace)).
140140
Where(billingprofile.Default(true)).
141141
Where(billingprofile.DeletedAtIsNil()).
@@ -158,7 +158,7 @@ func (a *adapter) ListCustomerOverrides(ctx context.Context, input billing.ListC
158158
// Warning: We need to use the customer db parts as for the UI (and for a good API) we need to
159159
// be able to filter based on customer fields too.
160160
return entutils.TransactingRepo(ctx, a, func(ctx context.Context, tx *adapter) (billing.ListCustomerOverridesAdapterResult, error) {
161-
query := a.db.Customer.Query().
161+
query := tx.db.Customer.Query().
162162
Where(dbcustomer.NamespaceEQ(input.Namespace)).
163163
Where(dbcustomer.DeletedAtIsNil())
164164

openmeter/meter/adapter/manage.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func (a *Adapter) HasActiveFeatureForMeter(ctx context.Context, namespace, key s
124124
ctx,
125125
a,
126126
func(ctx context.Context, repo *Adapter) (bool, error) {
127-
exists, err := a.db.Feature.Query().
127+
exists, err := repo.db.Feature.Query().
128128
Where(featuredb.Namespace(namespace)).
129129
Where(featuredb.MeterSlug(key)).
130130
Where(featuredb.Or(featuredb.ArchivedAtIsNil(), featuredb.ArchivedAtGT(clock.Now()))).
@@ -166,7 +166,7 @@ func (a *Adapter) ListFeaturesForMeter(ctx context.Context, namespace, key strin
166166
ctx,
167167
a,
168168
func(ctx context.Context, repo *Adapter) ([]feature.Feature, error) {
169-
featureRows, err := a.db.Feature.Query().
169+
featureRows, err := repo.db.Feature.Query().
170170
Where(featuredb.Namespace(namespace)).
171171
Where(featuredb.MeterSlug(key)).
172172
Where(featuredb.And(

0 commit comments

Comments
 (0)