fix(tariffs): include DB-only visible tariffs missing from ezy API
Some checks are pending
CI / Type Check (push) Waiting to run
CI / Lint (push) Waiting to run
CI / Unit Tests (push) Waiting to run
Deploy / Build & Push Image (push) Waiting to run
Deploy / Deploy to VPS (push) Blocked by required conditions

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 <noreply@anthropic.com>
This commit is contained in:
Vadym Samoilenko 2026-05-13 15:32:18 +01:00
parent e4b259afdc
commit 380776fb03

View file

@ -18,6 +18,8 @@ export async function GET(): Promise<NextResponse> {
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<NextResponse> {
}
})
.filter(<T>(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')