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 <noreply@anthropic.com>
This commit is contained in:
parent
e4b259afdc
commit
380776fb03
1 changed files with 19 additions and 2 deletions
|
|
@ -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')
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue