import { Controller, Get, Post, Put, Delete, Body, Param, Res, UseGuards } from '@nestjs/common'; import { ApiTags, ApiBearerAuth } from '@nestjs/swagger'; import { Response } from 'express'; import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard'; import { UnitsService } from './units.service'; @ApiTags('units') @Controller('units') @ApiBearerAuth() @UseGuards(JwtAuthGuard) export class UnitsController { constructor(private unitsService: UnitsService) {} @Get() findAll() { return this.unitsService.findAll(); } @Get('export') async exportCSV(@Res() res: Response) { const csv = await this.unitsService.exportCSV(); res.set({ 'Content-Type': 'text/csv', 'Content-Disposition': 'attachment; filename="units.csv"' }); res.send(csv); } @Get(':id') findOne(@Param('id') id: string) { return this.unitsService.findOne(id); } @Post('import') importCSV(@Body() rows: any[]) { return this.unitsService.importCSV(rows); } @Post() create(@Body() dto: any) { return this.unitsService.create(dto); } @Put(':id') update(@Param('id') id: string, @Body() dto: any) { return this.unitsService.update(id, dto); } @Delete(':id') delete(@Param('id') id: string) { return this.unitsService.delete(id); } }