fixed ports

This commit is contained in:
2ManyProjects 2025-04-25 11:15:53 -05:00
parent 37f7cc23b7
commit 0234426529
4 changed files with 102 additions and 23 deletions

2
.gitignore vendored
View file

@ -3,4 +3,4 @@ node_modules
npm-debug.log npm-debug.log
yarn-error.log yarn-error.log
.DS_Store .DS_Store
uploads/* public/uploads/*

View file

@ -36,25 +36,51 @@ module.exports = (pool, query, authMiddleware) => {
const cartItemsResult = await query( const cartItemsResult = await query(
`SELECT ci.id, ci.quantity, ci.added_at, `SELECT ci.id, ci.quantity, ci.added_at,
p.id AS product_id, p.name, p.description, p.price, p.id AS product_id, p.name, p.description, p.price,
p.category_id, pc.name AS category_name p.category_id, pc.name AS category_name,
(
SELECT json_agg(
json_build_object(
'id', pi.id,
'path', pi.image_path,
'isPrimary', pi.is_primary,
'displayOrder', pi.display_order
) ORDER BY pi.display_order
)
FROM product_images pi
WHERE pi.product_id = p.id
) AS images
FROM cart_items ci FROM cart_items ci
JOIN products p ON ci.product_id = p.id JOIN products p ON ci.product_id = p.id
JOIN product_categories pc ON p.category_id = pc.id JOIN product_categories pc ON p.category_id = pc.id
WHERE ci.cart_id = $1`, WHERE ci.cart_id = $1
GROUP BY ci.id, ci.quantity, ci.added_at, p.id, p.name, p.description, p.price, p.category_id, pc.name`,
[cartId] [cartId]
); );
// Calculate total // Process images to add primary_image field
const total = cartItemsResult.rows.reduce((sum, item) => { const processedItems = cartItemsResult.rows.map(item => {
// Add primary_image field derived from images array
let primaryImage = null;
if (item.images && item.images.length > 0) {
primaryImage = item.images.find(img => img.isPrimary === true) || item.images[0];
}
return {
...item,
primary_image: primaryImage
};
});
// Calculate total
const total = processedItems.reduce((sum, item) => {
return sum + (parseFloat(item.price) * item.quantity); return sum + (parseFloat(item.price) * item.quantity);
}, 0); }, 0);
res.json({ res.json({
id: cartId, id: cartId,
userId, userId,
items: cartItemsResult.rows, items: processedItems,
itemCount: cartItemsResult.rows.length, itemCount: processedItems.length,
total total
}); });
} catch (error) { } catch (error) {
@ -69,7 +95,7 @@ module.exports = (pool, query, authMiddleware) => {
if (req.user.id !== userId) { if (req.user.id !== userId) {
return res.status(403).json({ return res.status(403).json({
error: true, error: true,
message: 'You can only modify your own cart' + req.user.id + " "+ userId message: 'You can only modify your own cart'
}); });
} }
// Check if product exists // Check if product exists
@ -126,24 +152,51 @@ module.exports = (pool, query, authMiddleware) => {
const updatedCartItems = await query( const updatedCartItems = await query(
`SELECT ci.id, ci.quantity, ci.added_at, `SELECT ci.id, ci.quantity, ci.added_at,
p.id AS product_id, p.name, p.description, p.price, p.id AS product_id, p.name, p.description, p.price,
p.category_id, pc.name AS category_name p.category_id, pc.name AS category_name,
(
SELECT json_agg(
json_build_object(
'id', pi.id,
'path', pi.image_path,
'isPrimary', pi.is_primary,
'displayOrder', pi.display_order
) ORDER BY pi.display_order
)
FROM product_images pi
WHERE pi.product_id = p.id
) AS images
FROM cart_items ci FROM cart_items ci
JOIN products p ON ci.product_id = p.id JOIN products p ON ci.product_id = p.id
JOIN product_categories pc ON p.category_id = pc.id JOIN product_categories pc ON p.category_id = pc.id
WHERE ci.cart_id = $1`, WHERE ci.cart_id = $1
GROUP BY ci.id, ci.quantity, ci.added_at, p.id, p.name, p.description, p.price, p.category_id, pc.name`,
[cartId] [cartId]
); );
// Process images to add primary_image field
const processedItems = updatedCartItems.rows.map(item => {
// Add primary_image field derived from images array
let primaryImage = null;
if (item.images && item.images.length > 0) {
primaryImage = item.images.find(img => img.isPrimary === true) || item.images[0];
}
return {
...item,
primary_image: primaryImage
};
});
// Calculate total // Calculate total
const total = updatedCartItems.rows.reduce((sum, item) => { const total = processedItems.reduce((sum, item) => {
return sum + (parseFloat(item.price) * item.quantity); return sum + (parseFloat(item.price) * item.quantity);
}, 0); }, 0);
res.json({ res.json({
id: cartId, id: cartId,
userId, userId,
items: updatedCartItems.rows, items: processedItems,
itemCount: updatedCartItems.rows.length, itemCount: processedItems.length,
total total
}); });
} catch (error) { } catch (error) {
@ -158,7 +211,7 @@ module.exports = (pool, query, authMiddleware) => {
if (req.user.id !== userId) { if (req.user.id !== userId) {
return res.status(403).json({ return res.status(403).json({
error: true, error: true,
message: 'You can only modify your own cart' + req.user.id + " "+ userId message: 'You can only modify your own cart'
}); });
} }
// Get cart // Get cart
@ -194,24 +247,51 @@ module.exports = (pool, query, authMiddleware) => {
const updatedCartItems = await query( const updatedCartItems = await query(
`SELECT ci.id, ci.quantity, ci.added_at, `SELECT ci.id, ci.quantity, ci.added_at,
p.id AS product_id, p.name, p.description, p.price, p.id AS product_id, p.name, p.description, p.price,
p.category_id, pc.name AS category_name p.category_id, pc.name AS category_name,
(
SELECT json_agg(
json_build_object(
'id', pi.id,
'path', pi.image_path,
'isPrimary', pi.is_primary,
'displayOrder', pi.display_order
) ORDER BY pi.display_order
)
FROM product_images pi
WHERE pi.product_id = p.id
) AS images
FROM cart_items ci FROM cart_items ci
JOIN products p ON ci.product_id = p.id JOIN products p ON ci.product_id = p.id
JOIN product_categories pc ON p.category_id = pc.id JOIN product_categories pc ON p.category_id = pc.id
WHERE ci.cart_id = $1`, WHERE ci.cart_id = $1
GROUP BY ci.id, ci.quantity, ci.added_at, p.id, p.name, p.description, p.price, p.category_id, pc.name`,
[cartId] [cartId]
); );
// Process images to add primary_image field
const processedItems = updatedCartItems.rows.map(item => {
// Add primary_image field derived from images array
let primaryImage = null;
if (item.images && item.images.length > 0) {
primaryImage = item.images.find(img => img.isPrimary === true) || item.images[0];
}
return {
...item,
primary_image: primaryImage
};
});
// Calculate total // Calculate total
const total = updatedCartItems.rows.reduce((sum, item) => { const total = processedItems.reduce((sum, item) => {
return sum + (parseFloat(item.price) * item.quantity); return sum + (parseFloat(item.price) * item.quantity);
}, 0); }, 0);
res.json({ res.json({
id: cartId, id: cartId,
userId, userId,
items: updatedCartItems.rows, items: processedItems,
itemCount: updatedCartItems.rows.length, itemCount: processedItems.length,
total total
}); });
} catch (error) { } catch (error) {
@ -226,7 +306,7 @@ module.exports = (pool, query, authMiddleware) => {
if (req.user.id !== userId) { if (req.user.id !== userId) {
return res.status(403).json({ return res.status(403).json({
error: true, error: true,
message: 'You can only modify your own cart' + req.user.id + " "+ userId message: 'You can only modify your own cart'
}); });
} }
// Get cart // Get cart

View file

@ -7,7 +7,7 @@ services:
context: ./frontend context: ./frontend
dockerfile: Dockerfile dockerfile: Dockerfile
ports: ports:
- "3000:80" - "3000:3000"
volumes: volumes:
- ./frontend:/app - ./frontend:/app
- /app/node_modules - /app/node_modules

View file

@ -153,7 +153,6 @@ const CartPage = () => {
</Box> </Box>
<Divider /> <Divider />
{cart.items.map((item) => ( {cart.items.map((item) => (
<React.Fragment key={item.product_id}> <React.Fragment key={item.product_id}>
<Box sx={{ p: 2 }}> <Box sx={{ p: 2 }}>
@ -163,7 +162,7 @@ const CartPage = () => {
<Card sx={{ height: '100%' }}> <Card sx={{ height: '100%' }}>
<CardMedia <CardMedia
component="img" component="img"
image={imageUtils.getImageUrl(item.image_url || '/images/placeholder.jpg')} image={imageUtils.getImageUrl(item.primary_image.path || '/images/placeholder.jpg')}
alt={item.name} alt={item.name}
sx={{ height: 80, objectFit: 'cover' }} sx={{ height: 80, objectFit: 'cover' }}
/> />