Files
classroomio/apps/api/src/routes/account/account.ts
T
Rotimi Best 4b52906445 feat: enhance API route naming conventions and structure
- Added comprehensive guidelines for API route naming and structure in `ROUTE_NAMING_BEST_PRACTICES.md`.
- Updated `ARCHITECHTURE.md` to reference the new best practices document.
- Refactored course-related routes to follow new naming conventions, including changes to endpoint paths and validation schemas.
- Removed the deprecated course clone route and integrated cloning functionality directly into the course routes.
- Adjusted various API methods to ensure consistent usage of HTTP methods and parameter structures across the application.
2025-12-05 17:24:16 +01:00

50 lines
1.3 KiB
TypeScript

import { getAccountData, updateUser } from '@api/services/account';
import { Hono } from '@api/utils/hono';
import { ZUpdateProfile } from '@cio/utils/validation/account';
import { authMiddleware } from '@api/middlewares/auth';
import { handleError } from '@api/utils/errors';
import { zValidator } from '@hono/zod-validator';
export const accountRouter = new Hono()
.get('/', authMiddleware, async (c) => {
const user = c.get('user');
try {
console.time('accountRouter');
const accountData = await getAccountData(user.id);
console.timeEnd('accountRouter');
return c.json(
{
success: true,
user,
profile: accountData.profile,
organizations: accountData.organizations
},
200
);
} catch (error) {
return handleError(c, error, 'Failed to fetch account data');
}
})
.put('/profile', authMiddleware, zValidator('json', ZUpdateProfile), async (c) => {
const user = c.get('user');
try {
const validatedData = c.req.valid('json');
const updatedProfile = await updateUser(user.id, validatedData);
return c.json(
{
success: true,
profile: updatedProfile
},
200
);
} catch (error) {
return handleError(c, error, 'Failed to update profile');
}
});