diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactHealthRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactHealthRecord.kt index d3c6b55..d8660ef 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactHealthRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactHealthRecord.kt @@ -80,12 +80,15 @@ class ReactHealthRecord { fun parseRecords( recordType: String, response: ReadRecordsResponse - ): WritableNativeArray { + ): WritableNativeMap { val recordClass = createReactHealthRecordInstance(recordType) - return WritableNativeArray().apply { - for (record in response.records) { - pushMap(recordClass.parseRecord(record)) - } + return WritableNativeMap().apply { + putString("pageToken", response.pageToken) + putArray("records", WritableNativeArray().apply { + for (record in response.records) { + pushMap(recordClass.parseRecord(record)) + } + }) } } diff --git a/docs/docs/api/methods/07-readRecords.md b/docs/docs/api/methods/07-readRecords.md index c8f5638..9927c2b 100644 --- a/docs/docs/api/methods/07-readRecords.md +++ b/docs/docs/api/methods/07-readRecords.md @@ -15,7 +15,7 @@ function readRecords( // read options such as time range filter, data origin filter, ordering and pagination options: ReadRecordsOptions -): Promise[]> +): Promise> ``` # Example @@ -30,8 +30,8 @@ const readSampleData = () => { startTime: '2023-01-09T12:00:00.405Z', endTime: '2023-01-09T23:53:15.405Z', }, - }).then((result) => { - console.log('Retrieved records: ', JSON.stringify({ result }, null, 2)); // Retrieved records: {"result":[{"startTime":"2023-01-09T12:00:00.405Z","endTime":"2023-01-09T23:53:15.405Z","energy":{"inCalories":15000000,"inJoules":62760000.00989097,"inKilojoules":62760.00000989097,"inKilocalories":15000},"metadata":{"id":"239a8cfd-990d-42fc-bffc-c494b829e8e1","lastModifiedTime":"2023-01-17T21:06:23.335Z","clientRecordId":null,"dataOrigin":"com.healthconnectexample","clientRecordVersion":0,"device":0}}]} + }).then(({ records }) => { + console.log('Retrieved records: ', JSON.stringify({ records }, null, 2)); // Retrieved records: {"records":[{"startTime":"2023-01-09T12:00:00.405Z","endTime":"2023-01-09T23:53:15.405Z","energy":{"inCalories":15000000,"inJoules":62760000.00989097,"inKilojoules":62760.00000989097,"inKilocalories":15000},"metadata":{"id":"239a8cfd-990d-42fc-bffc-c494b829e8e1","lastModifiedTime":"2023-01-17T21:06:23.335Z","clientRecordId":null,"dataOrigin":"com.healthconnectexample","clientRecordVersion":0,"device":0}}]} }); }; ``` diff --git a/docs/docs/get-started.md b/docs/docs/get-started.md index 6ff426e..18cc65c 100644 --- a/docs/docs/get-started.md +++ b/docs/docs/get-started.md @@ -144,7 +144,7 @@ const readSampleData = async () => { // check if granted - const result = await readRecords('ActiveCaloriesBurned', { + const { records } = await readRecords('ActiveCaloriesBurned', { timeRangeFilter: { operator: 'between', startTime: '2023-01-09T12:00:00.405Z', @@ -152,7 +152,7 @@ const readSampleData = async () => { }, }); // { - // result: [ + // records: [ // { // startTime: '2023-01-09T12:00:00.405Z', // endTime: '2023-01-09T23:53:15.405Z', diff --git a/src/NativeHealthConnect.ts b/src/NativeHealthConnect.ts index c8c8aae..b1af4a6 100644 --- a/src/NativeHealthConnect.ts +++ b/src/NativeHealthConnect.ts @@ -24,10 +24,7 @@ export interface Spec extends TurboModule { getGrantedPermissions(): Promise; revokeAllPermissions(): Promise; insertRecords(records: HealthConnectRecord[]): Promise; - readRecords( - recordType: string, - options: ReadRecordsOptions - ): Promise>; + readRecords(recordType: string, options: ReadRecordsOptions): Promise<{}>; readRecord(recordType: string, recordId: string): Promise<{}>; aggregateRecord(record: { recordType: string; diff --git a/src/index.tsx b/src/index.tsx index ff9e589..15ae186 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -9,6 +9,7 @@ import type { ReadRecordsOptions, RecordResult, RecordType, + ReadRecordsResult, GetChangesRequest, GetChangesResults, } from './types'; @@ -110,7 +111,7 @@ export function revokeAllPermissions(): void { export function readRecords( recordType: T, options: ReadRecordsOptions -): Promise[]> { +): Promise> { return HealthConnect.readRecords(recordType, options); } diff --git a/src/types/results.types.ts b/src/types/results.types.ts index 08e370d..06fe78a 100644 --- a/src/types/results.types.ts +++ b/src/types/results.types.ts @@ -321,3 +321,8 @@ export type RecordResult = Omit< Extract, 'recordType' >; + +export type ReadRecordsResult = { + records: RecordResult[]; + pageToken?: string; +};