@@ -124,7 +124,10 @@ func (s *Store) GetPlanBySlug(ctx context.Context, slug, appID string) (*plan.Pl
124124func (s * Store ) ListPlans (ctx context.Context , appID string , opts plan.ListOpts ) ([]* plan.Plan , error ) {
125125 var models []planModel
126126
127- filter := bson.M {"app_id" : appID }
127+ filter := bson.M {}
128+ if appID != "" {
129+ filter ["app_id" ] = appID
130+ }
128131 if opts .Status != "" {
129132 filter ["status" ] = string (opts .Status )
130133 }
@@ -248,7 +251,13 @@ func (s *Store) GetActiveSubscription(ctx context.Context, tenantID, appID strin
248251func (s * Store ) ListSubscriptions (ctx context.Context , tenantID , appID string , opts subscription.ListOpts ) ([]* subscription.Subscription , error ) {
249252 var models []subscriptionModel
250253
251- filter := bson.M {"tenant_id" : tenantID , "app_id" : appID }
254+ filter := bson.M {}
255+ if tenantID != "" {
256+ filter ["tenant_id" ] = tenantID
257+ }
258+ if appID != "" {
259+ filter ["app_id" ] = appID
260+ }
252261 if opts .Status != "" {
253262 filter ["status" ] = string (opts .Status )
254263 }
@@ -389,7 +398,13 @@ func (s *Store) AggregateMulti(ctx context.Context, tenantID, appID string, feat
389398func (s * Store ) QueryUsage (ctx context.Context , tenantID , appID string , opts meter.QueryOpts ) ([]* meter.UsageEvent , error ) {
390399 var models []usageEventModel
391400
392- filter := bson.M {"tenant_id" : tenantID , "app_id" : appID }
401+ filter := bson.M {}
402+ if tenantID != "" {
403+ filter ["tenant_id" ] = tenantID
404+ }
405+ if appID != "" {
406+ filter ["app_id" ] = appID
407+ }
393408 if opts .FeatureKey != "" {
394409 filter ["feature_key" ] = opts .FeatureKey
395410 }
@@ -544,7 +559,13 @@ func (s *Store) GetInvoice(ctx context.Context, invID id.InvoiceID) (*invoice.In
544559func (s * Store ) ListInvoices (ctx context.Context , tenantID , appID string , opts invoice.ListOpts ) ([]* invoice.Invoice , error ) {
545560 var models []invoiceModel
546561
547- filter := bson.M {"tenant_id" : tenantID , "app_id" : appID }
562+ filter := bson.M {}
563+ if tenantID != "" {
564+ filter ["tenant_id" ] = tenantID
565+ }
566+ if appID != "" {
567+ filter ["app_id" ] = appID
568+ }
548569 if opts .Status != "" {
549570 filter ["status" ] = string (opts .Status )
550571 }
@@ -616,8 +637,13 @@ func (s *Store) GetInvoiceByPeriod(ctx context.Context, tenantID, appID string,
616637func (s * Store ) ListPendingInvoices (ctx context.Context , appID string ) ([]* invoice.Invoice , error ) {
617638 var models []invoiceModel
618639
640+ filter := bson.M {"status" : string (invoice .StatusPending )}
641+ if appID != "" {
642+ filter ["app_id" ] = appID
643+ }
644+
619645 err := s .mdb .NewFind (& models ).
620- Filter (bson. M { "app_id" : appID , "status" : string ( invoice . StatusPending )} ).
646+ Filter (filter ).
621647 Sort (bson.D {{Key : "created_at" , Value : - 1 }}).
622648 Scan (ctx )
623649 if err != nil {
@@ -713,7 +739,10 @@ func (s *Store) GetCouponByID(ctx context.Context, couponID id.CouponID) (*coupo
713739func (s * Store ) ListCoupons (ctx context.Context , appID string , opts coupon.ListOpts ) ([]* coupon.Coupon , error ) {
714740 var models []couponModel
715741
716- filter := bson.M {"app_id" : appID }
742+ filter := bson.M {}
743+ if appID != "" {
744+ filter ["app_id" ] = appID
745+ }
717746 if opts .Active {
718747 t := time .Now ().UTC ()
719748 filter ["$and" ] = bson.A {
@@ -827,7 +856,10 @@ func (s *Store) GetFeatureByKey(ctx context.Context, key, appID string) (*featur
827856func (s * Store ) ListFeatures (ctx context.Context , appID string , opts feature.ListOpts ) ([]* feature.Feature , error ) {
828857 var models []featureCatalogModel
829858
830- filter := bson.M {"app_id" : appID }
859+ filter := bson.M {}
860+ if appID != "" {
861+ filter ["app_id" ] = appID
862+ }
831863 if opts .Status != "" {
832864 filter ["status" ] = string (opts .Status )
833865 }
0 commit comments