feat: Add user role retrieval, enhance recommended course filtering and detail, and introduce new k6 load tests.
This commit is contained in:
parent
e3873f616e
commit
45b9c6516b
11 changed files with 515 additions and 139 deletions
|
|
@ -14,7 +14,8 @@ import {
|
|||
updateAvatarRequest,
|
||||
updateAvatarResponse,
|
||||
SendVerifyEmailResponse,
|
||||
VerifyEmailResponse
|
||||
VerifyEmailResponse,
|
||||
rolesResponse
|
||||
} from '../types/user.types';
|
||||
import nodemailer from 'nodemailer';
|
||||
import { UnauthorizedError, ValidationError, ForbiddenError } from '../middleware/errorHandler';
|
||||
|
|
@ -212,6 +213,30 @@ export class UserService {
|
|||
}
|
||||
}
|
||||
|
||||
async getRoles(token: string): Promise<rolesResponse> {
|
||||
try {
|
||||
jwt.verify(token, config.jwt.secret);
|
||||
const roles = await prisma.role.findMany({
|
||||
select: {
|
||||
id: true,
|
||||
code: true
|
||||
}
|
||||
});
|
||||
return { roles };
|
||||
} catch (error) {
|
||||
if (error instanceof jwt.TokenExpiredError) {
|
||||
logger.error('JWT token expired:', error);
|
||||
throw new UnauthorizedError('Token expired');
|
||||
}
|
||||
if (error instanceof jwt.JsonWebTokenError) {
|
||||
logger.error('Invalid JWT token:', error);
|
||||
throw new UnauthorizedError('Invalid token');
|
||||
}
|
||||
logger.error('Failed to get roles', { error });
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload avatar picture to MinIO
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue