feat: Integrate caliper data enrichment and weight loading in API responses
- Enhanced the caliper listing and export functionalities to include enriched data from weight logs. - Updated the upsert and update operations to utilize new composition functions for body composition calculations. - Refactored the CaliperScreen component to streamline payload construction by removing unnecessary parameters.
This commit is contained in:
1 parent
00437a92ab
commit
49e9c9c214
6 files changed
+178
-19
No files matched your search
@@ -19,7 +19,6 @@ function emptyForm() {
|
||||
function CaliperForm({ form, setForm, profile, onSave, onCancel, saveLabel='Speichern', saving=false, error=null, usage=null }) {
|
||||
const sex = profile?.sex||'m'
|
||||
const age = profile?.dob ? Math.floor((Date.now()-new Date(profile.dob))/(365.25*24*3600*1000)) : 30
|
||||
const weight = form.weight || 80
|
||||
const sfPoints = METHOD_POINTS[form.sf_method]?.[sex] || []
|
||||
const sfVals = {}
|
||||
sfPoints.forEach(k=>{ const v=form[`sf_${k}`]; if(v!==''&&v!=null) sfVals[k]=parseFloat(v) })
|
||||
@@ -79,7 +78,7 @@ function CaliperForm({ form, setForm, profile, onSave, onCancel, saveLabel='Spei
|
||||
<button
|
||||
className="btn btn-primary"
|
||||
style={{width:'100%', cursor: (usage && !usage.allowed) ? 'not-allowed' : 'pointer'}}
|
||||
onClick={()=>onSave(bfPct, sex)}
|
||||
onClick={()=>onSave(bfPct)}
|
||||
disabled={saving || (usage && !usage.allowed)}
|
||||
>
|
||||
{(usage && !usage.allowed) ? '🔒 Limit erreicht' : saveLabel}
|
||||
@@ -117,22 +116,19 @@ export default function CaliperScreen() {
|
||||
loadUsage()
|
||||
},[])
|
||||
|
||||
const buildPayload = (f, bfPct, sex) => {
|
||||
const weight = profile?.weight || null
|
||||
const buildPayload = (f, bfPct) => {
|
||||
const payload = { date: f.date, sf_method: f.sf_method, notes: f.notes }
|
||||
Object.entries(f).forEach(([k,v])=>{ if(k.startsWith('sf_')&&v!==''&&v!=null) payload[k]=parseFloat(v) })
|
||||
if(bfPct!=null) {
|
||||
payload.body_fat_pct = bfPct
|
||||
// get latest weight from profile or skip lean/fat
|
||||
}
|
||||
if (bfPct != null) payload.body_fat_pct = bfPct
|
||||
// lean_mass / fat_mass: Backend leitet aus nächstem weight_log zum Messdatum ab
|
||||
return payload
|
||||
}
|
||||
|
||||
const handleSave = async (bfPct, sex) => {
|
||||
const handleSave = async (bfPct) => {
|
||||
setSaving(true)
|
||||
setError(null)
|
||||
try {
|
||||
const payload = buildPayload(form, bfPct, sex)
|
||||
const payload = buildPayload(form, bfPct)
|
||||
await api.upsertCaliper(payload)
|
||||
setSaved(true)
|
||||
await load()
|
||||
@@ -148,8 +144,8 @@ export default function CaliperScreen() {
|
||||
}
|
||||
}
|
||||
|
||||
const handleUpdate = async (bfPct, sex) => {
|
||||
const payload = buildPayload(editing, bfPct, sex)
|
||||
const handleUpdate = async (bfPct) => {
|
||||
const payload = buildPayload(editing, bfPct)
|
||||
await api.updateCaliper(editing.id, payload)
|
||||
setEditing(null); await load()
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user