Spaces:
Runtime error
Runtime error
Download apps/api/src/services/expense/analytics/analytics.controller.ts from ClaraSu/llm-router: direct link, hf CLI and curl.
- Browser
- Download file 1 kB
-
https://huggingface.co/spaces/ClaraSu/llm-router/resolve/main/apps/api/src/services/expense/analytics/analytics.controller.ts
- Command line
-
hf download hf://spaces/ClaraSu/llm-router/apps/api/src/services/expense/analytics/analytics.controller.ts
-
curl -L -o analytics.controller.ts https://huggingface.co/spaces/ClaraSu/llm-router/resolve/main/apps/api/src/services/expense/analytics/analytics.controller.ts
1 kB
| import type { Request, RequestHandler } from 'express' | |
| import type { AuthenticatedRequest } from '@llm-router/auth-client' | |
| import { container } from '../loader.js' | |
| function tenantOf(req: Request): string { | |
| return (req as AuthenticatedRequest).auth!.tenantId | |
| } | |
| function monthOf(req: Request): string | undefined { | |
| const raw = req.query['month'] | |
| return typeof raw === 'string' && /^\d{4}-(0[1-9]|1[0-2])$/.test(raw) ? raw : undefined | |
| } | |
| export const getSummary: RequestHandler = async (req, res, next) => { | |
| try { | |
| res.json(await container.analyticsRepo.getSummary(tenantOf(req), monthOf(req))) | |
| } catch (err: unknown) { | |
| next(err) | |
| } | |
| } | |
| export const getTrends: RequestHandler = async (req, res, next) => { | |
| try { | |
| const raw = Number(req.query['months'] ?? 6) | |
| const months = Number.isFinite(raw) && raw > 0 ? Math.min(Math.floor(raw), 24) : 6 | |
| res.json(await container.analyticsRepo.getTrends(tenantOf(req), months, monthOf(req))) | |
| } catch (err: unknown) { | |
| next(err) | |
| } | |
| } | |