feat: restrict data to Amazon customers only (DE/FR/ES/IT/UK/SC)

This commit is contained in:
Christian Vidal Wolf
2026-01-16 10:44:43 +01:00
parent 470db20458
commit a1ad3aa944
+12 -4
View File
@@ -151,6 +151,14 @@ const getColumnValue = (row: any, aliases: string[]): string => {
}
return '';
};
// Allowed Customers Whitelist
const ALLOWED_CUSTOMERS = ['Amazon DE', 'Amazon FR', 'Amazon ES', 'Amazon IT', 'Amazon UK', 'Amazon SC'];
const isAllowedCustomer = (customer: string): boolean => {
if (!customer) return false;
const normCustomer = customer.trim().toLowerCase();
return ALLOWED_CUSTOMERS.some(allowed => allowed.toLowerCase() === normCustomer);
};
// --- SALES / SELL OUT MAPPING ---
@@ -216,8 +224,8 @@ export const processCSV = (fileOrContent: File | string): Promise<SalesRecord[]>
const data: SalesRecord[] = results.data.map((row: any, index: number) => {
return mapRowToRecord(row, index);
})
// Relaxed filtering: Only exclude rows with absolutely no year info even after backfill
.filter((r: SalesRecord) => r.year > 0);
// Filter: Valid Year AND Allowed Customer
.filter((r: SalesRecord) => r.year > 0 && isAllowedCustomer(r.customer));
resolve(data);
} catch (err) {
@@ -240,8 +248,8 @@ export const processExcel = async (file: File): Promise<SalesRecord[]> => {
const data: SalesRecord[] = jsonData.map((row: any, index: number) => {
return mapRowToRecord(row, index);
})
// Relaxed filtering
.filter((r: SalesRecord) => r.year > 0);
// Filter: Valid Year AND Allowed Customer
.filter((r: SalesRecord) => r.year > 0 && isAllowedCustomer(r.customer));
return data;
} catch (error) {