feat: implement alias strategy for receipt import with user-scoped and global fallback, enhance validation and normalization, and update UI components
Test Suite / test (24.15.0) (push) Has been cancelled
Test Suite / test (24.15.0) (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
const ignoredReceiptAliasPatterns = [
|
||||
/^rabatt\b/,
|
||||
/^summa\b/,
|
||||
/^moms\b/,
|
||||
/^pant\b/,
|
||||
/^att\s+betala\b/,
|
||||
/^totalt\b/,
|
||||
/^kort\b/,
|
||||
/^kontant\b/,
|
||||
/^willys\s+plus\s*[:\-]?\b/,
|
||||
];
|
||||
|
||||
export function normalizeReceiptAliasName(value: string | null | undefined): string {
|
||||
return (value ?? '').trim().toLowerCase().replace(/\s+/g, ' ');
|
||||
}
|
||||
|
||||
export function isIgnoredReceiptAliasName(value: string | null | undefined): boolean {
|
||||
const normalized = normalizeReceiptAliasName(value);
|
||||
if (!normalized) return false;
|
||||
|
||||
return ignoredReceiptAliasPatterns.some((pattern) => pattern.test(normalized));
|
||||
}
|
||||
|
||||
export function validateReceiptAliasName(value: string | null | undefined): string | null {
|
||||
const normalized = normalizeReceiptAliasName(value);
|
||||
if (!normalized) {
|
||||
return 'Alias får inte vara tomt.';
|
||||
}
|
||||
|
||||
if (!/[a-z0-9åäö]/.test(normalized)) {
|
||||
return 'Alias måste innehålla bokstäver eller siffror.';
|
||||
}
|
||||
|
||||
if (ignoredReceiptAliasPatterns.some((pattern) => pattern.test(normalized))) {
|
||||
return 'Aliaset ser ut som en kvittorad som ska ignoreras och kan inte sparas.';
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
Reference in New Issue
Block a user