fix: strict has_subscription statements.
This commit is contained in:
@@ -24,6 +24,7 @@ async def get_subscription(ctx: AuthContext = Depends(get_auth_context)):
|
||||
sub = ctx.user.subscription
|
||||
if not sub:
|
||||
return SubscriptionData(
|
||||
has_subscription=False,
|
||||
devices=None,
|
||||
expires_at=None,
|
||||
addon_ids=[],
|
||||
@@ -32,6 +33,7 @@ async def get_subscription(ctx: AuthContext = Depends(get_auth_context)):
|
||||
rw_user = await get_rw_user(get_sdk(), ctx.user.telegram_id, ctx.user.username)
|
||||
|
||||
return SubscriptionData(
|
||||
has_subscription=True,
|
||||
devices=sub.devices,
|
||||
expires_at=sub.expires_at,
|
||||
addon_ids=[a.id for a in sub.addons],
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from datetime import datetime
|
||||
|
||||
from pydantic import BaseModel, Field, computed_field
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class SubscriptionData(BaseModel):
|
||||
@@ -8,11 +8,7 @@ class SubscriptionData(BaseModel):
|
||||
expires_at: datetime | None = Field(None)
|
||||
addon_ids: list[str] = Field(default_factory=list)
|
||||
subscription_link: str | None = Field(None)
|
||||
|
||||
@property
|
||||
@computed_field
|
||||
def has_subscription(self) -> bool:
|
||||
return all([self.devices, self.expires_at, self.subscription_link, self.addon_ids])
|
||||
has_subscription: bool = Field()
|
||||
|
||||
|
||||
class UserInfo(BaseModel):
|
||||
|
||||
Reference in New Issue
Block a user