feat: odebírání položek objednávky ve sloupci Z nabídky
CI / Generate TypeScript types (push) Successful in 10s
CI / Server unit tests (push) Successful in 26s
CI / Build server (push) Successful in 58s
CI / Build client (push) Successful in 1m4s
CI / Playwright E2E tests (push) Successful in 1m47s
CI / Build and push Docker image (push) Successful in 45s
CI / Notify (push) Successful in 2s
CI / Generate TypeScript types (push) Successful in 10s
CI / Server unit tests (push) Successful in 26s
CI / Build server (push) Successful in 58s
CI / Build client (push) Successful in 1m4s
CI / Playwright E2E tests (push) Successful in 1m47s
CI / Build and push Docker image (push) Successful in 45s
CI / Notify (push) Successful in 2s
This commit is contained in:
@@ -73,3 +73,30 @@ export function countNoteItems(note: string | undefined): number {
|
||||
return note.split('+').map(p => p.trim()).filter(Boolean)
|
||||
.reduce((sum, part) => sum + parseQuantity(part).quantity, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Části poznámky oddělené „+" (tak, jak je uživatel zapsal). Pokud celá poznámka
|
||||
* odpovídá jednomu jídlu z nabídky (název může obsahovat „+"), je to jediná položka.
|
||||
*/
|
||||
export function splitNoteItems(note: string | undefined, menu: StoreMenuDish[] = []): string[] {
|
||||
const trimmed = (note ?? '').trim();
|
||||
if (trimmed && menu.some(d => normalizeDishName(d.name) === normalizeDishName(trimmed))) return [trimmed];
|
||||
return trimmed.split('+').map(p => p.trim()).filter(Boolean);
|
||||
}
|
||||
|
||||
/**
|
||||
* Odebere z poznámky jeden kus položky na daném indexu: „2x Hranolky" → „Hranolky",
|
||||
* jinak celou část. Vrátí novou poznámku a cenu odebraného kusu dle nabídky (Kč), je-li známa.
|
||||
*/
|
||||
export function removeNoteItem(note: string | undefined, index: number, menu: StoreMenuDish[]): { note: string, removedPrice?: number } {
|
||||
const parts = splitNoteItems(note, menu);
|
||||
const part = parts[index];
|
||||
if (part == null) return { note: note ?? '' };
|
||||
const { quantity, rest } = parseQuantity(part);
|
||||
const dishes = menu.map(dish => ({ dish, norm: normalizeDishName(dish.name) }));
|
||||
const dish = dishes.find(d => d.norm === normalizeDishName(part))?.dish ?? findDish(rest, dishes);
|
||||
if (quantity > 2) parts[index] = `${quantity - 1}x ${rest.trim()}`;
|
||||
else if (quantity === 2) parts[index] = rest.trim();
|
||||
else parts.splice(index, 1);
|
||||
return { note: parts.join(' + '), removedPrice: dish?.price };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user