@@ -2,6 +2,7 @@ import assert from "node:assert/strict";
22import type { BunRequest } from "bun" ;
33import moment from "moment-timezone" ;
44import { successResponse } from "./apiUtils" ;
5+ import { env } from "./config" ;
56import { ApiError } from "./error" ;
67import { sendEntryNotification } from "./notifications" ;
78import {
@@ -33,16 +34,16 @@ export const logSleepRoute = async (req: BunRequest) => {
3334
3435 const result : GoogleSheetsAppendUpdates = await append (
3536 sheetsObj ,
36- process . env . SPREADSHEET_ID ! ,
37- process . env . SPREADSHEET_RANGE ! ,
37+ env . SPREADSHEET_ID ,
38+ env . SPREADSHEET_RANGE ,
3839 valuesToAppend
3940 ) . catch ( ( error ) => {
4041 throw new ApiError ( "Failed to append rows to Google Sheet" , error ) ;
4142 } ) ;
4243
4344 const updatedRows = await getObjectArrayHeader (
4445 sheetsObj ,
45- process . env . SPREADSHEET_ID ! ,
46+ env . SPREADSHEET_ID ,
4647 result . updatedRange
4748 ) . catch ( ( error ) => {
4849 throw new ApiError ( "Failed to retrieve row after writing" , error ) ;
@@ -62,8 +63,8 @@ export const getSleepRoute = async () => {
6263
6364 const result : SheetsSleepEntry [ ] = await getObjectArray (
6465 sheetsObj ,
65- process . env . SPREADSHEET_ID ! ,
66- process . env . SPREADSHEET_RANGE !
66+ env . SPREADSHEET_ID ,
67+ env . SPREADSHEET_RANGE
6768 ) . catch ( ( error : Error ) => {
6869 throw new ApiError ( "Failed to retrieve rows" , error ) ;
6970 } ) ;
@@ -78,8 +79,8 @@ export const getLastSleep = async () => {
7879
7980 const result : SheetsSleepEntry [ ] = await getObjectArray (
8081 sheetsObj ,
81- process . env . SPREADSHEET_ID ! ,
82- process . env . SPREADSHEET_RANGE !
82+ env . SPREADSHEET_ID ,
83+ env . SPREADSHEET_RANGE
8384 ) . catch ( ( error : Error ) => {
8485 throw new ApiError ( "Failed to retrieve rows" , error ) ;
8586 } ) ;
@@ -115,8 +116,8 @@ export const replaceLastSleepRoute = async (req: BunRequest) => {
115116
116117 const rows = await getArray (
117118 sheetsObj ,
118- process . env . SPREADSHEET_ID ! ,
119- process . env . SPREADSHEET_RANGE !
119+ env . SPREADSHEET_ID ,
120+ env . SPREADSHEET_RANGE
120121 ) . catch ( ( error : Error ) => {
121122 throw new ApiError ( "Failed to retrieve rows" , error ) ;
122123 } ) ;
@@ -125,7 +126,7 @@ export const replaceLastSleepRoute = async (req: BunRequest) => {
125126
126127 const result : GoogleSheetsAppendUpdates = await update (
127128 sheetsObj ,
128- process . env . SPREADSHEET_ID ! ,
129+ env . SPREADSHEET_ID ,
129130 rangeToUpdate ,
130131 valuesToAppend
131132 ) . catch ( ( error ) => {
@@ -134,7 +135,7 @@ export const replaceLastSleepRoute = async (req: BunRequest) => {
134135
135136 const updatedRows = await getObjectArrayHeader (
136137 sheetsObj ,
137- process . env . SPREADSHEET_ID ! ,
138+ env . SPREADSHEET_ID ,
138139 result . updatedRange
139140 ) . catch ( ( error ) => {
140141 throw new ApiError ( "Failed to retrieve row after updating" , error ) ;
@@ -192,7 +193,7 @@ const getSleepEntryFromGeolocationPosition = (
192193export const checkRequestApiKey = ( req : BunRequest ) => {
193194 const { searchParams } = new URL ( req . url ) ;
194195 const apiKey = searchParams . get ( "apiKey" ) ;
195- if ( apiKey != process . env . API_KEY ) {
196+ if ( apiKey != env . API_KEY ) {
196197 throw new ApiError ( "Invalid API key" ) ;
197198 }
198199} ;
0 commit comments