diff --git a/src/auth/auth.controller.ts b/src/auth/auth.controller.ts index 5bae9ba..775932a 100644 --- a/src/auth/auth.controller.ts +++ b/src/auth/auth.controller.ts @@ -20,10 +20,14 @@ export class AuthController { throw new UnauthorizedException('Пользователь не аутентифицирован'); } - const user = req.user as { userId: number; username: string; login?: string }; - const userWithoutPassword = { ...user }; + const user = req.user as { userId: number; username: string; login?: string; role?: string }; + const userWithoutPassword = { + id: user.userId, + login: user.login || user.username, + role: user.role + }; - this.logger.log(`Аутентифицированный пользователь: ${user.username}`); + this.logger.log(`Аутентифицированный пользователь: ${user.username}, роль: ${user.role}`); return { isAuthenticated: true, user: userWithoutPassword @@ -58,7 +62,8 @@ export class AuthController { success: true, user: { id: user.id, - login: user.login + login: user.login, + role: user.role // Добавляем роль в ответ }, access_token }; diff --git a/src/auth/auth.service.ts b/src/auth/auth.service.ts index ff7ba09..e61dcd2 100644 --- a/src/auth/auth.service.ts +++ b/src/auth/auth.service.ts @@ -17,15 +17,19 @@ export class AuthService { if (user && user.password === password) { const { password, ...result } = user; - return result; + return { + ...result, + role: user.role + }; } return null; } async login(user: any) { - const payload = { - username: user.login, - sub: user.id + const payload = { + username: user.login, + sub: user.id, + role: user.role }; return { access_token: this.jwtService.sign(payload), diff --git a/src/auth/jwt.strategy.ts b/src/auth/jwt.strategy.ts index 1b2e76d..e951c2a 100644 --- a/src/auth/jwt.strategy.ts +++ b/src/auth/jwt.strategy.ts @@ -19,10 +19,11 @@ export class JwtStrategy extends PassportStrategy(Strategy) { } async validate(payload: any) { - return { - userId: payload.sub, + return { + userId: payload.sub, username: payload.username, - login: payload.username + login: payload.username, + role: payload.role }; } } \ No newline at end of file diff --git a/src/auth/user.entity.ts b/src/auth/user.entity.ts index fd88287..fdbf45a 100644 --- a/src/auth/user.entity.ts +++ b/src/auth/user.entity.ts @@ -10,4 +10,7 @@ export class User { @Column() password: string; + + @Column({ default: 'user' }) + role: 'user' | 'admin'; } diff --git a/src/prometheus.service.ts b/src/prometheus.service.ts index eb685a1..2932f56 100644 --- a/src/prometheus.service.ts +++ b/src/prometheus.service.ts @@ -224,11 +224,14 @@ export class PrometheusService { } async fetchAllMetricsWithValues(): Promise { - const metricNames = await this.fetchAllMetrics(); - const promises = metricNames.map(async (metric) => { - const data = await this.fetchMetrics(metric); - return { metric, data }; - }); - return Promise.all(promises); - } + const metricNames = await this.fetchAllMetrics(); + const zvksMetrics = metricNames.filter(metric => metric.startsWith('zvks')); + + const promises = zvksMetrics.map(async (metric) => { + const data = await this.fetchMetrics(metric); + return { metric, data }; + }); + + return Promise.all(promises); +} }