feat(receipt-import): add function to ignore specific receipt names and filter out ignored items

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
Nils-Johan Gynther
2026-05-03 18:18:07 +02:00
parent 6c3e391582
commit a555e74201
2 changed files with 38 additions and 1 deletions
@@ -32,6 +32,22 @@ function tokenize(value: string): string[] {
.filter((w) => w.length >= 3);
}
function isIgnoredReceiptName(value: string | null | undefined): boolean {
const normalized = (value ?? '').trim().toLowerCase();
if (!normalized) return false;
if (/^rabatt\b/.test(normalized)) return true;
if (/^summa\b/.test(normalized)) return true;
if (/^moms\b/.test(normalized)) return true;
if (/^pant\b/.test(normalized)) return true;
if (/^att\s+betala\b/.test(normalized)) return true;
if (/^totalt\b/.test(normalized)) return true;
if (/^kort\b/.test(normalized)) return true;
if (/^kontant\b/.test(normalized)) return true;
return false;
}
function normalizeToken(s: string): string {
return s.replace(/å/g, 'a').replace(/ä/g, 'a').replace(/ö/g, 'o').replace(/é/g, 'e').replace(/è/g, 'e');
}
@@ -177,7 +193,8 @@ export class ReceiptImportService {
throw new BadRequestException(message);
}
return response.json() as Promise<ParsedReceiptItem[]>;
const items = (await response.json()) as ParsedReceiptItem[];
return items.filter((item) => !isIgnoredReceiptName(item.rawName));
}
private async matchProducts(