feat: stock price widget (#2579)
* feat: added stock price widget * fix: formatting * fix: broken lock file * fix: requested changes * fix: added parsing schema * fix: improve time range and interval inputs * fix: only return required data * fix: formatting * fix: deepsource tests * fix: moved all time frames into one location * fix: formatting * fix: requested changes * fix: formatting * fix: parse response data * fix: update packages * fix: typescript issues * fix: formatting * fix: broken lockfile --------- Co-authored-by: Meier Lukas <meierschlumpf@gmail.com>
This commit is contained in:
@@ -13,6 +13,7 @@ import { notebookRouter } from "./notebook";
|
||||
import { optionsRouter } from "./options";
|
||||
import { rssFeedRouter } from "./rssFeed";
|
||||
import { smartHomeRouter } from "./smart-home";
|
||||
import { stockPriceRouter } from "./stocks";
|
||||
import { weatherRouter } from "./weather";
|
||||
|
||||
export const widgetRouter = createTRPCRouter({
|
||||
@@ -21,6 +22,7 @@ export const widgetRouter = createTRPCRouter({
|
||||
app: appRouter,
|
||||
dnsHole: dnsHoleRouter,
|
||||
smartHome: smartHomeRouter,
|
||||
stockPrice: stockPriceRouter,
|
||||
mediaServer: mediaServerRouter,
|
||||
calendar: calendarRouter,
|
||||
downloads: downloadsRouter,
|
||||
|
||||
23
packages/api/src/router/widgets/stocks.ts
Normal file
23
packages/api/src/router/widgets/stocks.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import { fetchStockPriceHandler } from "@homarr/request-handler/stock-price";
|
||||
|
||||
import { stockPriceTimeFrames } from "../../../../widgets/src/stocks";
|
||||
import { createTRPCRouter, publicProcedure } from "../../trpc";
|
||||
|
||||
const stockPriceInputSchema = z.object({
|
||||
stock: z.string().nonempty(),
|
||||
timeRange: z.enum(stockPriceTimeFrames.range),
|
||||
timeInterval: z.enum(stockPriceTimeFrames.interval),
|
||||
});
|
||||
|
||||
export const stockPriceRouter = createTRPCRouter({
|
||||
getPriceHistory: publicProcedure.input(stockPriceInputSchema).query(async ({ input }) => {
|
||||
const innerHandler = fetchStockPriceHandler.handler({
|
||||
stock: input.stock,
|
||||
timeRange: input.timeRange,
|
||||
timeInterval: input.timeInterval,
|
||||
});
|
||||
return await innerHandler.getCachedOrUpdatedDataAsync({ forceUpdate: false });
|
||||
}),
|
||||
});
|
||||
Reference in New Issue
Block a user