mirror of
https://github.com/BEDOLAGA-DEV/remnawave-bedolaga-telegram-bot.git
synced 2026-05-04 20:15:56 +00:00
Merge pull request #1487 from Fr1ngg/dbunp5-bedolaga/fix-double-reward-issue-in-poll-system
Prevent double payout when rewarding poll
This commit is contained in:
@@ -168,6 +168,8 @@ async def reward_user_for_poll(
|
||||
db: AsyncSession,
|
||||
response: PollResponse,
|
||||
) -> int:
|
||||
await db.refresh(response, with_for_update=True)
|
||||
|
||||
poll = response.poll
|
||||
if not poll.reward_enabled or poll.reward_amount_kopeks <= 0:
|
||||
return 0
|
||||
@@ -178,6 +180,9 @@ async def reward_user_for_poll(
|
||||
user = response.user
|
||||
description = f"Награда за участие в опросе \"{poll.title}\""
|
||||
|
||||
response.reward_given = True
|
||||
response.reward_amount_kopeks = poll.reward_amount_kopeks
|
||||
|
||||
success = await add_user_balance(
|
||||
db,
|
||||
user,
|
||||
@@ -189,9 +194,10 @@ async def reward_user_for_poll(
|
||||
if not success:
|
||||
return 0
|
||||
|
||||
response.reward_given = True
|
||||
response.reward_amount_kopeks = poll.reward_amount_kopeks
|
||||
await db.commit()
|
||||
await db.refresh(
|
||||
response,
|
||||
attribute_names=["reward_given", "reward_amount_kopeks"],
|
||||
)
|
||||
|
||||
return poll.reward_amount_kopeks
|
||||
|
||||
|
||||
Reference in New Issue
Block a user