From 553e1ee7c8b38ea963098a985b6f112e0c3512b1 Mon Sep 17 00:00:00 2001 From: Charlie Tonneslan Date: Sun, 17 May 2026 15:01:15 -0400 Subject: [PATCH] listing: skip amiChart findMany when no units carry an AMI chart When addUnitsSummarized runs against a listing pulled with a view that doesn't select amiChart, every unit.amiChart?.id is undefined, so unitsWithCharts ends up empty and we issue prisma.amiChart.findMany with an 'in: []' filter. That's enough to trip up downstream callers that expected the base path to not hit the AMI chart table at all, which is what was happening on account/application/[id]. Short-circuit the findMany when unitsWithCharts is empty. Closes #5684. Signed-off-by: Charlie Tonneslan --- api/src/services/listing.service.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/api/src/services/listing.service.ts b/api/src/services/listing.service.ts index e841c88afa2..034c8acd85e 100644 --- a/api/src/services/listing.service.ts +++ b/api/src/services/listing.service.ts @@ -2963,13 +2963,18 @@ export class ListingService implements OnModuleInit { addUnitsSummarized = async (listing: Listing) => { if (Array.isArray(listing.units) && listing.units.length > 0) { const unitsWithCharts = listing.units.filter((unit) => unit.amiChart?.id); - const amiChartsRaw = await this.prisma.amiChart.findMany({ - where: { - id: { - in: unitsWithCharts.map((unit) => unit.amiChart?.id), - }, - }, - }); + // Skip the findMany when none of the units carry an amiChart (e.g. + // when called from a view that doesn't select amiChart). Otherwise + // we'd run an `in: []` query that downstream views weren't expecting. + const amiChartsRaw = unitsWithCharts.length + ? await this.prisma.amiChart.findMany({ + where: { + id: { + in: unitsWithCharts.map((unit) => unit.amiChart?.id), + }, + }, + }) + : []; const amiCharts = mapTo(AmiChart, amiChartsRaw); listing.unitsSummarized = summarizeUnits(listing, amiCharts); }