Add 'opmerking' column to assessments and implement related functionality
All checks were successful
Build & Push / Build & Push image (push) Successful in 38s

- Updated the database migration to include an 'opmerking' column in the assessments table.
- Modified the Assessment model to include the new 'opmerking' field.
- Enhanced the API to handle saving and retrieving remarks associated with assessments.
- Updated the frontend to display and edit remarks in the assessments table.
This commit is contained in:
2026-03-03 09:17:50 +01:00
parent aa47399b62
commit 5f2e1fdb1b
5 changed files with 409 additions and 86 deletions

View File

@@ -70,10 +70,11 @@ def get_assessments():
@login_required
@limiter.limit('120 per minute') # max 2 per seconde per gebruiker
def save_assessment():
data = request.get_json() or {}
vak_id = (data.get('vak_id') or '').strip()
goal_id = (data.get('goal_id') or '').strip()
status = (data.get('status') or '').strip()
data = request.get_json() or {}
vak_id = (data.get('vak_id') or '').strip()
goal_id = (data.get('goal_id') or '').strip()
status = (data.get('status') or '').strip()
opmerking = (data.get('opmerking') or '').strip()[:500]
if not vak_id or not goal_id:
return jsonify({'error': 'vak_id en goal_id zijn verplicht'}), 400
@@ -104,6 +105,7 @@ def save_assessment():
if assessment:
assessment.status = status
assessment.opmerking = opmerking or None
assessment.updated_at = datetime.utcnow()
else:
assessment = Assessment(
@@ -113,6 +115,7 @@ def save_assessment():
vak_id=vak_id,
goal_id=goal_id,
status=status,
opmerking=opmerking or None,
)
db.session.add(assessment)
@@ -124,6 +127,55 @@ def save_assessment():
return jsonify({'assessment': assessment.to_dict()})
@api_bp.route('/assessments/opmerking', methods=['POST'])
@login_required
@limiter.limit('120 per minute')
def save_opmerking():
"""Sla enkel een opmerking op bij een bestaand of nieuw assessment record."""
data = request.get_json() or {}
vak_id = (data.get('vak_id') or '').strip()
goal_id = (data.get('goal_id') or '').strip()
opmerking = (data.get('opmerking') or '').strip()[:500]
if not vak_id or not goal_id:
return jsonify({'error': 'vak_id en goal_id zijn verplicht'}), 400
if len(vak_id) > 100 or len(goal_id) > 50:
return jsonify({'error': 'Ongeldige invoer'}), 400
if not current_user.school_id:
return jsonify({'error': 'Account niet gekoppeld aan een school'}), 400
school_year = get_active_year(current_user.school_id)
if not school_year:
return jsonify({'error': 'Geen actief schooljaar'}), 400
assessment = Assessment.query.filter_by(
user_id=current_user.id,
school_year_id=school_year.id,
vak_id=vak_id,
goal_id=goal_id,
).first()
if assessment:
assessment.opmerking = opmerking or None
assessment.updated_at = datetime.utcnow()
else:
# Maak een record aan zonder status voor de opmerking
assessment = Assessment(
user_id=current_user.id,
school_id=current_user.school_id,
school_year_id=school_year.id,
vak_id=vak_id,
goal_id=goal_id,
status='',
opmerking=opmerking or None,
)
db.session.add(assessment)
db.session.commit()
return jsonify({'ok': True})
@api_bp.route('/assessments/bulk-import', methods=['POST'])
@login_required
@limiter.limit('5 per minute')