48 lines
1.6 KiB
TypeScript
48 lines
1.6 KiB
TypeScript
import { Controller, Get, Post, Body, HttpException, HttpStatus, Param } from '@nestjs/common';
|
|
import { FormulaService } from './formula.service';
|
|
import { MenuService } from './menu.service';
|
|
|
|
@Controller('formula')
|
|
export class FormulaController {
|
|
constructor(
|
|
private readonly FormulaService: FormulaService,
|
|
private readonly menuService: MenuService
|
|
) { }
|
|
|
|
@Get(':id')
|
|
async getFormulaData(@Param('id') id: string) {
|
|
try {
|
|
return await this.FormulaService.getFormulaData(id);
|
|
} catch (error) {
|
|
throw new HttpException('Failed to fetch Formula data', HttpStatus.INTERNAL_SERVER_ERROR);
|
|
}
|
|
}
|
|
|
|
@Post(':id/update')
|
|
async updateFormulaData(
|
|
@Param('id') id: string,
|
|
@Body() data: any
|
|
) {
|
|
if (!data) {
|
|
throw new HttpException('Invalid data format', HttpStatus.BAD_REQUEST);
|
|
}
|
|
|
|
try {
|
|
const result = await this.FormulaService.updateFormulaData(id, data);
|
|
this.menuService.invalidateCache();
|
|
return result;
|
|
} catch (error) {
|
|
throw new HttpException(error.message, HttpStatus.INTERNAL_SERVER_ERROR);
|
|
}
|
|
}
|
|
|
|
// OPTIONS метод для получения данных (как в вашем примере curl)
|
|
@Get(':id/options')
|
|
async getFormulaOptions(@Param('id') id: string) {
|
|
try {
|
|
return await this.FormulaService.getFormulaOptions(id);
|
|
} catch (error) {
|
|
throw new HttpException('Failed to fetch Formula options', HttpStatus.INTERNAL_SERVER_ERROR);
|
|
}
|
|
}
|
|
} |