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:
Marc-André Bombeck committed 2026-05-14 17:09:46 +02:00
1 parent 7851341d98
commit 8c929fc554
1 file changed
+10 -14
+10 -14
View File
@@ -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;
}