1- import type { ApiResponse , GetLastSleepRouteResponse } from ' ../../types.js' ;
2- import { getApiKey } from ' ./params.js'
1+ import type { ApiResponse , GetLastSleepRouteResponse } from " ../../types.js" ;
2+ import { getApiKey } from " ./params.js" ;
33
44export const getSleepEntries = async ( ) => {
55 const apiKey = getApiKey ( ) ;
66 const url = getEndpointUrl ( "api/sleep" , apiKey ) ;
77
88 return await fetch ( url )
9- . then ( res => res . json ( ) )
10- . catch ( err => console . error ( err ) ) ;
9+ . then ( ( res ) => res . json ( ) )
10+ . catch ( ( err ) => console . error ( err ) ) ;
1111} ;
1212
1313export const getLastSleepEntry = async ( ) => {
1414 const apiKey = getApiKey ( ) ;
1515 const url = getEndpointUrl ( "api/sleep/last" , apiKey ) ;
1616
1717 const response = await fetch ( url )
18- . then ( res => res . json ( ) )
19- . catch ( err => console . error ( err ) ) ;
18+ . then ( ( res ) => res . json ( ) )
19+ . catch ( ( err ) => console . error ( err ) ) ;
2020
2121 return response as ApiResponse < GetLastSleepRouteResponse > ;
2222} ;
@@ -30,25 +30,25 @@ export const submitSleepEntry = async (position: GeolocationPosition) => {
3030 accuracy : position . coords . accuracy ,
3131 altitudeAccuracy : position . coords . altitudeAccuracy ,
3232 heading : position . coords . heading ,
33- speed : position . coords . speed
33+ speed : position . coords . speed ,
3434 } ,
3535 timestamp : position . timestamp ,
3636 } ;
3737
3838 const options = {
39- method : ' POST' ,
39+ method : " POST" ,
4040 body : JSON . stringify ( json ) ,
4141 headers : {
42- ' Content-Type' : ' application/json' ,
42+ " Content-Type" : " application/json" ,
4343 } ,
4444 } ;
4545
4646 const apiKey = getApiKey ( ) ;
4747 const url = getEndpointUrl ( "api/sleep" , apiKey ) ;
4848
4949 return await fetch ( url , options )
50- . then ( res => res . json ( ) )
51- . catch ( err => console . error ( err ) ) ;
50+ . then ( ( res ) => res . json ( ) )
51+ . catch ( ( err ) => console . error ( err ) ) ;
5252} ;
5353
5454export const replaceLastSleepEntry = async ( position : GeolocationPosition ) => {
@@ -60,31 +60,31 @@ export const replaceLastSleepEntry = async (position: GeolocationPosition) => {
6060 accuracy : position . coords . accuracy ,
6161 altitudeAccuracy : position . coords . altitudeAccuracy ,
6262 heading : position . coords . heading ,
63- speed : position . coords . speed
63+ speed : position . coords . speed ,
6464 } ,
6565 timestamp : position . timestamp ,
6666 } ;
6767
6868 const options = {
69- method : ' PUT' ,
69+ method : " PUT" ,
7070 body : JSON . stringify ( json ) ,
7171 headers : {
72- ' Content-Type' : ' application/json' ,
72+ " Content-Type" : " application/json" ,
7373 } ,
7474 } ;
7575
7676 const apiKey = getApiKey ( ) ;
7777 const url = getEndpointUrl ( "api/sleep/replace" , apiKey ) ;
7878
7979 return await fetch ( url , options )
80- . then ( res => res . json ( ) )
81- . catch ( err => console . error ( err ) ) ;
82- }
80+ . then ( ( res ) => res . json ( ) )
81+ . catch ( ( err ) => console . error ( err ) ) ;
82+ } ;
8383
8484const getEndpointUrl = ( endpoint : string , apiKey ?: string ) => {
8585 const url = new URL ( endpoint , window . location . href ) ;
8686 if ( apiKey ) {
87- url . searchParams . append ( ' apiKey' , apiKey ) ;
87+ url . searchParams . append ( " apiKey" , apiKey ) ;
8888 }
8989 return url ;
90- }
90+ } ;
0 commit comments