feat: add receipt import functionality with UI and backend integration

This commit is contained in:
Nils-Johan Gynther
2026-04-16 20:02:57 +02:00
parent 88d3c4ad73
commit a12abe0402
10 changed files with 513 additions and 0 deletions
@@ -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);
}
}