tercul-frontend/server/routes/userProfile.ts
google-labs-jules[bot] 1dcd8f076c
feat: Fix TypeScript errors and improve type safety (#6)
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.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
2025-11-27 18:48:47 +01:00

55 lines
1.4 KiB
TypeScript

import { Router } from "express";
import type { Request } from "express";
import { graphqlClient } from "../lib/graphqlClient";
import { respondWithError } from "../lib/error";
import {
GetUserProfileDocument,
UpdateUserProfileDocument,
type GetUserProfileQuery,
type UpdateUserProfileMutation,
} from "../../shared/generated/graphql";
interface GqlRequest extends Request {
gql?: typeof graphqlClient;
}
const router = Router();
// GET /api/userProfile/:userId
router.get("/:userId", async (req: GqlRequest, res) => {
try {
const client = req.gql || graphqlClient;
const { userProfile } = await client.request<GetUserProfileQuery>(
GetUserProfileDocument,
{
userId: req.params.userId,
}
);
if (!userProfile)
return res.status(404).json({ message: "UserProfile not found" });
res.json(userProfile);
} catch (error) {
respondWithError(res, error, "Failed to fetch user profile");
}
});
// PUT /api/userProfile/:userId
router.put("/:userId", async (req: GqlRequest, res) => {
try {
const client = req.gql || graphqlClient;
const { updateUserProfile } =
await client.request<UpdateUserProfileMutation>(
UpdateUserProfileDocument,
{
userId: req.params.userId,
input: req.body,
}
);
res.json(updateUserProfile);
} catch (error) {
respondWithError(res, error, "Failed to update user profile");
}
});
export default router;