fix(dataProcessor): improve regex parsing for week number in Ads and Traffic CSV/Excel import

This commit is contained in:
Christian Vidal Wolf
2026-02-26 10:37:50 +01:00
parent 21ec5b63ab
commit fa588a6444
+6 -3
View File
@@ -460,7 +460,8 @@ export const processAdsCSV = (file: File): Promise<AdsRecord[]> => {
if (!asin || !countryRaw || weekRaw === undefined || weekRaw === '') continue;
const weekNum = parseInt(String(weekRaw));
const weekMatch = String(weekRaw).match(/\d+/);
const weekNum = weekMatch ? parseInt(weekMatch[0], 10) : NaN;
if (isNaN(weekNum) || weekNum < 1 || weekNum > 53) continue;
// For CSV without sheet names, assume current year
@@ -540,7 +541,8 @@ export const processAdsExcel = async (fileOrBuffer: File | ArrayBuffer): Promise
// Skip if missing essential data
if (!asin || !countryRaw || weekRaw === undefined || weekRaw === '') continue;
const weekNum = parseInt(String(weekRaw));
const weekMatch = String(weekRaw).match(/\d+/);
const weekNum = weekMatch ? parseInt(weekMatch[0], 10) : NaN;
if (isNaN(weekNum) || weekNum < 1 || weekNum > 53) continue;
// Log first parsed row per sheet for column match diagnosis
@@ -632,7 +634,8 @@ export const processTrafficExcel = async (fileOrBuffer: File | ArrayBuffer): Pro
if (!asin || yearRaw === undefined || weekRaw === undefined || !countryRaw) continue;
const year = typeof yearRaw === 'number' ? yearRaw : parseInt(String(yearRaw));
const weekNum = parseInt(String(weekRaw));
const weekMatch = String(weekRaw).match(/\d+/);
const weekNum = weekMatch ? parseInt(weekMatch[0], 10) : NaN;
if (isNaN(year) || year < 2020 || year > 2100) continue;
if (isNaN(weekNum) || weekNum < 1 || weekNum > 53) continue;