Refactor subcription layer
This commit is contained in:
@@ -102,6 +102,42 @@ class SubscriptionRepository(TenantBaseRepository):
|
||||
error=str(e))
|
||||
raise DatabaseError(f"Failed to create subscription: {str(e)}")
|
||||
|
||||
async def get_by_tenant_id(self, tenant_id: str) -> Optional[Subscription]:
|
||||
"""Get subscription by tenant ID"""
|
||||
try:
|
||||
subscriptions = await self.get_multi(
|
||||
filters={
|
||||
"tenant_id": tenant_id
|
||||
},
|
||||
limit=1,
|
||||
order_by="created_at",
|
||||
order_desc=True
|
||||
)
|
||||
return subscriptions[0] if subscriptions else None
|
||||
except Exception as e:
|
||||
logger.error("Failed to get subscription by tenant ID",
|
||||
tenant_id=tenant_id,
|
||||
error=str(e))
|
||||
raise DatabaseError(f"Failed to get subscription: {str(e)}")
|
||||
|
||||
async def get_by_stripe_id(self, stripe_subscription_id: str) -> Optional[Subscription]:
|
||||
"""Get subscription by Stripe subscription ID"""
|
||||
try:
|
||||
subscriptions = await self.get_multi(
|
||||
filters={
|
||||
"stripe_subscription_id": stripe_subscription_id
|
||||
},
|
||||
limit=1,
|
||||
order_by="created_at",
|
||||
order_desc=True
|
||||
)
|
||||
return subscriptions[0] if subscriptions else None
|
||||
except Exception as e:
|
||||
logger.error("Failed to get subscription by Stripe ID",
|
||||
stripe_subscription_id=stripe_subscription_id,
|
||||
error=str(e))
|
||||
raise DatabaseError(f"Failed to get subscription: {str(e)}")
|
||||
|
||||
async def get_active_subscription(self, tenant_id: str) -> Optional[Subscription]:
|
||||
"""Get active subscription for tenant"""
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user