added ranges editor
test-org/trust-module-backend/pipeline/pr-rc This commit looks good
Details
test-org/trust-module-backend/pipeline/pr-rc This commit looks good
Details
parent
dadb6f3bcb
commit
4074d45384
|
|
@ -1,7 +1,6 @@
|
|||
import { Controller, Get, Post, Put, Body, Param, Headers, HttpException, HttpStatus } from '@nestjs/common';
|
||||
import { MenuService } from './menu.service';
|
||||
import { MenuItem } from './menu.interface';
|
||||
import { Response } from 'express';
|
||||
|
||||
@Controller('menu')
|
||||
export class MenuController {
|
||||
|
|
|
|||
|
|
@ -4,10 +4,11 @@ import { HttpModule } from '@nestjs/axios';
|
|||
import { MenuService } from './menu.service';
|
||||
import { PrometheusModule } from '../prometheus.module';
|
||||
import { RangeService } from './range.service';
|
||||
import { RangeController } from './range.controller';
|
||||
|
||||
@Module({
|
||||
imports: [PrometheusModule, HttpModule],
|
||||
controllers: [MenuController],
|
||||
controllers: [MenuController, RangeController],
|
||||
providers: [MenuService, RangeService]
|
||||
})
|
||||
export class MenuModule { }
|
||||
|
|
@ -289,17 +289,22 @@ export class MenuService {
|
|||
if (!item) throw new Error('Menu item not found');
|
||||
Object.assign(item, update);
|
||||
|
||||
// Инвалидируем кэш после изменения
|
||||
|
||||
this.menuCache = null;
|
||||
return item;
|
||||
}
|
||||
|
||||
async saveOverrides(overrides: Partial<MenuItem>[]): Promise<void> {
|
||||
await fs.writeFile(this.menuOverridesPath, JSON.stringify({ overrides }, null, 2), 'utf-8');
|
||||
// Инвалидируем кэш после изменения оверрайдов
|
||||
|
||||
this.menuCache = null;
|
||||
}
|
||||
|
||||
invalidateCache(): void {
|
||||
this.menuCache = null;
|
||||
this.lastModified = new Date();
|
||||
}
|
||||
|
||||
private findMenuItem(menu: MenuItem, id: string): MenuItem | null {
|
||||
if (menu.id === id) return menu;
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,37 @@
|
|||
import { Controller, Post, Get, Body, HttpException, HttpStatus } from '@nestjs/common';
|
||||
import { RangeService } from './range.service';
|
||||
import { MenuService } from './menu.service';
|
||||
|
||||
@Controller('ranges')
|
||||
export class RangeController {
|
||||
constructor(
|
||||
private readonly rangeService: RangeService,
|
||||
private readonly menuService: MenuService
|
||||
) { }
|
||||
|
||||
@Get('list')
|
||||
async getRanges() {
|
||||
try {
|
||||
return await this.rangeService.getRanges();
|
||||
} catch (error) {
|
||||
throw new HttpException('Failed to fetch ranges', HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Post('update')
|
||||
async updateRanges(
|
||||
@Body() data: Array<{ name: string; ranges: { min: number; max: number; status: number }[] }>
|
||||
) {
|
||||
if (!Array.isArray(data)) {
|
||||
throw new HttpException('Invalid data format', HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await this.rangeService.updateRanges(data);
|
||||
this.menuService.invalidateCache();
|
||||
return result;
|
||||
} catch (error) {
|
||||
throw new HttpException(error.message, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -51,4 +51,20 @@ export class RangeService {
|
|||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
async updateRanges(data: Array<{ name: string; ranges: { min: number; max: number; status: number }[] }>) {
|
||||
try {
|
||||
const response = await firstValueFrom(
|
||||
this.httpService.post('http://192.168.2.39:9999/api/ranges/9999', data, {
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
})
|
||||
);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.error('Failed to update ranges:', error);
|
||||
throw new Error('Failed to update ranges');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue