Accident display: fix aliases + submitted_at format

Issues:
1. Frontend renders record[h] where h comes from column_order.
   column_order now uses submitter_email (not employee_name),
   so record[submitter_email] = None → shows as "-".

2. submitted_at shows as ISO format "2026-07-06T15:45:33.850000"
   (less readable than "2026-07-06 15:45:33").

Fix:
1. to_dict adds both submitter_email and employee_name alias
   (same value, r.submitter_email). Same for injured_person_id ↔ employee_id.
   Frontend column_order key matches record key (submitter_email shows email).

2. submitted_at formatted as "YYYY-MM-DD HH:MM:%S" via strftime

Verified:
- record.submitter_email = "operation@scmedical.hk"
- record.employee_name = "operation@scmedical.hk" (alias)
- record.submitted_at = "2026-07-06 15:45:33"
This commit is contained in:
IT Dog
2026-07-20 01:46:59 +08:00
parent 975791b9bd
commit 95814350c9
+8 -3
View File
@@ -2353,13 +2353,18 @@ async def accident_records(
return { return {
"id": r.id, "id": r.id,
"submitted_at": r.submitted_at.isoformat() if r.submitted_at else None, # Submitted time formatted as "YYYY-MM-DD HH:MM:SS" (display-friendly)
"submitted_at": r.submitted_at.strftime("%Y-%m-%d %H:%M:%S") if r.submitted_at else None,
"date": r.date.isoformat() if r.date else None, "date": r.date.isoformat() if r.date else None,
"time": r.time, "time": r.time,
"incident_datetime": incident_dt, # YYYY-MM-DD HH:MM:SS combined "incident_datetime": incident_dt, # YYYY-MM-DD HH:MM:SS combined
"location": r.location, "location": r.location,
"employee_name": r.submitter_email, # Backend alias: frontend column_order uses submitter_email as key
"employee_id": r.injured_person_id, # but legacy UI expected employee_name
"submitter_email": r.submitter_email,
"employee_name": r.submitter_email, # alias for backward compat
"injured_person_id": r.injured_person_id,
"employee_id": r.injured_person_id, # alias
"department": r.department, "department": r.department,
"description": r.description, "description": r.description,
"severity": r.severity, "severity": r.severity,