Compare commits
1 Commits
8c656ca6d5
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 3b7798369f |
@@ -58,16 +58,42 @@ def edit_child(id):
|
|||||||
result = child_db.search(ChildQuery.id == id)
|
result = child_db.search(ChildQuery.id == id)
|
||||||
if not result:
|
if not result:
|
||||||
return jsonify({'error': 'Child not found'}), 404
|
return jsonify({'error': 'Child not found'}), 404
|
||||||
child = result[0]
|
child = Child.from_dict(result[0])
|
||||||
|
|
||||||
if name is not None:
|
if name is not None:
|
||||||
child['name'] = name
|
child.name = name
|
||||||
if age is not None:
|
if age is not None:
|
||||||
child['age'] = age
|
child.age = age
|
||||||
if points is not None:
|
if points is not None:
|
||||||
child['points'] = points
|
child.points = points
|
||||||
if image is not None:
|
if image is not None:
|
||||||
child['image_id'] = image
|
child.image_id = image
|
||||||
child_db.update(child, ChildQuery.id == id)
|
|
||||||
|
# Check if points changed and handle pending rewards
|
||||||
|
if points is not None:
|
||||||
|
PendingQuery = Query()
|
||||||
|
pending_rewards = pending_reward_db.search(PendingQuery.child_id == id)
|
||||||
|
|
||||||
|
RewardQuery = Query()
|
||||||
|
for pr in pending_rewards:
|
||||||
|
pending = PendingReward.from_dict(pr)
|
||||||
|
reward_result = reward_db.get(RewardQuery.id == pending.reward_id)
|
||||||
|
if reward_result:
|
||||||
|
reward = Reward.from_dict(reward_result)
|
||||||
|
# If child can no longer afford the reward, remove the pending request
|
||||||
|
if child.points < reward.cost:
|
||||||
|
pending_reward_db.remove(
|
||||||
|
(PendingQuery.child_id == id) & (PendingQuery.reward_id == reward.id)
|
||||||
|
)
|
||||||
|
send_event_to_user(
|
||||||
|
"user123",
|
||||||
|
Event(
|
||||||
|
EventType.CHILD_REWARD_REQUEST.value,
|
||||||
|
ChildRewardRequest(id, reward.id, ChildRewardRequest.REQUEST_CANCELLED)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
child_db.update(child.to_dict(), ChildQuery.id == id)
|
||||||
send_event_to_user("user123", Event(EventType.CHILD_MODIFIED.value, ChildModified(id, ChildModified.OPERATION_EDIT)))
|
send_event_to_user("user123", Event(EventType.CHILD_MODIFIED.value, ChildModified(id, ChildModified.OPERATION_EDIT)))
|
||||||
return jsonify({'message': f'Child {id} updated.'}), 200
|
return jsonify({'message': f'Child {id} updated.'}), 200
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
# file: config/version.py
|
# file: config/version.py
|
||||||
import os
|
import os
|
||||||
|
|
||||||
BASE_VERSION = "1.0.2" # update manually when releasing features
|
BASE_VERSION = "1.0.3" # update manually when releasing features
|
||||||
|
|
||||||
def get_full_version() -> str:
|
def get_full_version() -> str:
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user