feat: Enhance activity log handling and session metrics synchronization
- Added a new function to synchronize session metrics with activity log entries, ensuring data consistency. - Updated the create and update activity endpoints to call the synchronization function after inserting or modifying activity logs. - Introduced a set of allowed keys for activity log payloads to streamline data handling in the frontend. - Improved data coercion logic for various data types in the frontend to ensure accurate data submission.
This commit is contained in:
1 parent
db9952525a
commit
3296dfca28
4 files changed
+174
-14
No files matched your search
@@ -15,6 +15,26 @@ const ACTIVITY_TYPES = [
|
||||
'Cardio Dance','Geist & Körper','Sonstiges'
|
||||
]
|
||||
|
||||
/** Spalten, die mit ActivityEntry / UPDATE activity_log geschrieben werden dürfen (Übergang: Profilfelder → Kopfzeile). */
|
||||
const ACTIVITY_LOG_PAYLOAD_KEYS = new Set([
|
||||
'date',
|
||||
'start_time',
|
||||
'end_time',
|
||||
'activity_type',
|
||||
'duration_min',
|
||||
'kcal_active',
|
||||
'kcal_resting',
|
||||
'hr_avg',
|
||||
'hr_max',
|
||||
'distance_km',
|
||||
'rpe',
|
||||
'source',
|
||||
'notes',
|
||||
'training_type_id',
|
||||
'training_category',
|
||||
'training_subcategory',
|
||||
])
|
||||
|
||||
function empty() {
|
||||
return {
|
||||
date: dayjs().format('YYYY-MM-DD'),
|
||||
@@ -360,6 +380,26 @@ export default function ActivityPage() {
|
||||
try {
|
||||
const payload = { ...editing }
|
||||
delete payload.id
|
||||
for (const s of sessionDetail?.schema || []) {
|
||||
const col = s.source_field
|
||||
if (!col || !ACTIVITY_LOG_PAYLOAD_KEYS.has(col)) continue
|
||||
if (!(s.key in metricDraft)) continue
|
||||
const raw = metricDraft[s.key]
|
||||
if (raw === '' || raw === null || raw === undefined) continue
|
||||
let v = raw
|
||||
if (s.data_type === 'integer') {
|
||||
v = parseInt(String(raw), 10)
|
||||
if (Number.isNaN(v)) continue
|
||||
} else if (s.data_type === 'float') {
|
||||
v = parseFloat(String(raw))
|
||||
if (Number.isNaN(v)) continue
|
||||
} else if (s.data_type === 'boolean') {
|
||||
v = !!raw
|
||||
} else {
|
||||
v = String(raw)
|
||||
}
|
||||
payload[col] = v
|
||||
}
|
||||
if (payload.duration_min !== '' && payload.duration_min != null) payload.duration_min = parseFloat(payload.duration_min)
|
||||
if (payload.kcal_active !== '' && payload.kcal_active != null) payload.kcal_active = parseFloat(payload.kcal_active)
|
||||
if (payload.hr_avg !== '' && payload.hr_avg != null) payload.hr_avg = parseFloat(payload.hr_avg)
|
||||
|
||||
Reference in new issue
Block a user