getting to payment screen. Bug fixes and formatting changes for item detail

This commit is contained in:
jackiettran
2025-08-21 16:44:05 -04:00
parent b624841350
commit 022c0b9c06
10 changed files with 859 additions and 815 deletions

View File

@@ -9,7 +9,6 @@ router.get("/", async (req, res) => {
const {
minPrice,
maxPrice,
location,
city,
zipCode,
search,
@@ -24,7 +23,6 @@ router.get("/", async (req, res) => {
if (minPrice) where.pricePerDay[Op.gte] = minPrice;
if (maxPrice) where.pricePerDay[Op.lte] = maxPrice;
}
if (location) where.location = { [Op.iLike]: `%${location}%` };
if (city) where.city = { [Op.iLike]: `%${city}%` };
if (zipCode) where.zipCode = { [Op.iLike]: `%${zipCode}%` };
if (search) {
@@ -83,6 +81,42 @@ router.get("/recommendations", authenticateToken, async (req, res) => {
}
});
// Public endpoint to get reviews for a specific item (must come before /:id route)
router.get('/:id/reviews', async (req, res) => {
try {
const { Rental, User } = require('../models');
const reviews = await Rental.findAll({
where: {
itemId: req.params.id,
status: 'completed',
rating: { [Op.not]: null },
review: { [Op.not]: null }
},
include: [
{
model: User,
as: 'renter',
attributes: ['id', 'firstName', 'lastName']
}
],
order: [['createdAt', 'DESC']]
});
const averageRating = reviews.length > 0
? reviews.reduce((sum, review) => sum + review.rating, 0) / reviews.length
: 0;
res.json({
reviews,
averageRating,
totalReviews: reviews.length
});
} catch (error) {
res.status(500).json({ error: error.message });
}
});
router.get("/:id", async (req, res) => {
try {
const item = await Item.findByPk(req.params.id, {