feat: standardize login response format with code, message, and data wrapper

Update login endpoint to return consistent API response structure with code, message, and data fields. Wrap token, refreshToken, and user data inside a data object to match the standardized response format used across other endpoints.
This commit is contained in:
JakkrapartXD 2026-01-30 17:54:43 +07:00
parent 4ff57555a2
commit d7f824f353
3 changed files with 42 additions and 30 deletions

View file

@ -28,31 +28,35 @@ export class AuthController {
@SuccessResponse('200', 'Login successful') @SuccessResponse('200', 'Login successful')
@Response('401', 'Invalid credentials') @Response('401', 'Invalid credentials')
@Example<LoginResponse>({ @Example<LoginResponse>({
token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...', code: 200,
refreshToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...', message: 'Login successful',
user: { data: {
id: 1, token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
username: 'admin', refreshToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
email: 'admin@elearning.local', user: {
updated_at: new Date('2024-01-01T00:00:00Z'), id: 1,
created_at: new Date('2024-01-01T00:00:00Z'), username: 'admin',
role: { email: 'admin@elearning.local',
code: 'ADMIN', updated_at: new Date('2024-01-01T00:00:00Z'),
name: { created_at: new Date('2024-01-01T00:00:00Z'),
th: 'ผู้ดูแลระบบ', role: {
en: 'Administrator' code: 'ADMIN',
} name: {
}, th: 'ผู้ดูแลระบบ',
profile: { en: 'Administrator'
prefix: { }
th: 'นาย',
en: 'Mr.'
}, },
first_name: 'Admin', profile: {
last_name: 'User', prefix: {
phone: null, th: 'นาย',
avatar_url: null, en: 'Mr.'
birth_date: null },
first_name: 'Admin',
last_name: 'User',
phone: null,
avatar_url: null,
birth_date: null
}
} }
} }
}) })

View file

@ -58,9 +58,13 @@ export class AuthService {
logger.info('User logged in successfully', { userId: user.id, email: user.email }); logger.info('User logged in successfully', { userId: user.id, email: user.email });
return { return {
token, code: 200,
refreshToken, message: 'Login successful',
user: await this.formatUserResponse(user) data: {
token,
refreshToken,
user: await this.formatUserResponse(user)
}
}; };
} }

View file

@ -23,9 +23,13 @@ export interface RegisterRequest {
} }
export interface LoginResponse { export interface LoginResponse {
token: string; code: number;
refreshToken: string; message: string;
user: UserResponse; data: {
token: string;
refreshToken: string;
user: UserResponse;
};
} }
export interface RegisterResponse { export interface RegisterResponse {