get me api

This commit is contained in:
JakkrapartXD 2026-01-13 17:55:00 +07:00
parent 815e8aeaf0
commit d8d3dff2e7
8 changed files with 1719 additions and 575 deletions

View file

@ -35,6 +35,8 @@ export class AuthController {
id: 1,
username: 'admin',
email: 'admin@elearning.local',
updated_at: new Date('2024-01-01T00:00:00Z'),
created_at: new Date('2024-01-01T00:00:00Z'),
role: {
code: 'ADMIN',
name: {
@ -49,7 +51,9 @@ export class AuthController {
},
first_name: 'Admin',
last_name: 'User',
avatar_url: undefined
phone: null,
avatar_url: null,
birth_date: null
}
}
})
@ -79,6 +83,8 @@ export class AuthController {
id: 4,
username: 'newstudent',
email: 'student@example.com',
updated_at: new Date('2024-01-01T00:00:00Z'),
created_at: new Date('2024-01-01T00:00:00Z'),
role: {
code: 'STUDENT',
name: {
@ -92,7 +98,10 @@ export class AuthController {
en: 'Mr.'
},
first_name: 'John',
last_name: 'Doe'
last_name: 'Doe',
phone: null,
avatar_url: null,
birth_date: null
}
},
message: 'Registration successful'

View file

@ -0,0 +1,37 @@
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);
}
}