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
@@ -12,11 +12,11 @@ class PhotoMutationResolver(BaseMutationResolver):
def __init__(self):
super().__init__(Photo, models.Photo)
async def reset_flight_cover(self, db: AsyncSession, flight_id: int):
async def reset_flight_cover(self, db: AsyncSession, flight_id: int, ignored_photo_id: int):
(await db.execute(
update(models.Photo)
.filter(models.Photo.flight_id == flight_id)
.filter(models.Photo.id != id).values(is_flight_cover=False))
.filter(models.Photo.id != ignored_photo_id).values(is_flight_cover=False))
)
async def update(self, id: int, input: EditPhotoInput, user_id: int) -> Photo:
@@ -35,6 +35,6 @@ class PhotoMutationResolver(BaseMutationResolver):
if input.is_flight_cover:
# reset other covers
await self.reset_flight_cover(db, photo.flight_id)
await self.reset_flight_cover(db, photo.flight_id, id)
return await self._do_update(db, obj=photo, data=data)