Fix otaceni fotek, drobny refaktoring

This commit is contained in:
Michal Kváček
2023-10-15 14:24:57 +02:00
parent bc258efa3a
commit 322e61bce3
8 changed files with 25 additions and 30 deletions
@@ -3,6 +3,7 @@ from sqlalchemy.ext.asyncio import AsyncSession
from database import models
from database.query_builder import QueryBuilder
from database.transaction import get_session
from graphql_schema.entities.types.base import BaseGraphqlInputType
GQL_TYPE = TypeVar('GQL_TYPE')
@@ -76,6 +77,11 @@ class BaseMutationResolver(BaseResolver):
model = await self.model.update(db, data=data, **update_where)
return self.graphql_type(**model.as_dict())
async def update(self, id: int, data: BaseGraphqlInputType, user_id: int) -> GQL_TYPE:
async with get_session() as db:
item = await self._get_one(db, id, user_id)
return await self._do_update(db, item, data.to_dict())
async def delete(self, user_id: int, id: int) -> GQL_TYPE:
async with get_session() as db:
model = await self._get_one(db, id, user_id)