how to fix///
This commit is contained in:
		
							parent
							
								
									dd18be4e7e
								
							
						
					
					
						commit
						bebccbd350
					
				| 
						 | 
				
			
			@ -56,7 +56,9 @@ async def grant_tab(request: RequestSchema):
 | 
			
		|||
@app.post("/grant_subscribe/")
 | 
			
		||||
async def grant_tab(request: RequestSchema):
 | 
			
		||||
    profile = await get_profile(schema=request)
 | 
			
		||||
    print('profile')
 | 
			
		||||
    await database.update_subscription(user=profile)
 | 
			
		||||
    print('yesss')
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
async def get_profile(schema: RequestSchema) -> UserSchema:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -141,8 +141,11 @@ class Database:
 | 
			
		|||
    async def update_subscription(self, user: UserSchema):
 | 
			
		||||
        async with self.AsyncSessionLocal() as session:
 | 
			
		||||
            try:
 | 
			
		||||
                print(1)
 | 
			
		||||
                await self.delete_expired_subscriptions()
 | 
			
		||||
                print(2)
 | 
			
		||||
                await self.delete_expired_tab_users()
 | 
			
		||||
                print(3)
 | 
			
		||||
                expiry_datetime = datetime.datetime.fromtimestamp(user.expiry, datetime.timezone.utc)
 | 
			
		||||
                if user.has_sub:
 | 
			
		||||
                    subscription = await session.execute(select(Subscribe).where(Subscribe.discord == user.discord_id and Subscribe.nickname == user.username))
 | 
			
		||||
| 
						 | 
				
			
			@ -156,10 +159,14 @@ class Database:
 | 
			
		|||
                else:
 | 
			
		||||
                    new_subscription = Subscribe(discord=user.discord_id, nickname=user.username, expiry=expiry_datetime)
 | 
			
		||||
                    session.add(new_subscription)
 | 
			
		||||
                print(4)
 | 
			
		||||
                await session.commit()
 | 
			
		||||
                await self.grant_tab_by_username(user=user)
 | 
			
		||||
                print(5)
 | 
			
		||||
                await self.grant_permissions_by_uuid(user=user)
 | 
			
		||||
                print(6)
 | 
			
		||||
                await discord_role(str(user.discord_id))
 | 
			
		||||
                print(7)
 | 
			
		||||
            except Exception as e:
 | 
			
		||||
                print("Ошибка при выполнении запроса:", e)
 | 
			
		||||
                await session.rollback()
 | 
			
		||||
| 
						 | 
				
			
			@ -173,12 +180,14 @@ class Database:
 | 
			
		|||
                print("Ошибка при удалении устаревших подписок:", e)
 | 
			
		||||
                await session.rollback()
 | 
			
		||||
    
 | 
			
		||||
async def discord_role(discord_id: int):
 | 
			
		||||
async def discord_role(discord_id: str):
 | 
			
		||||
    params = {"user_id": discord_id, "token": configs.TOKEN_DS}
 | 
			
		||||
    
 | 
			
		||||
    async with httpx.AsyncClient() as client:
 | 
			
		||||
        try:
 | 
			
		||||
            print(66)
 | 
			
		||||
            response = await client.get(configs.DS_URL, params=params)
 | 
			
		||||
            print(666)
 | 
			
		||||
            data = response.json()
 | 
			
		||||
            return data
 | 
			
		||||
        except httpx.HTTPError as e:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue