38 lines
1.3 KiB
TypeScript
38 lines
1.3 KiB
TypeScript
|
|
import { Get, Body, Post, Route, Tags, SuccessResponse, Response, Example, Controller, Security, Request } from 'tsoa';
|
||
|
|
import { UserService } from '../services/user.service';
|
||
|
|
import {
|
||
|
|
UserResponse,
|
||
|
|
ProfileResponse,
|
||
|
|
ProfileUpdate,
|
||
|
|
ProfileUpdateResponse,
|
||
|
|
ChangePasswordRequest,
|
||
|
|
ChangePasswordResponse
|
||
|
|
} from '../types/user.types';
|
||
|
|
import { profileUpdateSchema, changePasswordSchema } from "../validators/user.validator";
|
||
|
|
import { ValidationError } from '../middleware/errorHandler';
|
||
|
|
|
||
|
|
@Route('api/user')
|
||
|
|
@Tags('Usermanagement')
|
||
|
|
export class UserController {
|
||
|
|
private userService = new UserService();
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get current user profile
|
||
|
|
* @summary Retrieve authenticated user's profile information
|
||
|
|
* @param request Express request object with JWT token in Authorization header
|
||
|
|
*/
|
||
|
|
@Get('me')
|
||
|
|
@SuccessResponse('200', 'User found')
|
||
|
|
@Response('404', 'User not found')
|
||
|
|
@Response('401', 'Invalid or expired token')
|
||
|
|
@Security('jwt')
|
||
|
|
public async getMe(@Request() request: any): Promise<UserResponse> {
|
||
|
|
// Extract token from Authorization header
|
||
|
|
const token = request.headers.authorization?.replace('Bearer ', '');
|
||
|
|
if (!token) {
|
||
|
|
throw new ValidationError('No token provided');
|
||
|
|
}
|
||
|
|
return await this.userService.getUserProfile(token);
|
||
|
|
}
|
||
|
|
}
|