Compare commits

...

6 Commits

Author SHA1 Message Date
deployer3000 2067bb9c55 Merge pull request 'rc' (#31) from rc into main
Reviewed-on: http://git.enode/deployer3000/trust-module-backend/pulls/31
2025-07-21 13:20:38 +03:00
Vladislav Drozdov 8466aa1f93 Merge pull request 'adding filter for metrics' (#30) from swagger into rc
test-org/trust-module-backend/pipeline/pr-main Build succeeded
Reviewed-on: http://git.enode/deployer3000/trust-module-backend/pulls/30
Reviewed-by: Vladislav Drozdov <ya2@ya.ru>
2025-07-21 13:15:54 +03:00
DmitriyA ff3bf02d2e Merge branch 'swagger' of http://git.enode/deployer3000/trust-module-backend into swagger
test-org/trust-module-backend/pipeline/pr-rc This commit looks good Details
2025-07-16 10:00:28 -04:00
DmitriyA a76b0b9a86 adding roles 2025-07-16 09:49:52 -04:00
deployer3000 c3b9983b73 Merge branch 'rc' into swagger
test-org/trust-module-backend/pipeline/pr-rc This commit looks good Details
2025-07-14 10:23:24 +03:00
DmitriyA 8a5d530d44 adding filter for metrics
test-org/trust-module-backend/pipeline/pr-rc This commit looks good Details
2025-07-14 03:14:51 -04:00
5 changed files with 34 additions and 18 deletions

View File

@ -20,10 +20,14 @@ export class AuthController {
throw new UnauthorizedException('Пользователь не аутентифицирован'); throw new UnauthorizedException('Пользователь не аутентифицирован');
} }
const user = req.user as { userId: number; username: string; login?: string }; const user = req.user as { userId: number; username: string; login?: string; role?: string };
const userWithoutPassword = { ...user }; 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 { return {
isAuthenticated: true, isAuthenticated: true,
user: userWithoutPassword user: userWithoutPassword
@ -58,7 +62,8 @@ export class AuthController {
success: true, success: true,
user: { user: {
id: user.id, id: user.id,
login: user.login login: user.login,
role: user.role // Добавляем роль в ответ
}, },
access_token access_token
}; };

View File

@ -17,7 +17,10 @@ export class AuthService {
if (user && user.password === password) { if (user && user.password === password) {
const { password, ...result } = user; const { password, ...result } = user;
return result; return {
...result,
role: user.role
};
} }
return null; return null;
} }
@ -25,7 +28,8 @@ export class AuthService {
async login(user: any) { async login(user: any) {
const payload = { const payload = {
username: user.login, username: user.login,
sub: user.id sub: user.id,
role: user.role
}; };
return { return {
access_token: this.jwtService.sign(payload), access_token: this.jwtService.sign(payload),

View File

@ -22,7 +22,8 @@ export class JwtStrategy extends PassportStrategy(Strategy) {
return { return {
userId: payload.sub, userId: payload.sub,
username: payload.username, username: payload.username,
login: payload.username login: payload.username,
role: payload.role
}; };
} }
} }

View File

@ -10,4 +10,7 @@ export class User {
@Column() @Column()
password: string; password: string;
@Column({ default: 'user' })
role: 'user' | 'admin';
} }

View File

@ -224,11 +224,14 @@ export class PrometheusService {
} }
async fetchAllMetricsWithValues(): Promise<any[]> { async fetchAllMetricsWithValues(): Promise<any[]> {
const metricNames = await this.fetchAllMetrics(); const metricNames = await this.fetchAllMetrics();
const promises = metricNames.map(async (metric) => { const zvksMetrics = metricNames.filter(metric => metric.startsWith('zvks'));
const data = await this.fetchMetrics(metric);
return { metric, data }; const promises = zvksMetrics.map(async (metric) => {
}); const data = await this.fetchMetrics(metric);
return Promise.all(promises); return { metric, data };
} });
return Promise.all(promises);
}
} }