mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-09 21:10:59 +00:00
refactor(apple-health): collapse sleep branch in mapAppleHealthEntry
Builds the base output object once with the four shared fields and appends sleepStage only when the mapping carries a sleep-stage table. Drops one duplicated object literal and one return path; the function keeps the same null-on-bad-input semantics for unmapped, invalid date, missing stage, and unknown stage cases.
This commit is contained in:
1 parent
7851341d98
commit
8c929fc554
1 file changed
+10
-14
@@ -438,23 +438,19 @@ export function mapAppleHealthEntry(
|
||||
|
||||
const value = mapping.convertToDbUnit(input.value);
|
||||
|
||||
if (mapping.sleepStageMap !== undefined) {
|
||||
if (input.sleepStage === undefined) return null;
|
||||
const stage = mapping.sleepStageMap[input.sleepStage];
|
||||
if (!stage) return null;
|
||||
return {
|
||||
type: mapping.measurementType,
|
||||
value,
|
||||
unit: mapping.dbUnit,
|
||||
takenAt,
|
||||
sleepStage: stage,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
const out: AppleHealthEntryOutput = {
|
||||
type: mapping.measurementType,
|
||||
value,
|
||||
unit: mapping.dbUnit,
|
||||
takenAt,
|
||||
};
|
||||
|
||||
if (mapping.sleepStageMap) {
|
||||
if (input.sleepStage === undefined) return null;
|
||||
const stage = mapping.sleepStageMap[input.sleepStage];
|
||||
if (!stage) return null;
|
||||
out.sleepStage = stage;
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
Reference in new issue
Block a user