From 380776fb038ed07f120f1d25901ec5b58c896a02 Mon Sep 17 00:00:00 2001 From: Vadym Samoilenko Date: Wed, 13 May 2026 15:32:18 +0100 Subject: [PATCH] fix(tariffs): include DB-only visible tariffs missing from ezy API Dyvolis tariffs (ezy_id 2001/2002) exist in DB but ezy returns only the "Online" 3xxx-series tariffs from its activity endpoint. The merge loop silently dropped anything not in the ezy response, leaving the DyvoLis ticket section empty. Now after building the ezy-merged list, DB-visible tariffs absent from ezy are appended so every visible tariff shows up regardless of which ezy activity it belongs to. Co-Authored-By: Claude Sonnet 4.6 --- src/app/api/tickets/tariffs/route.ts | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/app/api/tickets/tariffs/route.ts b/src/app/api/tickets/tariffs/route.ts index 6eadd24..037d7bb 100644 --- a/src/app/api/tickets/tariffs/route.ts +++ b/src/app/api/tickets/tariffs/route.ts @@ -18,6 +18,8 @@ export async function GET(): Promise { overrideAccess: true, }) + const ezyIdSet = new Set(ezyTariffs.map((t) => t.id)) + const merged = ezyTariffs .map((t) => { const dbRecord = dbTariffs.find((d) => d.ezy_id === t.id) @@ -34,9 +36,24 @@ export async function GET(): Promise { } }) .filter((v: T | null): v is T => v !== null) - .sort((a, b) => a.sort - b.sort) - return NextResponse.json({ tariffs: merged }) + // Include visible DB tariffs not present in ezy (e.g. dyvolis uses a separate ezy activity) + const dbOnly = dbTariffs + .filter((d) => d.ezy_id != null && !ezyIdSet.has(d.ezy_id as number)) + .map((d) => ({ + id: d.ezy_id as number, + name: (d.display_name ?? d.last_synced_name) as string, + price: (d.last_synced_price ?? 0) as number, + categoryTag: d.category_tag as string | null, + description: d.description ?? null, + image: d.image ?? null, + icon: d.icon ?? null, + sort: (d.sort ?? 0) as number, + })) + + const all = [...merged, ...dbOnly].sort((a, b) => a.sort - b.sort) + + return NextResponse.json({ tariffs: all }) } catch (err) { logger.error({ err }, 'Failed to get tariffs from ezy — trying DB fallback')