added fixes for bug plan 1.0.6RC01
Some checks failed
Chore App Build, Test, and Push Docker Images / build-and-push (push) Failing after 5m43s
Some checks failed
Chore App Build, Test, and Push Docker Images / build-and-push (push) Failing after 5m43s
This commit is contained in:
@@ -3,11 +3,12 @@ from tinydb import Query
|
||||
|
||||
from api.utils import send_event_for_current_user, get_validated_user_id
|
||||
from events.types.child_rewards_set import ChildRewardsSet
|
||||
from db.db import reward_db, child_db
|
||||
from db.db import reward_db, child_db, pending_confirmations_db
|
||||
from db.child_overrides import delete_overrides_for_entity
|
||||
from events.types.event import Event
|
||||
from events.types.event_types import EventType
|
||||
from events.types.reward_modified import RewardModified
|
||||
from events.types.child_reward_request import ChildRewardRequest
|
||||
from models.reward import Reward
|
||||
|
||||
reward_api = Blueprint('reward_api', __name__)
|
||||
@@ -155,6 +156,21 @@ def edit_reward(id):
|
||||
if not is_dirty:
|
||||
return jsonify({'error': 'No valid fields to update'}), 400
|
||||
|
||||
# Reset pending reward requests when cost changes
|
||||
if 'cost' in data:
|
||||
PendingQuery = Query()
|
||||
pending_rewards = pending_confirmations_db.search(
|
||||
(PendingQuery.entity_id == id) & (PendingQuery.entity_type == 'reward') &
|
||||
(PendingQuery.status == 'pending')
|
||||
)
|
||||
for pr in pending_rewards:
|
||||
pending_confirmations_db.remove(
|
||||
(PendingQuery.child_id == pr['child_id']) & (PendingQuery.entity_id == id) &
|
||||
(PendingQuery.entity_type == 'reward') & (PendingQuery.status == 'pending')
|
||||
)
|
||||
send_event_for_current_user(Event(EventType.CHILD_REWARD_REQUEST.value,
|
||||
ChildRewardRequest(pr['child_id'], id, ChildRewardRequest.REQUEST_CANCELLED)))
|
||||
|
||||
if reward.user_id is None: # public reward
|
||||
new_reward = Reward(name=reward.name, description=reward.description, cost=reward.cost, image_id=reward.image_id, user_id=user_id)
|
||||
reward_db.insert(new_reward.to_dict())
|
||||
|
||||
Reference in New Issue
Block a user