Skip to content

Commit

Permalink
[BREAKING] feat: return pageToken in readRecords (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
Minishlink authored Aug 8, 2024
1 parent 01e0d83 commit c825563
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,15 @@ class ReactHealthRecord {
fun parseRecords(
recordType: String,
response: ReadRecordsResponse<out Record>
): WritableNativeArray {
): WritableNativeMap {
val recordClass = createReactHealthRecordInstance<Record>(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))
}
})
}
}

Expand Down
6 changes: 3 additions & 3 deletions docs/docs/api/methods/07-readRecords.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function readRecords<T extends RecordType>(

// read options such as time range filter, data origin filter, ordering and pagination
options: ReadRecordsOptions
): Promise<RecordResult<T>[]>
): Promise<ReadRecordsResult<T>>
```

# Example
Expand All @@ -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}}]}
});
};
```
4 changes: 2 additions & 2 deletions docs/docs/get-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,15 @@ 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',
endTime: '2023-01-09T23:53:15.405Z',
},
});
// {
// result: [
// records: [
// {
// startTime: '2023-01-09T12:00:00.405Z',
// endTime: '2023-01-09T23:53:15.405Z',
Expand Down
5 changes: 1 addition & 4 deletions src/NativeHealthConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ export interface Spec extends TurboModule {
getGrantedPermissions(): Promise<Permission[]>;
revokeAllPermissions(): Promise<void>;
insertRecords(records: HealthConnectRecord[]): Promise<string[]>;
readRecords(
recordType: string,
options: ReadRecordsOptions
): Promise<Array<{}>>;
readRecords(recordType: string, options: ReadRecordsOptions): Promise<{}>;
readRecord(recordType: string, recordId: string): Promise<{}>;
aggregateRecord(record: {
recordType: string;
Expand Down
3 changes: 2 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
ReadRecordsOptions,
RecordResult,
RecordType,
ReadRecordsResult,
GetChangesRequest,
GetChangesResults,
} from './types';
Expand Down Expand Up @@ -110,7 +111,7 @@ export function revokeAllPermissions(): void {
export function readRecords<T extends RecordType>(
recordType: T,
options: ReadRecordsOptions
): Promise<RecordResult<T>[]> {
): Promise<ReadRecordsResult<T>> {
return HealthConnect.readRecords(recordType, options);
}

Expand Down
5 changes: 5 additions & 0 deletions src/types/results.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,3 +321,8 @@ export type RecordResult<T extends RecordType> = Omit<
Extract<HealthConnectRecordResult, { recordType: T }>,
'recordType'
>;

export type ReadRecordsResult<T extends RecordType> = {
records: RecordResult<T>[];
pageToken?: string;
};

0 comments on commit c825563

Please sign in to comment.