UNPKG

react-native-healthkit-bridge

Version:

A comprehensive React Native bridge for Apple HealthKit with TypeScript support, advanced authorization, and flexible data queries

50 lines (44 loc) 1.68 kB
import { HealthKitRepository } from '../repositories/HealthKitRepository'; import { HealthKitQuantitySample } from '../entities/HealthKitSample'; import { HealthKitIdentifier, HealthKitUnit, DateRange } from '../value-objects/HealthKitIdentifier'; export class GetQuantitySamplesUseCase { constructor(private readonly healthKitRepository: HealthKitRepository) {} async execute( identifier: string, unit: string, dateRange: { startDate: Date; endDate: Date } ): Promise<HealthKitQuantitySample[]> { try { const healthKitIdentifier = HealthKitIdentifier.create(identifier); const healthKitUnit = HealthKitUnit.create(unit); const range = new DateRange(dateRange.startDate, dateRange.endDate); return await this.healthKitRepository.getQuantitySamples( healthKitIdentifier, healthKitUnit, range ); } catch (error) { throw new Error(`Failed to get quantity samples: ${error instanceof Error ? error.message : 'Unknown error'}`); } } async executeForDays( identifier: string, unit: string, days: number ): Promise<HealthKitQuantitySample[]> { try { const healthKitIdentifier = HealthKitIdentifier.create(identifier); const healthKitUnit = HealthKitUnit.create(unit); if (days <= 0) { throw new Error('Days must be greater than 0'); } return await this.healthKitRepository.getQuantitySamplesForDays( healthKitIdentifier, healthKitUnit, days ); } catch (error) { throw new Error(`Failed to get quantity samples for days: ${error instanceof Error ? error.message : 'Unknown error'}`); } } }