@@ -64,7 +64,7 @@ export class HealthData extends Common implements HealthDataApi {
6464 return new Promise ( ( resolve , reject ) => {
6565 let typeOfData = acceptableDataTypes [ opts . dataType ] ;
6666 if ( quantityTypes [ typeOfData ] || categoryTypes [ typeOfData ] ) {
67- this . queryForQuantityOrCategoryData ( typeOfData , opts . startDate , opts . endDate , opts . aggregateBy , opts . unit , ( res , error ) => {
67+ this . queryForQuantityOrCategoryData ( typeOfData , opts , ( res , error ) => {
6868 if ( error ) {
6969 reject ( error ) ;
7070 } else {
@@ -92,16 +92,16 @@ export class HealthData extends Common implements HealthDataApi {
9292 }
9393 }
9494
95- private queryForQuantityOrCategoryData ( dataType : string , start : Date , end : Date , aggregateBy : AggregateBy , unitString : string , callback : ( data : Array < ResponseItem > , error : string ) => void ) {
95+ private queryForQuantityOrCategoryData ( dataType : string , opts : QueryRequest , callback : ( data : Array < ResponseItem > , error : string ) => void ) {
9696 let objectType = this . resolveDataType ( dataType ) ;
9797
98- const predicate = HKQuery . predicateForSamplesWithStartDateEndDateOptions ( start , end , HKQueryOptions . StrictStartDate ) ;
98+ const predicate = HKQuery . predicateForSamplesWithStartDateEndDateOptions ( opts . startDate , opts . endDate , HKQueryOptions . StrictStartDate ) ;
9999
100- let endDateSortDescriptor = NSSortDescriptor . alloc ( ) . initWithKeyAscending ( HKSampleSortIdentifierEndDate , true ) ;
100+ let endDateSortDescriptor = NSSortDescriptor . alloc ( ) . initWithKeyAscending ( HKSampleSortIdentifierEndDate , opts . sortOrder !== "desc" ) ;
101101 const sortBy = NSArray . arrayWithObject < NSSortDescriptor > ( endDateSortDescriptor ) ;
102102
103103 // note that passing an invalid 'unitString' will crash the app (can't catch that error either)
104- const unit = HKUnit . unitFromString ( unitString ) ;
104+ const unit = HKUnit . unitFromString ( opts . unit ) ;
105105
106106 let query = HKSampleQuery . alloc ( ) . initWithSampleTypePredicateLimitSortDescriptorsResultsHandler (
107107 objectType , predicate , null , sortBy , ( query : HKSampleQuery , listResults : NSArray < HKSample > , error : NSError ) => {
@@ -114,7 +114,7 @@ export class HealthData extends Common implements HealthDataApi {
114114
115115 const resultItem = < ResponseItem > {
116116 source : source . name ,
117- unit : unitString ,
117+ unit : opts . unit ,
118118 start : startDate ,
119119 end : endDate
120120 } ;
@@ -124,14 +124,14 @@ export class HealthData extends Common implements HealthDataApi {
124124 if ( ( < HKQuantitySample > sample ) . quantity . isCompatibleWithUnit ( unit ) ) {
125125 resultItem . value = ( < HKQuantitySample > sample ) . quantity . doubleValueForUnit ( unit ) ;
126126 } else {
127- console . log ( "Incompatible unit passed: " + unitString + " (" + unit + ")" ) ;
127+ console . log ( "Incompatible unit passed: " + opts . unit + " (" + unit + ")" ) ;
128128 }
129129 }
130130
131131 parsedData . push ( resultItem ) ;
132132 }
133133
134- callback ( this . aggregate ( parsedData , aggregateBy ) , null ) ;
134+ callback ( this . aggregate ( parsedData , opts . aggregateBy ) , null ) ;
135135 } else {
136136 console . dir ( error ) ;
137137 callback ( null , error . localizedDescription ) ;
0 commit comments