Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions api/src/services/listing.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down