tercul-frontend/server/routes/tag.ts
Damir Mukimov 4a23f496fa
Major frontend development updates
- Enhanced annotation system with improved inline editing
- Updated author components with new card and header designs
- Improved reading view with enhanced line numbering and controls
- Added new blog management features and tag management
- Updated UI components with improved accessibility and styling
- Enhanced search functionality with better filtering
- Added new dashboard features and activity feeds
- Improved translation selector and work comparison tools
- Updated GraphQL integration and API hooks
- Enhanced responsive design and mobile experience
2025-11-27 03:44:09 +01:00

42 lines
1.2 KiB
TypeScript

import { Router } from "express";
import type { Request } from "express";
import { graphqlClient } from "../lib/graphqlClient";
import { respondWithError } from "../lib/error";
import { GetTagDocument, TagsDocument } 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(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(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;