mirror of
https://github.com/SamyRai/tercul-frontend.git
synced 2025-12-27 03:41:34 +00:00
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.
82 lines
2.0 KiB
TypeScript
82 lines
2.0 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,
|
|
type GetUserQuery,
|
|
type UsersQuery,
|
|
type UpdateUserMutation,
|
|
type DeleteUserMutation,
|
|
} 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<GetUserQuery>(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<UsersQuery>(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<UpdateUserMutation>(
|
|
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<DeleteUserMutation>(
|
|
DeleteUserDocument,
|
|
{
|
|
id: req.params.id,
|
|
}
|
|
);
|
|
res.json({ success: deleteUser });
|
|
} catch (error) {
|
|
respondWithError(res, error, "Failed to delete user");
|
|
}
|
|
});
|
|
|
|
export default router;
|