import { Controller, Post, UseInterceptors, UploadedFile, Get, Param, BadRequestException, } from '@nestjs/common'; import { FileInterceptor } from '@nestjs/platform-express'; import { diskStorage } from 'multer'; import { extname } from 'path'; import { CaptureService } from './capture.service'; @Controller('capture') export class CaptureController { constructor(private readonly service: CaptureService) {} @Post('upload') @UseInterceptors( FileInterceptor('file', { storage: diskStorage({ destination: './uploads', filename: (req, file, cb) => { const uniqueName = `${Date.now()}-${Math.round(Math.random() * 1e9)}${extname(file.originalname)}`; cb(null, uniqueName); }, }), }), ) async uploadFile(@UploadedFile() file: any) { if (!file) { throw new BadRequestException('No file provided'); } return this.service.processInvoice(file); } @Get() findAll() { return this.service.findAll(); } @Get(':id') findOne(@Param('id') id: string) { return this.service.findOne(Number(id)); } }