diff --git a/src/infrastructure/repository/fitbit.data.repository.ts b/src/infrastructure/repository/fitbit.data.repository.ts index cc877be..5296c25 100644 --- a/src/infrastructure/repository/fitbit.data.repository.ts +++ b/src/infrastructure/repository/fitbit.data.repository.ts @@ -640,9 +640,21 @@ export class FitbitDataRepository implements IFitbitDataRepository { private parsePhysicalActivity(item: any, userId: string): PhysicalActivity { if (!item) return item - const heartrate: any = { average: undefined, heart_rate_zones: undefined } + const activity: any = { + type: 'physical_activity', + start_time: moment(item.startTime).utc().format(), + end_time: moment(item.startTime).add(item.duration, 'milliseconds').utc().format(), + duration: item.duration, + child_id: userId, + name: item.activityName, + calories: item.calories, + steps: item.steps, + distance: item.distance ? this.convertDistanceToMetter(item.distance, item.distanceUnit) : undefined, + levels: item.activityLevel.map(level => { + return { duration: level.minutes * 60000, name: level.name } + }) + } if (item.averageHeartRate !== undefined && item.heartRateZones !== undefined) { - heartrate.average = item.averageHeartRate const out_of_range = item.heartRateZones.filter(zone => zone.name = 'Out of Range')[0] const fat_burn = item.heartRateZones.filter(zone => zone.name = 'Fat Burn')[0] @@ -654,24 +666,10 @@ export class FitbitDataRepository implements IFitbitDataRepository { const cardio_zone = { min: cardio.min, max: cardio.max, duration: cardio.minutes * 60000 } const peak_zone = { min: peak.min, max: peak.max, duration: peak.minutes * 60000 } - heartrate.heart_rate_zones = { out_of_range_zone, fat_burn_zone, cardio_zone, peak_zone } - } + activity.heart_rate = { average: item.averageHeartRate, out_of_range_zone, fat_burn_zone, cardio_zone, peak_zone } - return new PhysicalActivity().fromJSON({ - type: 'physical_activity', - start_time: moment(item.startTime).utc().format(), - end_time: moment(item.startTime).add(item.duration, 'milliseconds').utc().format(), - duration: item.duration, - child_id: userId, - name: item.activityName, - calories: item.calories, - steps: item.steps, - distance: item.distance ? this.convertDistanceToMetter(item.distance, item.distanceUnit) : undefined, - levels: item.activityLevel.map(level => { - return { duration: level.minutes * 60000, name: level.name } - }), - heart_rate: heartrate.average && heartrate.heart_rate_zones ? heartrate : undefined - }) + } + return new PhysicalActivity().fromJSON(activity) } private convertDistanceToMetter(distance: number, unit: string): number {