fix: price sorting by period type, pagination, avgRating on dashboard

- Sort by monthlyPrice when periodType=MONTHLY instead of always dailyPrice
- Fix client-side pagination in MyBookingsPage and LandlordListingsPage
- Compute avgRating in /rentals/mine endpoint so dashboard shows ratings
- Fix falsy filter for avgRating=0 on landlord dashboard

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
delta-lynx-89e8
2026-02-22 17:03:23 -08:00
parent dcd2dcb841
commit dc07f2a98d
4 changed files with 16 additions and 13 deletions

View File

@@ -37,10 +37,16 @@ router.get('/mine', authenticate, async (req, res, next) => {
const listings = await prisma.rentalListing.findMany({
where,
select: rentalSelect,
select: { ...rentalSelect, reviews: { select: { rating: true } } },
orderBy: { createdAt: 'desc' },
});
res.json(listings);
const withRatings = listings.map(l => ({
...l,
avgRating: l.reviews.length > 0
? l.reviews.reduce((sum, r) => sum + r.rating, 0) / l.reviews.length
: undefined,
}));
res.json(withRatings);
} catch (error) {
next(error);
}
@@ -111,8 +117,9 @@ router.get('/', optionalAuth, async (req, res, next) => {
where.dailyPrice = priceFilter;
}
const orderBy = sort === 'price_asc' ? { dailyPrice: 'asc' as const }
: sort === 'price_desc' ? { dailyPrice: 'desc' as const }
const priceField = periodType === 'MONTHLY' ? 'monthlyPrice' : 'dailyPrice';
const orderBy = sort === 'price_asc' ? { [priceField]: 'asc' as const }
: sort === 'price_desc' ? { [priceField]: 'desc' as const }
: sort === 'popular' ? { viewCount: 'desc' as const }
: { createdAt: 'desc' as const };