feat: add weather widget (#286)
* feat: add nestjs replacement, remove nestjs * feat: add weather widget * fix: lock issue * fix: format issue * fix: deepsource issues * fix: change timezone to auto
This commit is contained in:
18
packages/api/src/router/location.ts
Normal file
18
packages/api/src/router/location.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import type { z } from "@homarr/validation";
|
||||
import { validation } from "@homarr/validation";
|
||||
|
||||
import { createTRPCRouter, publicProcedure } from "../trpc";
|
||||
|
||||
export const locationRouter = createTRPCRouter({
|
||||
searchCity: publicProcedure
|
||||
.input(validation.location.searchCity.input)
|
||||
.output(validation.location.searchCity.output)
|
||||
.query(async ({ input }) => {
|
||||
const res = await fetch(
|
||||
`https://geocoding-api.open-meteo.com/v1/search?name=${input.query}`,
|
||||
);
|
||||
return (await res.json()) as z.infer<
|
||||
typeof validation.location.searchCity.output
|
||||
>;
|
||||
}),
|
||||
});
|
||||
6
packages/api/src/router/widgets/index.ts
Normal file
6
packages/api/src/router/widgets/index.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { createTRPCRouter } from "../../trpc";
|
||||
import { weatherRouter } from "./weather";
|
||||
|
||||
export const widgetRouter = createTRPCRouter({
|
||||
weather: weatherRouter,
|
||||
});
|
||||
15
packages/api/src/router/widgets/weather.ts
Normal file
15
packages/api/src/router/widgets/weather.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { validation } from "@homarr/validation";
|
||||
|
||||
import { createTRPCRouter, publicProcedure } from "../../trpc";
|
||||
|
||||
export const weatherRouter = createTRPCRouter({
|
||||
atLocation: publicProcedure
|
||||
.input(validation.widget.weather.atLocationInput)
|
||||
.output(validation.widget.weather.atLocationOutput)
|
||||
.query(async ({ input }) => {
|
||||
const res = await fetch(
|
||||
`https://api.open-meteo.com/v1/forecast?latitude=${input.latitude}&longitude=${input.longitude}&daily=weathercode,temperature_2m_max,temperature_2m_min¤t_weather=true&timezone=auto`,
|
||||
);
|
||||
return res.json();
|
||||
}),
|
||||
});
|
||||
Reference in New Issue
Block a user