feat: add receipt import functionality with UI and backend integration
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import {
|
||||
Controller,
|
||||
Post,
|
||||
UploadedFile,
|
||||
UseInterceptors,
|
||||
BadRequestException,
|
||||
} from '@nestjs/common';
|
||||
import { FileInterceptor } from '@nestjs/platform-express';
|
||||
import { memoryStorage } from 'multer';
|
||||
import { ReceiptImportService } from './receipt-import.service';
|
||||
import { ParsedReceiptItem } from './dto/parsed-receipt-item.dto';
|
||||
|
||||
const ALLOWED_MIMES = [
|
||||
'image/jpeg',
|
||||
'image/png',
|
||||
'image/webp',
|
||||
'image/heic',
|
||||
'image/heif',
|
||||
];
|
||||
|
||||
@Controller('receipt-import')
|
||||
export class ReceiptImportController {
|
||||
constructor(private readonly receiptImportService: ReceiptImportService) {}
|
||||
|
||||
@Post()
|
||||
@UseInterceptors(
|
||||
FileInterceptor('file', {
|
||||
storage: memoryStorage(),
|
||||
limits: { fileSize: 15 * 1024 * 1024 }, // 15 MB
|
||||
}),
|
||||
)
|
||||
async parseReceipt(
|
||||
@UploadedFile() file?: Express.Multer.File,
|
||||
): Promise<ParsedReceiptItem[]> {
|
||||
if (!file?.buffer) {
|
||||
throw new BadRequestException('Ingen fil skickades med.');
|
||||
}
|
||||
if (!ALLOWED_MIMES.includes(file.mimetype)) {
|
||||
throw new BadRequestException(
|
||||
'Otillåten filtyp. Använd JPEG, PNG eller WebP.',
|
||||
);
|
||||
}
|
||||
return this.receiptImportService.parseReceipt(file);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user