From 4fa02bcf98ef965927f9055dc441e103d05f6259 Mon Sep 17 00:00:00 2001 From: Ahmed Elsakaan Date: Mon, 6 Nov 2023 08:25:52 +0000 Subject: [PATCH] fix: formatting --- src/server/api/routers/weather.ts | 39 +++++++++++++++++-------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/src/server/api/routers/weather.ts b/src/server/api/routers/weather.ts index d5c5c318..f261fb10 100644 --- a/src/server/api/routers/weather.ts +++ b/src/server/api/routers/weather.ts @@ -10,17 +10,17 @@ type RawWeatherData = { next_12_hours: { summary: { symbol_code: string; - } - }, + }; + }; instant: { details: { air_temperature: number; - } - } - } - }[] - } -} + }; + }; + }; + }[]; + }; +}; type WeatherData = { temp_max: number; @@ -43,9 +43,9 @@ export const weatherRouter = createTRPCRouter({ `https://api.met.no/weatherapi/locationforecast/2.0/compact?lat=${latitude}&lon=${longitude}`, { headers: { - "User-Agent": `noodle.run (https://github.com/noodle-run/noodle)` - } - } + "User-Agent": `noodle.run (https://github.com/noodle-run/noodle)`, + }, + }, ); if (!response.ok) { @@ -55,13 +55,14 @@ export const weatherRouter = createTRPCRouter({ }); } - const rawWeatherData: RawWeatherData = await response.json() as RawWeatherData; + const rawWeatherData: RawWeatherData = + (await response.json()) as RawWeatherData; if (rawWeatherData.properties.timeseries.length < 12) { throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", - message: "Partial weather data" - }) + message: "Partial weather data", + }); } const temperatures = []; @@ -71,11 +72,13 @@ export const weatherRouter = createTRPCRouter({ } const weatherData: WeatherData = { - summary: rawWeatherData.properties.timeseries[0]!.data.next_12_hours.summary.symbol_code, + summary: + rawWeatherData.properties.timeseries[0]!.data.next_12_hours.summary + .symbol_code, temp_max: Math.max(...temperatures), - temp_min: Math.min(...temperatures) - } - + temp_min: Math.min(...temperatures), + }; + return weatherData; }), });