move chage password to user con

This commit is contained in:
JakkrapartXD 2026-01-14 14:06:09 +07:00
parent ff5b189b2f
commit a6cddc6318
6 changed files with 85 additions and 57 deletions

View file

@ -8,10 +8,9 @@ import {
ResetPasswordRequest,
LoginResponse,
RegisterResponse,
RefreshTokenResponse,
ChangePassword
RefreshTokenResponse
} from '../types/auth.types';
import { loginSchema, registerSchema, refreshTokenSchema, resetRequestSchema, resetPasswordSchema, changePasswordSchema } from '../validators/auth.validator';
import { loginSchema, registerSchema, refreshTokenSchema, resetRequestSchema, resetPasswordSchema } from '../validators/auth.validator';
import { ValidationError } from '../middleware/errorHandler';
@Route('api/auth')
@ -172,26 +171,4 @@ export class AuthController {
}
return await this.authService.resetPassword(body.token, body.password);
}
/**
* Change password
* @summary Change password using old password
* @param body User ID, old password and new password
* @returns Success message
*/
@Post('change-password')
@Security('jwt')
@SuccessResponse('200', 'Password changed successfully')
@Response('401', 'Invalid or expired reset token')
public async changePassword(@Request() request: any, @Body() body: ChangePassword): Promise<{ message: string }> {
const { error } = changePasswordSchema.validate(body);
if (error) {
throw new ValidationError(error.details[0].message);
}
const token = request.headers.authorization?.replace('Bearer ', '');
if (!token) {
throw new ValidationError('No token provided');
}
return await this.authService.changePassword(token, body.oldPassword, body.newPassword);
}
}