1+ import type { ApiResponse , GetLastSleepRouteResponse } from '../../types.js' ;
12import { getApiKey } from './params.js'
23
34export const getSleepEntries = async ( ) => {
@@ -13,12 +14,14 @@ export const getLastSleepEntry = async () => {
1314 const apiKey = getApiKey ( ) ;
1415 const url = getEndpointUrl ( "api/sleep/last" , apiKey ) ;
1516
16- return await fetch ( url )
17+ const response = await fetch ( url )
1718 . then ( res => res . json ( ) )
1819 . catch ( err => console . error ( err ) ) ;
20+
21+ return response as ApiResponse < GetLastSleepRouteResponse > ;
1922} ;
2023
21- export const submitSleepEntry = async ( position ) => {
24+ export const submitSleepEntry = async ( position : GeolocationPosition ) => {
2225 const json = {
2326 coords : {
2427 latitude : position . coords . latitude ,
@@ -48,7 +51,7 @@ export const submitSleepEntry = async (position) => {
4851 . catch ( err => console . error ( err ) ) ;
4952} ;
5053
51- export const replaceLastSleepEntry = async ( position ) => {
54+ export const replaceLastSleepEntry = async ( position : GeolocationPosition ) => {
5255 const json = {
5356 coords : {
5457 latitude : position . coords . latitude ,
@@ -78,7 +81,7 @@ export const replaceLastSleepEntry = async (position) => {
7881 . catch ( err => console . error ( err ) ) ;
7982}
8083
81- const getEndpointUrl = ( endpoint , apiKey ) => {
84+ const getEndpointUrl = ( endpoint : string , apiKey ?: string ) => {
8285 const url = new URL ( endpoint , window . location . href ) ;
8386 if ( apiKey ) {
8487 url . searchParams . append ( 'apiKey' , apiKey ) ;
0 commit comments