tercul-frontend/server/routes/tag.ts
google-labs-jules[bot] ea15477b86 feat: Fix TypeScript errors and improve type safety
This commit addresses 275 TypeScript compilation errors and improves type safety, code quality, and maintainability across the frontend codebase.

The following issues have been resolved:
- Standardized `translationId` to `number`
- Fixed missing properties on annotation types
- Resolved `tags` type mismatch
- Corrected `country` type mismatch
- Addressed date vs. string mismatches
- Fixed variable hoisting issues
- Improved server-side type safety
- Added missing null/undefined checks
- Fixed arithmetic operations on non-numbers
- Resolved `RefObject` type issues

Note: I was unable to verify the frontend changes due to local setup issues with the development server. The server would not start, and I was unable to run the Playwright tests.
2025-11-27 17:48:31 +00:00

47 lines
1.3 KiB
TypeScript

import { Router } from "express";
import type { Request } from "express";
import { graphqlClient } from "../lib/graphqlClient";
import { respondWithError } from "../lib/error";
import {
GetTagDocument,
TagsDocument,
type GetTagQuery,
type TagsQuery,
} from "../../shared/generated/graphql";
interface GqlRequest extends Request {
gql?: typeof graphqlClient;
}
const router = Router();
// GET /api/tags
router.get("/", async (req: GqlRequest, res) => {
try {
const variables = {
limit: req.query.limit ? Number(req.query.limit) : undefined,
offset: req.query.offset ? Number(req.query.offset) : undefined,
};
const client = req.gql || graphqlClient;
const { tags } = await client.request<TagsQuery>(TagsDocument, variables);
res.json(tags);
} catch (error) {
respondWithError(res, error, "Failed to fetch tags");
}
});
// GET /api/tags/:id
router.get("/:id", async (req: GqlRequest, res) => {
try {
const client = req.gql || graphqlClient;
const { tag } = await client.request<GetTagQuery>(GetTagDocument, {
id: req.params.id,
});
if (!tag) return res.status(404).json({ message: "Tag not found" });
res.json(tag);
} catch (error) {
respondWithError(res, error, "Failed to fetch tag");
}
});
export default router;