tasks work better now
This commit is contained in:
24
app.py
24
app.py
@@ -192,19 +192,31 @@ def stop_timer():
|
||||
def complete_task():
|
||||
if not is_logged_in(): return jsonify({'error': 'auth'}), 401
|
||||
|
||||
user_id = get_user_id()
|
||||
task_id = request.form['task_id']
|
||||
is_checked = request.form['is_checked'] == 'true'
|
||||
|
||||
status = 'completed' if is_checked else 'open'
|
||||
completed_at = datetime.now() if is_checked else None
|
||||
|
||||
db.tasks.update_one(
|
||||
{'_id': ObjectId(task_id), 'user_id': get_user_id()},
|
||||
{'$set': {'status': status, 'completed_at': completed_at}}
|
||||
)
|
||||
update_doc = {
|
||||
'status': status,
|
||||
'completed_at': completed_at
|
||||
}
|
||||
|
||||
# If it was a generic activity task, bind it to current entry if one acts so it shows in log
|
||||
# (Optional logic, skipping for simplicity)
|
||||
# If the task is being completed, try to link it to the currently active timer
|
||||
if is_checked:
|
||||
current_entry = db.time_entries.find_one({
|
||||
'user_id': user_id,
|
||||
'end_time': None
|
||||
})
|
||||
if current_entry:
|
||||
update_doc['time_entry_id'] = current_entry['_id']
|
||||
|
||||
db.tasks.update_one(
|
||||
{'_id': ObjectId(task_id), 'user_id': user_id},
|
||||
{'$set': update_doc}
|
||||
)
|
||||
|
||||
return jsonify({'status': 'success'})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user