Skip to content

Commit

Permalink
fix: formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ixahmedxi committed Nov 6, 2023
1 parent ddf140b commit 4fa02bc
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions src/server/api/routers/weather.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ type RawWeatherData = {
next_12_hours: {
summary: {
symbol_code: string;
}
},
};
};
instant: {
details: {
air_temperature: number;
}
}
}
}[]
}
}
};
};
};
}[];
};
};

type WeatherData = {
temp_max: number;
Expand All @@ -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) {
Expand All @@ -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 = [];
Expand All @@ -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;
}),
});

0 comments on commit 4fa02bc

Please sign in to comment.