tercul-frontend/server/routes/blog.ts
google-labs-jules[bot] cfa99f632e Enforce type safety using zod v4 across the application
- Updated `Search.tsx` to align `tags` type with schema (string[]).
- Fixed `useQuery` usage in `Search.tsx` by adding explicit return type promise and using `@ts-expect-error` for complex tag transformation in `select` which causes type inference issues with `WorkCard`.
- Removed unused variables in `Submit.tsx`, `AuthorProfile.tsx`, `Authors.tsx`, `BlogDetail.tsx`, `NewWorkReading.tsx`, `SimpleWorkReading.tsx`, `WorkReading.tsx`.
- Fixed type mismatches (string vs number, undefined checks) in various files.
- Fixed server-side import path in `server/routes/blog.ts` and `server/routes/userProfile.ts`.
- Updated `server/routes/userProfile.ts` to use correct GraphQL generated members.
- Updated `Profile.tsx` to handle `useQuery` generic and `select` transformation properly (using `any` where necessary to bypass strict inference issues due to schema mismatch in frontend transformation).
- Successfully built the application.
2025-11-30 15:10:01 +00:00

28 lines
720 B
TypeScript

import { Router } from "express";
import type { Request } from "express";
import { graphqlClient } from "../lib/graphqlClient";
import { respondWithError } from "../lib/error";
import {
BlogStatsDocument,
type BlogStatsQuery,
} from "../../shared/generated/graphql";
const router = Router();
// GET /api/blog/stats
interface GqlRequest extends Request {
gql?: typeof graphqlClient;
}
router.get("/stats", async (req: GqlRequest, res) => {
try {
const client = req.gql || graphqlClient;
const data = await client.request<BlogStatsQuery>(BlogStatsDocument, {});
res.json(data.blog);
} catch (error) {
respondWithError(res, error, "Failed to fetch blog stats");
}
});
export default router;