-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from oldratip/feat/exposing-heartbeat-series-q…
…uery feat: exposing HKHeartbeatSeriesQuery for Heartbeat series data
- Loading branch information
Showing
10 changed files
with
261 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import type { HKHeartbeatSeriesSampleRaw } from '../native-types' | ||
import type { HKHeartbeatSeriesSample } from '../types' | ||
|
||
function deserializeHeartbeatSeriesSample(sample: HKHeartbeatSeriesSampleRaw): HKHeartbeatSeriesSample { | ||
return { | ||
...sample, | ||
startDate: new Date(sample.startDate), | ||
endDate: new Date(sample.endDate), | ||
} | ||
} | ||
|
||
export default deserializeHeartbeatSeriesSample |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import Native from '../native-types' | ||
import deserializeHeartbeatSeriesSample from './deserializeHeartbeatSeriesSample' | ||
import prepareOptions from './prepareOptions' | ||
|
||
import type { DeletedHeartbeatSeriesSampleRaw } from '../native-types' | ||
import type { GenericQueryOptions, HKHeartbeatSeriesSample } from '../types' | ||
|
||
export type QueryHeartbeatSeriesSamplesResponse = { | ||
readonly samples: readonly HKHeartbeatSeriesSample[], | ||
readonly deletedSamples: readonly DeletedHeartbeatSeriesSampleRaw[], | ||
readonly newAnchor: string | ||
} | ||
|
||
export type QueryHeartbeatSeriesSamplesFn = (options: GenericQueryOptions) => Promise<QueryHeartbeatSeriesSamplesResponse>; | ||
|
||
const queryHeartbeatSeriesSamples: QueryHeartbeatSeriesSamplesFn = async (options) => { | ||
const opts = prepareOptions(options) | ||
|
||
const result = await Native.queryHeartbeatSeriesSamples( | ||
opts.from, | ||
opts.to, | ||
opts.limit, | ||
opts.ascending, | ||
opts.anchor, | ||
) | ||
|
||
return { | ||
deletedSamples: result.deletedSamples, | ||
newAnchor: result.newAnchor, | ||
samples: result.samples.map(deserializeHeartbeatSeriesSample), | ||
} | ||
} | ||
|
||
export default queryHeartbeatSeriesSamples |