tercul-frontend/server/routes/user.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

70 lines
1.8 KiB
TypeScript

import { Router } from "express";
import type { Request } from "express";
import { graphqlClient } from "../lib/graphqlClient";
import { respondWithError } from "../lib/error";
import {
GetUserDocument,
UsersDocument,
UpdateUserDocument,
DeleteUserDocument,
} from "../../shared/generated/graphql";
const router = Router();
// GET /api/users/:id
interface GqlRequest extends Request {
gql?: typeof graphqlClient;
}
router.get("/:id", async (req: GqlRequest, res) => {
try {
const client = req.gql || graphqlClient;
const { user } = await client.request(GetUserDocument, {
id: req.params.id,
});
res.json(user);
} catch (error) {
respondWithError(res, error, "Failed to fetch user");
}
});
// GET /api/users
router.get("/", async (req: GqlRequest, res) => {
try {
const client = req.gql || graphqlClient;
const { users } = await client.request(UsersDocument, { ...req.query });
res.json(users);
} catch (error) {
respondWithError(res, error, "Failed to fetch users");
}
});
// PUT /api/users/:id
router.put("/:id", async (req: GqlRequest, res) => {
try {
const client = req.gql || graphqlClient;
const { updateUser } = await client.request(UpdateUserDocument, {
id: req.params.id,
input: req.body,
});
res.json(updateUser);
} catch (error) {
respondWithError(res, error, "Failed to update user");
}
});
// DELETE /api/users/:id
router.delete("/:id", async (req: GqlRequest, res) => {
try {
const client = req.gql || graphqlClient;
const { deleteUser } = await client.request(DeleteUserDocument, {
id: req.params.id,
});
res.json({ success: deleteUser });
} catch (error) {
respondWithError(res, error, "Failed to delete user");
}
});
export default router;