feat: detekce starého menu TechTower, příznak isStale
Pokud TechTower vrátí menu z jiného týdne, uloží data s příznakem isStale a zobrazí varování "Data jsou z minulého týdne" místo chybové hlášky. Odstraněno staré varování o datech starších 24 hodin.
This commit is contained in:
@@ -4,6 +4,10 @@ import { getMenuSladovnickaMock, getMenuTechTowerMock, getMenuUMotlikuMock, getM
|
||||
import { formatDate } from "./utils";
|
||||
import { Food } from "../../types/gen/types.gen";
|
||||
|
||||
export class StaleWeekError extends Error {
|
||||
constructor(public food: Food[][]) { super('Data jsou z jiného týdne'); }
|
||||
}
|
||||
|
||||
// Fráze v názvech jídel, které naznačují že se jedná o polévku
|
||||
const SOUP_NAMES = [
|
||||
'polévka',
|
||||
@@ -299,7 +303,6 @@ export const getMenuTechTower = async (firstDayOfWeek: Date, mock: boolean = fal
|
||||
}
|
||||
|
||||
const result: Food[][] = [];
|
||||
// TODO validovat, že v textu nalezeného <font> je rozsah, do kterého spadá vstupní datum
|
||||
const siblings = secondTry ? $(font).parent().parent().parent().siblings('p') : $(font).parent().parent().siblings();
|
||||
let parsing = false;
|
||||
let currentDayIndex = 0;
|
||||
@@ -345,6 +348,18 @@ export const getMenuTechTower = async (firstDayOfWeek: Date, mock: boolean = fal
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Validace, zda text hlavičky obsahuje datum odpovídající požadovanému týdnu
|
||||
const headerText = $(font).text().trim();
|
||||
const dateMatch = headerText.match(/(\d{1,2})\.(\d{1,2})\./);
|
||||
if (dateMatch) {
|
||||
const foundDay = parseInt(dateMatch[1]);
|
||||
const foundMonth = parseInt(dateMatch[2]) - 1; // JS months are 0-based
|
||||
if (foundDay !== firstDayOfWeek.getDate() || foundMonth !== firstDayOfWeek.getMonth()) {
|
||||
throw new StaleWeekError(result);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user